a3fcf357157d9fe58a5e683f15c47ea0fba3a594
[openwrt/openwrt.git] / target / linux / ath79 / generic / 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 adtran,bsap1800-v2|\
13 adtran,bsap1840|\
14 alfa-network,ap121f|\
15 aruba,ap-105|\
16 avm,fritz300e|\
17 devolo,dvl1200i|\
18 devolo,dvl1750c|\
19 devolo,dvl1750i|\
20 devolo,dvl1750x|\
21 dlink,dir-505|\
22 engenius,ecb1750|\
23 glinet,gl-ar300m-lite|\
24 mikrotik,routerboard-wap-g-5hact2hnd|\
25 netgear,ex6400|\
26 netgear,ex7300|\
27 ocedo,koala|\
28 ocedo,raccoon|\
29 pcs,cap324|\
30 pisen,ts-d084|\
31 pisen,wmb001n|\
32 pisen,wmm003n|\
33 tplink,cpe210-v2|\
34 tplink,cpe210-v3|\
35 tplink,cpe510-v2|\
36 tplink,cpe510-v3|\
37 tplink,cpe610-v1|\
38 tplink,re350k-v1|\
39 tplink,re355-v1|\
40 tplink,re450-v1|\
41 tplink,re450-v2|\
42 tplink,tl-wr902ac-v1|\
43 ubnt,bullet-m|\
44 ubnt,bullet-m-xw|\
45 ubnt,lap-120|\
46 ubnt,litebeam-ac-gen2|\
47 ubnt,nanobeam-ac|\
48 ubnt,nanostation-ac-loco|\
49 ubnt,nanostation-loco-m-xw|\
50 ubnt,rocket-m|\
51 ubnt,unifiac-lite|\
52 ubnt,unifiac-lr|\
53 ubnt,unifiac-mesh|\
54 ubnt,unifi|\
55 wd,mynet-wifi-rangeextender|\
56 winchannel,wb2000)
57 ucidef_set_interface_lan "eth0"
58 ;;
59 avm,fritz4020|\
60 pcs,cr3000|\
61 tplink,archer-c58-v1|\
62 tplink,archer-c59-v1|\
63 tplink,archer-c59-v2)
64 ucidef_set_interface_wan "eth1"
65 ucidef_add_switch "switch0" \
66 "0@eth0" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
67 ;;
68 buffalo,bhr-4grv|\
69 buffalo,wzr-hp-g450h)
70 ucidef_add_switch "switch0" \
71 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
72 ;;
73 buffalo,bhr-4grv2|\
74 trendnet,tew-823dru)
75 ucidef_add_switch "switch0" \
76 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth0"
77 ;;
78 buffalo,wzr-hp-ag300h|\
79 tplink,archer-c25-v1|\
80 tplink,tl-wdr3500-v1|\
81 tplink,tl-wr842n-v1|\
82 tplink,tl-wr842n-v3|\
83 ubnt,airrouter)
84 ucidef_set_interface_wan "eth1"
85 ucidef_add_switch "switch0" \
86 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
87 ;;
88 buffalo,wzr-hp-g302h-a1a0)
89 ucidef_add_switch "switch0" \
90 "0@eth0" "1:lan:1" "3:lan:4" "4:lan:3" "5:lan:2" "2:wan"
91 ;;
92 comfast,cf-e110n-v2|\
93 comfast,cf-e120a-v3|\
94 comfast,cf-e314n-v2|\
95 tplink,cpe210-v1|\
96 tplink,cpe220-v2|\
97 tplink,cpe220-v3|\
98 tplink,cpe510-v1|\
99 tplink,wbs210-v2|\
100 tplink,wbs510-v1|\
101 tplink,wbs510-v2|\
102 ubnt,nanostation-m|\
103 ubnt,routerstation)
104 ucidef_set_interfaces_lan_wan "eth1" "eth0"
105 ;;
106 comfast,cf-e560ac|\
107 tplink,archer-c60-v1|\
108 tplink,archer-c60-v2)
109 ucidef_set_interface_wan "eth1"
110 ucidef_add_switch "switch0" \
111 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan"
112 ;;
113 comfast,cf-wr650ac-v1|\
114 comfast,cf-wr650ac-v2)
115 ucidef_add_switch "switch0" \
116 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth1"
117 ;;
118 devolo,dvl1200e|\
119 devolo,dvl1750e|\
120 ocedo,ursus)
121 ucidef_set_interface_lan "eth0 eth1"
122 ;;
123 dlink,dir-825-b1)
124 ucidef_set_interface_wan "eth1"
125 ucidef_add_switch "switch0" \
126 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
127 ;;
128 dlink,dir-825-c1|\
129 dlink,dir-835-a1|\
130 dlink,dir-842-c1|\
131 dlink,dir-842-c2|\
132 dlink,dir-842-c3|\
133 dlink,dir-859-a1|\
134 engenius,epg5000|\
135 tplink,archer-c2-v3|\
136 tplink,tl-wr1043nd-v4|\
137 tplink,tl-wr1043n-v5)
138 ucidef_add_switch "switch0" \
139 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
140 ;;
141 elecom,wrc-1750ghbk2-i|\
142 elecom,wrc-300ghbk2-i)
143 ucidef_add_switch "switch0" \
144 "0@eth0" "2:lan:4" "3:lan:3" "4:lan:2" "5:lan:1" "1:wan"
145 ;;
146 embeddedwireless,dorin)
147 ucidef_add_switch "switch0" \
148 "0@eth0" "1:wan" "2:lan:3" "3:lan:2"
149 ;;
150 engenius,ews511ap)
151 ucidef_set_interface_lan "eth0 eth1" "dhcp"
152 ;;
153 etactica,eg200)
154 ucidef_set_interface_lan "eth0" "dhcp"
155 ;;
156 glinet,gl-ar750)
157 ucidef_set_interface_wan "eth1"
158 ucidef_add_switch "switch0" \
159 "0@eth0" "1:lan" "2:lan"
160 ;;
161 iodata,etg3-r|\
162 iodata,wn-ac1167dgr|\
163 iodata,wn-ac1600dgr|\
164 iodata,wn-ac1600dgr2|\
165 iodata,wn-ag300dgr|\
166 pcs,cr5000|\
167 sitecom,wlr-7100|\
168 wd,mynet-n750)
169 ucidef_add_switch "switch0" \
170 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
171 ;;
172 librerouter,librerouter-v1)
173 ucidef_add_switch "switch0" \
174 "0@eth0" "5:wan" "6@eth1" "4:lan"
175 ;;
176 nec,wg1200cr|\
177 ubnt,nanostation-ac|\
178 ubnt,unifiac-mesh-pro|\
179 ubnt,unifiac-pro|\
180 yuncore,a782|\
181 yuncore,xd4200)
182 ucidef_add_switch "switch0" \
183 "0@eth0" "2:lan" "3:wan"
184 ;;
185 nec,wg800hp)
186 ucidef_add_switch "switch0" \
187 "0@eth0" "2:lan" "3:lan" "4:lan" "1:wan"
188 ;;
189 netgear,wndr3700|\
190 netgear,wndr3700-v2|\
191 netgear,wndr3800|\
192 netgear,wndr3800ch)
193 ucidef_set_interface_wan "eth1"
194 ucidef_add_switch "switch0" \
195 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5u@eth0"
196 ucidef_add_switch_attr "switch0" "blinkrate" 2
197 ucidef_add_switch_port_attr "switch0" 1 led 6
198 ucidef_add_switch_port_attr "switch0" 2 led 9
199 ucidef_add_switch_port_attr "switch0" 5 led 2
200 ;;
201 netgear,wnr2200-8m|\
202 netgear,wnr2200-16m)
203 ucidef_set_interface_wan "eth0"
204 ucidef_add_switch "switch0" \
205 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
206 ;;
207 phicomm,k2t)
208 ucidef_add_switch "switch0" \
209 "0@eth0" "3:lan:1" "5:lan:2" "4:wan"
210 ;;
211 qihoo,c301)
212 ucidef_set_interface_wan "eth1"
213 ucidef_add_switch "switch0" \
214 "0@eth0" "2:lan" "3:lan"
215 ;;
216 rosinson,wr818)
217 ucidef_add_switch "switch0" \
218 "0@eth0" "1:lan" "2:lan" "3:wan"
219 ;;
220 tplink,archer-a7-v5|\
221 tplink,archer-c6-v2|\
222 tplink,archer-c6-v2-us|\
223 tplink,archer-c7-v4|\
224 tplink,archer-c7-v5|\
225 tplink,tl-wdr3600-v1|\
226 tplink,tl-wdr4300-v1|\
227 tplink,tl-wdr4300-v1-il)
228 ucidef_add_switch "switch0" \
229 "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
230 ;;
231 tplink,archer-c5-v1|\
232 tplink,archer-c7-v1|\
233 tplink,archer-c7-v2|\
234 tplink,tl-wdr4900-v2)
235 ucidef_add_switch "switch0" \
236 "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
237 ;;
238 tplink,archer-d50-v1)
239 ucidef_add_switch "switch0" \
240 "0@eth0" "2:lan:3" "3:lan:2" "4:lan:1" "1:wan"
241 ;;
242 tplink,tl-mr6400-v1)
243 ucidef_set_interfaces_lan_wan "eth0.1 eth1" "usb0"
244 ucidef_add_switch "switch0" \
245 "0@eth0" "1:lan:1" "2:lan:3" "3:lan:2"
246 ;;
247 tplink,tl-wr842n-v2)
248 ucidef_set_interface_wan "eth1"
249 ucidef_add_switch "switch0" \
250 "0@eth0" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
251 ;;
252 tplink,tl-wr1043nd-v1)
253 ucidef_add_switch "switch0" \
254 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
255 ;;
256 tplink,tl-wr1043nd-v2|\
257 tplink,tl-wr1043nd-v3|\
258 tplink,tl-wr1045nd-v2)
259 ucidef_add_switch "switch0" \
260 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
261 ;;
262 tplink,tl-wr2543-v1)
263 ucidef_add_switch "switch0" \
264 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
265 ;;
266 ubnt,acb-isp)
267 ucidef_set_interface_wan "eth1"
268 ucidef_add_switch "switch0" \
269 "0@eth0" "2:lan:1" "3:lan:3" "4:lan:2"
270 ;;
271 ubnt,edgeswitch-5xp)
272 ucidef_set_interface_wan "eth1"
273 ucidef_add_switch "switch0" \
274 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:lan"
275 ;;
276 ubnt,edgeswitch-8xp)
277 ucidef_set_interface_wan "eth1"
278 ucidef_add_switch "switch0" \
279 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:lan:5" "5:lan:6" "6:lan:7" "7:lan:8" "8@eth0"
280 ;;
281 ubnt,routerstation-pro)
282 ucidef_set_interface_wan "eth0"
283 ucidef_add_switch "switch0" \
284 "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
285 ;;
286 ubnt,nanostation-m-xw)
287 ucidef_add_switch "switch0" \
288 "0@eth0" "5:lan" "1:wan"
289 ;;
290 zbtlink,zbt-wd323|\
291 xiaomi,mi-router-4q)
292 ucidef_set_interface_wan "eth1"
293 ucidef_add_switch "switch0" \
294 "0@eth0" "3:lan:1" "4:lan:2"
295 ;;
296 *)
297 ucidef_set_interfaces_lan_wan "eth0" "eth1"
298 ;;
299 esac
300 }
301
302 ath79_setup_macs()
303 {
304 local board="$1"
305
306 case "$board" in
307 adtran,bsap1800-v2|\
308 adtran,bsap1840)
309 lan_mac=$(mtd_get_mac_binary "Board data" 2)
310 label_mac=$lan_mac
311 ;;
312 alfa-network,ap121f)
313 label_mac=$(mtd_get_mac_binary art 0x1002)
314 ;;
315 avm,fritz300e)
316 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
317 label_mac=$(fritz_tffs -n macwlan -i $(find_mtd_part "tffs (1)"))
318 ;;
319 avm,fritz4020)
320 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
321 wan_mac=$(fritz_tffs -n macb -i $(find_mtd_part "tffs (1)"))
322 ;;
323 dlink,dir-825-b1)
324 lan_mac=$(mtd_get_mac_text "caldata" 0xffa0)
325 wan_mac=$(mtd_get_mac_text "caldata" 0xffb4)
326 ;;
327 dlink,dir-505)
328 lan_mac=$(mtd_get_mac_text "mac" 0x4)
329 ;;
330 dlink,dir-825-c1|\
331 dlink,dir-835-a1)
332 lan_mac=$(mtd_get_mac_text "mac" 0x4)
333 wan_mac=$(mtd_get_mac_text "mac" 0x18)
334 ;;
335 dlink,dir-842-c1|\
336 dlink,dir-842-c2|\
337 dlink,dir-842-c3|\
338 nec,wg1200cr)
339 lan_mac=$(mtd_get_mac_ascii devdata "lanmac")
340 wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
341 label_mac=$lan_mac
342 ;;
343 dlink,dir-859-a1|\
344 qihoo,c301|\
345 wd,mynet-n750)
346 lan_mac=$(mtd_get_mac_ascii devdata "lanmac")
347 wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
348 ;;
349 elecom,wrc-1750ghbk2-i|\
350 elecom,wrc-300ghbk2-i)
351 wan_mac=$(macaddr_add "$(mtd_get_mac_binary art 0x1002)" -2)
352 ;;
353 engenius,ecb1750)
354 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
355 label_mac=$(mtd_get_mac_ascii u-boot-env athaddr)
356 ;;
357 engenius,epg5000)
358 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
359 wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
360 ;;
361 engenius,ews511ap)
362 lan_mac=$(mtd_get_mac_text "u-boot-env" 0xe9)
363 eth1_mac=$(macaddr_add "$lan_mac" 1)
364 ucidef_set_interface "eth0" ifname "eth0" protocol "none" macaddr "$lan_mac"
365 ucidef_set_interface "eth1" ifname "eth1" protocol "none" macaddr "$eth1_mac"
366 ;;
367 iodata,etg3-r)
368 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
369 wan_mac=$(macaddr_add "$lan_mac" -1)
370 label_mac=$wan_mac
371 ;;
372 iodata,wn-ac1167dgr|\
373 iodata,wn-ac1600dgr|\
374 iodata,wn-ac1600dgr2|\
375 iodata,wn-ag300dgr)
376 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
377 wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
378 label_mac=$wan_mac
379 ;;
380 jjplus,ja76pf2)
381 wan_mac=$(fconfig -s -r -d $(find_mtd_part "RedBoot config") -n alias/ethaddr)
382 lan_mac=$(macaddr_add "$wan_mac" 1)
383 ;;
384 nec,wg800hp)
385 lan_mac=$(mtd_get_mac_text board_data 0x280)
386 wan_mac=$(mtd_get_mac_text board_data 0x480)
387 label_mac=$wan_mac
388 ;;
389 netgear,wndr3700|\
390 netgear,wndr3700-v2|\
391 netgear,wndr3800)
392 lan_mac=$(macaddr_setbit_la "$(mtd_get_mac_binary art 0x0)")
393 ;;
394 phicomm,k2t)
395 lan_mac=$(k2t_get_mac "lan_mac")
396 wan_mac=$(k2t_get_mac "wan_mac")
397 ;;
398 rosinson,wr818)
399 wan_mac=$(mtd_get_mac_binary factory 0x0)
400 lan_mac=$(macaddr_setbit_la "$wan_mac")
401 ;;
402 sitecom,wlr-7100)
403 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
404 wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
405 label_mac=$lan_mac
406 ;;
407 tplink,archer-a7-v5|\
408 tplink,archer-c7-v4|\
409 tplink,archer-c7-v5|\
410 tplink,tl-wr1043nd-v4|\
411 tplink,tl-wr1043n-v5)
412 base_mac=$(mtd_get_mac_binary info 0x8)
413 wan_mac=$(macaddr_add "$base_mac" 1)
414 ;;
415 tplink,tl-wdr3600-v1|\
416 tplink,tl-wdr4300-v1|\
417 tplink,tl-wdr4300-v1-il)
418 base_mac=$(mtd_get_mac_binary u-boot 0x1fc00)
419 wan_mac=$(macaddr_add "$base_mac" 1)
420 ;;
421 trendnet,tew-823dru)
422 lan_mac=$(mtd_get_mac_text mac 0x4)
423 wan_mac=$(mtd_get_mac_text mac 0x18)
424 label_mac=$wan_mac
425 ;;
426 ubnt,airrouter|\
427 ubnt,bullet-m|\
428 ubnt,nanostation-m|\
429 ubnt,rocket-m|\
430 ubnt,unifi)
431 label_mac=$(cat /sys/class/ieee80211/phy0/macaddress)
432 ;;
433 ubnt,litebeam-ac-gen2)
434 label_mac=$(mtd_get_mac_binary art 0x5006)
435 ;;
436 ubnt,routerstation|\
437 ubnt,routerstation-pro)
438 wan_mac=$(fconfig -s -r -d $(find_mtd_part "RedBoot config") -n ar7100_esa)
439 lan_mac=$(macaddr_add "$wan_mac" 1)
440 ;;
441 wd,mynet-wifi-rangeextender)
442 lan_mac=$(nvram get et0macaddr)
443 ;;
444 esac
445
446 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
447 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
448 [ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
449 }
450
451 board_config_update
452 board=$(board_name)
453 ath79_setup_interfaces $board
454 ath79_setup_macs $board
455 board_config_flush
456
457 exit 0