b2c7762bb56154cf1ea1401c86716cf8103a39a6
[openwrt/openwrt.git] / target / linux / ath79 / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions/system.sh
4 . /lib/functions/uci-defaults.sh
5 . /lib/functions/k2t.sh
6
7 ath79_setup_interfaces()
8 {
9 local board="$1"
10
11 case "$board" in
12 avm,fritz300e|\
13 ocedo,koala|\
14 ocedo,raccoon|\
15 pcs,cap324|\
16 pisen,wmm003n|\
17 pqi,air-pen|\
18 tplink,re450-v2|\
19 tplink,tl-mr10u|\
20 tplink,tl-mr3020-v1|\
21 tplink,tl-mr3040-v2|\
22 tplink,tl-wa901nd-v2|\
23 tplink,tl-wr703n|\
24 ubnt,bullet-m|\
25 ubnt,bullet-m-xw|\
26 ubnt,lap-120|\
27 ubnt,nanostation-ac-loco|\
28 ubnt,rocket-m|\
29 ubnt,unifiac-lite|\
30 ubnt,unifiac-mesh|\
31 ubnt,unifi|\
32 wd,mynet-wifi-rangeextender|\
33 winchannel,wb2000)
34 ucidef_set_interface_lan "eth0"
35 ;;
36 avm,fritz4020|\
37 tplink,archer-c58-v1|\
38 tplink,archer-c59-v1)
39 ucidef_set_interface_wan "eth0"
40 ucidef_add_switch "switch0" \
41 "0@eth1" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
42 ;;
43 buffalo,bhr-4grv|\
44 buffalo,wzr-hp-g450h)
45 ucidef_add_switch "switch0" \
46 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
47 ;;
48 buffalo,bhr-4grv2)
49 ucidef_add_switch "switch0" \
50 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth0"
51 ;;
52 buffalo,wzr-hp-ag300h)
53 ucidef_set_interface_wan "eth1"
54 ucidef_add_switch "switch0" \
55 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
56 ;;
57 buffalo,wzr-hp-g302h-a1a0)
58 ucidef_add_switch "switch0" \
59 "0@eth0" "1:lan:1" "3:lan:4" "4:lan:3" "5:lan:2" "2:wan"
60 ;;
61 devolo,dvl1200e)
62 ucidef_set_interface_lan "eth0 eth1"
63 ;;
64 dlink,dir-825-b1)
65 ucidef_set_interface_wan "eth1"
66 ucidef_add_switch "switch0" \
67 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
68 ;;
69 dlink,dir-825-c1|\
70 dlink,dir-835-a1|\
71 iodata,etg3-r|\
72 iodata,wn-ac1167dgr|\
73 iodata,wn-ac1600dgr2|\
74 iodata,wn-ag300dgr|\
75 pcs,cr5000)
76 ucidef_add_switch "switch0" \
77 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
78 ;;
79 elecom,wrc-300ghbk2-i)
80 ucidef_add_switch "switch0" \
81 "0@eth0" "2:lan:4" "3:lan:3" "4:lan:2" "5:lan:1" "1:wan"
82 ;;
83 embeddedwireless,dorin)
84 ucidef_add_switch "switch0" \
85 "0@eth0" "1:wan" "2:lan:3" "3:lan:2"
86 ;;
87 etactica,eg200)
88 ucidef_set_interface_lan "eth0" "dhcp"
89 ;;
90 glinet,ar150|\
91 glinet,ar300m|\
92 glinet,gl-x750)
93 ucidef_set_interfaces_lan_wan "eth1" "eth0"
94 ;;
95 nec,wg800hp)
96 ucidef_add_switch "switch0" \
97 "0@eth0" "2:lan" "3:lan" "4:lan" "1:wan"
98 ;;
99 netgear,wndr3700|\
100 netgear,wndr3700v2|\
101 netgear,wndr3800)
102 ucidef_set_interfaces_lan_wan "eth0" "eth1"
103 ucidef_add_switch "switch0" \
104 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5u@eth0"
105 ucidef_add_switch_attr "switch0" "blinkrate" 2
106 ucidef_add_switch_port_attr "switch0" 1 led 6
107 ucidef_add_switch_port_attr "switch0" 2 led 9
108 ucidef_add_switch_port_attr "switch0" 5 led 2
109 ;;
110 netgear,wnr612-v2|\
111 on,n150r)
112 ucidef_set_interface_wan "eth0"
113 ucidef_add_switch "switch0" \
114 "0@eth1" "1:lan" "2:lan" "3:lan:3" "4:lan:4"
115 ;;
116 pcs,cr3000)
117 ucidef_add_switch "switch0" \
118 "0@eth1" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
119 ucidef_set_interface_wan "eth0"
120 ;;
121 phicomm,k2t)
122 ucidef_add_switch "switch0" \
123 "0@eth0" "3:lan:1" "5:lan:2" "4:wan"
124 ;;
125 rosinson,wr818)
126 ucidef_add_switch "switch0" \
127 "0@eth0" "1:lan" "2:lan" "3:wan"
128 ;;
129 tplink,archer-c7-v1|\
130 tplink,archer-c7-v2|\
131 tplink,tl-wdr4900-v2)
132 ucidef_add_switch "switch0" \
133 "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
134 ;;
135 buffalo,whr-g301n|\
136 tplink,tl-mr3220-v1|\
137 tplink,tl-mr3420-v1|\
138 tplink,tl-wr841-v7|\
139 ubnt,airrouter)
140 ucidef_set_interface_wan "eth0"
141 ucidef_add_switch "switch0" \
142 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
143 ;;
144 tplink,archer-a7-v5|\
145 tplink,archer-c7-v5|\
146 tplink,tl-wdr3600|\
147 tplink,tl-wdr4300)
148 ucidef_add_switch "switch0" \
149 "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
150 ;;
151 tplink,tl-wr1043nd-v1)
152 ucidef_add_switch "switch0" \
153 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
154 ;;
155 tplink,tl-wr1043nd-v2|\
156 tplink,tl-wr1043nd-v3)
157 ucidef_add_switch "switch0" \
158 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
159 ;;
160 tplink,tl-wr1043nd-v4)
161 ucidef_add_switch "switch0" \
162 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
163 ;;
164 tplink,tl-wr2543-v1)
165 ucidef_add_switch "switch0" \
166 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
167 ;;
168 tplink,tl-wr740n-v1|\
169 tplink,tl-wr740n-v3|\
170 tplink,tl-wr741-v1|\
171 tplink,tl-wr743nd-v1|\
172 tplink,tl-wr841-v5|\
173 tplink,tl-wr941-v4)
174 ucidef_set_interface_wan "eth0"
175 ucidef_add_switch "switch0" \
176 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
177 ;;
178 tplink,tl-wr740nd-v4|\
179 tplink,tl-wr741nd-v4|\
180 tplink,tl-wr841-v9|\
181 tplink,tl-wr841-v11)
182 ucidef_set_interface_wan "eth0"
183 ucidef_add_switch "switch0" \
184 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
185 ;;
186 tplink,tl-wr842n-v1|\
187 tplink,tl-wr842n-v2)
188 ucidef_set_interface_wan "eth0"
189 ucidef_add_switch "switch0" \
190 "0@eth1" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
191 ;;
192 tplink,tl-wr941-v2)
193 ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
194 ;;
195 ubnt,routerstation)
196 ucidef_set_interfaces_lan_wan "eth1" "eth0"
197 ;;
198 ubnt,routerstation-pro)
199 ucidef_set_interface_wan "eth0"
200 ucidef_add_switch "switch0" \
201 "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
202 ;;
203 ubnt,nanostation-ac|\
204 ubnt,unifiac-mesh-pro|\
205 ubnt,unifiac-pro)
206 ucidef_add_switch "switch0" \
207 "0@eth0" "2:lan" "3:wan"
208 ;;
209 *)
210 ucidef_set_interfaces_lan_wan "eth0" "eth1"
211 ;;
212 esac
213 }
214
215 ath79_setup_macs()
216 {
217 local board="$1"
218
219 case "$board" in
220 avm,fritz300e)
221 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
222 ;;
223 avm,fritz4020)
224 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
225 wan_mac=$(fritz_tffs -n macb -i $(find_mtd_part "tffs (1)"))
226 ;;
227 dlink,dir-825-b1)
228 lan_mac=$(mtd_get_mac_text "caldata" 65440)
229 wan_mac=$(mtd_get_mac_text "caldata" 65460)
230 ;;
231 dlink,dir-825-c1|\
232 dlink,dir-835-a1)
233 lan_mac=$(mtd_get_mac_text "mac" 4)
234 wan_mac=$(mtd_get_mac_text "mac" 24)
235 ;;
236 elecom,wrc-300ghbk2-i)
237 wan_mac=$(macaddr_add "$(mtd_get_mac_binary ART 4098)" -2)
238 ;;
239 iodata,etg3-r)
240 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
241 wan_mac=$(macaddr_add "$lan_mac" -1)
242 ;;
243 iodata,wn-ac1167dgr|\
244 iodata,wn-ac1600dgr2|\
245 iodata,wn-ag300dgr)
246 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
247 wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
248 ;;
249 nec,wg800hp)
250 lan_mac=$(mtd_get_mac_text board_data 640)
251 wan_mac=$(mtd_get_mac_text board_data 1152)
252 ;;
253 netgear,wndr3700|\
254 netgear,wndr3700v2|\
255 netgear,wndr3800)
256 lan_mac=$(macaddr_setbit_la "$(mtd_get_mac_binary art 0)")
257 ;;
258 phicomm,k2t)
259 lan_mac=$(k2t_get_mac "lan_mac")
260 wan_mac=$(k2t_get_mac "wan_mac")
261 ;;
262 rosinson,wr818)
263 wan_mac=$(mtd_get_mac_binary factory 0)
264 lan_mac=$(macaddr_setbit_la "$wan_mac")
265 ;;
266 tplink,tl-wr1043nd-v4)
267 base_mac=$(mtd_get_mac_binary product-info 8)
268 wan_mac=$(macaddr_add "$base_mac" 1)
269 ;;
270 tplink,tl-wr941-v2)
271 base_mac=$(mtd_get_mac_binary u-boot 130048)
272 wan_mac=$(macaddr_add "$base_mac" 1)
273 ;;
274 ubnt,routerstation|\
275 ubnt,routerstation-pro)
276 wan_mac=$(fconfig -s -r -d $(find_mtd_part "RedBoot config") -n ar7100_esa)
277 lan_mac=$(macaddr_add "$wan_mac" 1)
278 ;;
279 wd,mynet-wifi-rangeextender)
280 lan_mac=$(nvram get et0macaddr)
281 ;;
282 esac
283
284 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
285 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
286 }
287
288 board_config_update
289 board=$(board_name)
290 ath79_setup_interfaces $board
291 ath79_setup_macs $board
292 board_config_flush
293
294 exit 0