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