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