890efa0d93f62494a39b8ee644655a1a3f82da87
[openwrt/openwrt.git] / target / linux / ramips / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/functions/uci-defaults.sh
5 . /lib/functions/system.sh
6
7 ramips_setup_rt3x5x_vlans()
8 {
9 if [ ! -x /sbin/swconfig ]; then
10 # legacy default
11 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
12 return
13 fi
14 local wanports=""
15 local lanports=""
16 for port in 5 4 3 2 1 0; do
17 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
18 continue
19 fi
20 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
21 wanports="$port:wan $wanports"
22 else
23 lanports="$port:lan $lanports"
24 fi
25 done
26 ucidef_add_switch "rt305x" $lanports $wanports "6t@eth0"
27 }
28
29 ramips_setup_interfaces()
30 {
31 local board="$1"
32
33 case $board in
34 11acnas|\
35 d-team,newifi-d2|\
36 dir-615-h1|\
37 w2914nsv2|\
38 zbt-we2026)
39 ucidef_add_switch "switch0" \
40 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
41 ;;
42 3g150b|\
43 3g300m|\
44 a5-v11|\
45 all0256n-4M|\
46 all0256n-8M|\
47 all5002|\
48 all5003|\
49 bocco|\
50 broadway|\
51 dcs-930|\
52 dcs-930l-b1|\
53 ht-tm02|\
54 kimax,u35wf|\
55 linkits7688 | \
56 m2m|\
57 microwrt|\
58 mikrotik,rbm11g|\
59 mpr-a2|\
60 ncs601w|\
61 omega2 | \
62 omega2p | \
63 timecloud|\
64 tplink,tl-wa801nd-v5|\
65 w150m|\
66 widora,neo-16m|\
67 widora,neo-32m|\
68 wnce2001|\
69 zbt-cpe102|\
70 zorlik,zl5900v2|\
71 zte-q7)
72 ucidef_add_switch "switch0"
73 ucidef_add_switch_attr "switch0" "enable" "false"
74 ucidef_set_interface_lan "eth0"
75 ;;
76 mlw221|\
77 mr-102n)
78 ucidef_set_interface_lan "eth0.2"
79 ;;
80 3g-6200n|\
81 ai-br100|\
82 alfa-network,ac1200rm|\
83 mediatek,ap-mt7621a-v60|\
84 xzwifi,creativebox-v1|\
85 d240|\
86 db-wrt01|\
87 dir-300-b7|\
88 dir-320-b1|\
89 dir-610-a1|\
90 dir-615-h1|\
91 dir-810l|\
92 dlink,dwr-116-a1|\
93 dlink,dwr-921-c1|\
94 dlink,dwr-922-e2|\
95 ew1200|\
96 firewrt|\
97 hc5661a|\
98 hc5962|\
99 hlk-rm04|\
100 k2p|\
101 kn|\
102 kn_rc|\
103 mac1200rv2|\
104 miwifi-mini|\
105 miwifi-nano|\
106 mt7621|\
107 mt7628|\
108 mtc,wr1201|\
109 mzk-750dhp|\
110 mzk-w300nh2|\
111 nixcore-x1-8M|\
112 nixcore-x1-16M|\
113 oy-0001|\
114 pbr-m1|\
115 psg1208|\
116 psg1218a|\
117 r6220|\
118 netgear,r6350|\
119 rt-n12p|\
120 sap-g3200u3|\
121 sk-wb8|\
122 unielec,u7621-06-256m-16m|\
123 unielec,u7621-06-512m-64m|\
124 vr500|\
125 wavlink,wl-wn570ha1|\
126 wavlink,wl-wn575a3|\
127 wf-2881|\
128 whr-g300n|\
129 mqmaker,witi-256m|\
130 mqmaker,witi-512m|\
131 wndr3700v5|\
132 youku-yk1|\
133 zbt-ape522ii|\
134 zbt-we1326|\
135 zbtlink,zbt-we3526|\
136 zbt-we826-16M|\
137 zbt-we826-32M|\
138 zbt-wg2626|\
139 zbt-wg3526-16M|\
140 zbt-wg3526-32M|\
141 zbt-wr8305rt)
142 ucidef_add_switch "switch0" \
143 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
144 ;;
145 gehua,ghl-r-001)
146 ucidef_add_switch "switch0" \
147 "0:lan" "1:lan" "2:lan" "4:wan" "6@eth0"
148 ;;
149 alfa-network,awusfree1|\
150 alfa-network,tube-e4g|\
151 cs-qr10|\
152 d105|\
153 dlink,dap-1522-a1|\
154 dch-m225|\
155 ex2700|\
156 ex3700|\
157 hpm|\
158 mzk-ex300np|\
159 mzk-ex750np|\
160 na930|\
161 pbr-d1|\
162 ravpower,wd03|\
163 tama,w06|\
164 tplink,tl-mr3020-v3|\
165 tplink,tl-wr802n-v4|\
166 u25awf-h1|\
167 wli-tx4-ag300n|\
168 wmdr-143n|\
169 wmr-300|\
170 wn3000rpv3|\
171 wrh-300cr)
172 ucidef_set_interface_lan "eth0"
173 ;;
174 dlink,dwr-118-a1)
175 ucidef_add_switch "switch0" \
176 "1:lan:2" "2:lan:3" "3:lan:1" "4:lan:0" "5:wan" "6@eth0"
177 ;;
178 dlink,dwr-118-a2)
179 ucidef_add_switch "switch0" \
180 "1:lan:2" "2:lan:1" "3:lan:3" "4:lan" "0:wan" "6@eth0"
181 ;;
182 mir3g)
183 ucidef_add_switch "switch0" \
184 "2:lan:2" "3:lan:1" "1:wan" "6t@eth0"
185 ;;
186 psg1218b)
187 ucidef_add_switch "switch0" \
188 "0:lan:3" "1:lan:2" "2:lan:1" "3:wan" "6@eth0"
189 ;;
190 whr-300hp2|\
191 whr-600d|\
192 wsr-1166|\
193 wsr-600)
194 ucidef_add_switch "switch0" \
195 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
196 ;;
197 ar670w|\
198 ar725w|\
199 rt-ac51u)
200 ucidef_add_switch "switch0" \
201 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
202 ;;
203 belkin,f9k1109v1|\
204 rt-n15|\
205 wl-351)
206 ucidef_add_switch "switch0" \
207 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
208 ;;
209 asl26555-8M|\
210 asl26555-16M|\
211 rp-n53)
212 ucidef_add_switch "switch0" \
213 "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
214 ;;
215 atp-52b|\
216 awm002-evb-4M|\
217 awm002-evb-8M|\
218 bdcom,wap2100-sk|\
219 c20i|\
220 dir-645|\
221 gl-mt300a|\
222 gl-mt300n|\
223 gl-mt750|\
224 hiwifi,hc5861b|\
225 jhr-n805r|\
226 jhr-n825r|\
227 jhr-n926r|\
228 mikrotik,rb750gr3|\
229 mikrotik,rbm33g|\
230 mzk-wdpr|\
231 rt-n14u|\
232 skylab,skw92a|\
233 tplink,c20-v4|\
234 tplink,c50-v3|\
235 tplink,c50-v4|\
236 tplink,tl-mr3420-v5|\
237 tplink,tl-wr842n-v5|\
238 tl-wr840n-v4|\
239 tl-wr840n-v5|\
240 tl-wr841n-v13|\
241 u7628-01-128M-16M|\
242 ubnt-erx|\
243 ubnt-erx-sfp|\
244 ur-326n4g|\
245 wrtnode|\
246 wrtnode2p | \
247 wrtnode2r | \
248 youhua,wr1200js|\
249 zbt-wa05|\
250 zyxel,keenetic-extra-ii)
251 ucidef_add_switch "switch0" \
252 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
253 ;;
254 c50|\
255 tplink,c20-v1)
256 ucidef_add_switch "switch0" \
257 "1:lan:3" "2:lan:4" "3:lan:1" "4:lan:2" "0:wan" "6@eth0"
258 ;;
259 dir-860l-b1|\
260 elecom,wrc-1167ghbk2-s|\
261 elecom,wrc-2533gst|\
262 elecom,wrc-1900gst|\
263 hg255d|\
264 iodata,wn-ax1167gr|\
265 iodata,wn-gx300gr)
266 ucidef_add_switch "switch0" \
267 "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
268 ;;
269 gnubee,gb-pc1|\
270 gnubee,gb-pc2)
271 ucidef_add_switch "switch0" \
272 "0:lan" "4:lan" "6@eth0"
273 ;;
274 gl-mt300n-v2)
275 ucidef_add_switch "switch0" \
276 "1:lan" "0:wan" "6@eth0"
277 ;;
278 awapn2403)
279 ucidef_add_switch "switch0" \
280 "0:lan" "1:wan" "6@eth0"
281 ;;
282 b2c|\
283 nw718|\
284 psr-680w|\
285 sl-r7205|\
286 ur-336un|\
287 w502u|\
288 wr6202)
289 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
290 ;;
291 br-6475nd)
292 ucidef_add_switch "switch0" \
293 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
294 ;;
295 c108|\
296 cf-wr800n)
297 ucidef_add_switch "switch0" \
298 "4:lan" "6t@eth0"
299 ;;
300 cy-swr1100)
301 ucidef_add_switch "switch0" \
302 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
303 ;;
304 duzun-dm06)
305 ucidef_add_switch "switch0" \
306 "1:lan" "0:wan" "6@eth0"
307 ;;
308 e1700|\
309 mt7620a_mt7530)
310 ucidef_add_switch "switch1" \
311 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
312 ;;
313 edimax,br-6478ac-v2|\
314 tplink,c2-v1)
315 ucidef_add_switch "switch1" \
316 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
317 ;;
318 hc5661|\
319 y1s)
320 ucidef_add_switch "switch0" \
321 "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
322 ;;
323 hc5861)
324 ucidef_add_switch "switch0" \
325 "0:lan" "1:lan" "5:wan" "6@eth0"
326 ;;
327 iodata,wn-ac1167gr)
328 ucidef_add_switch "switch1" \
329 "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
330 ;;
331 kn_rf)
332 ucidef_add_switch "switch0" \
333 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
334 ;;
335 kng_rc)
336 ucidef_add_switch "switch1" \
337 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
338 ;;
339 mlwg2|\
340 wizard8800|\
341 wl-330n)
342 ucidef_set_interface_lan "eth0.1"
343 ;;
344 mr200)
345 ucidef_add_switch "switch0" \
346 "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
347 ucidef_set_interface_wan "usb0"
348 ;;
349 netgear,r6120)
350 ucidef_add_switch "switch0" \
351 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
352 ;;
353 hc5761)
354 ucidef_add_switch "switch0" \
355 "1:lan" "4:lan" "0:wan" "6@eth0"
356 ;;
357 mzk-dp150n|\
358 vocore-8M|\
359 vocore-16M)
360 ucidef_add_switch "switch0" \
361 "0:lan" "4:lan" "6t@eth0"
362 ;;
363 newifi-d1)
364 ucidef_add_switch "switch0" \
365 "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
366 ;;
367 phicomm,k2g)
368 ucidef_add_switch "switch0" \
369 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5:wan" "6@eth0"
370 ;;
371 re350-v1)
372 ucidef_add_switch "switch0" \
373 "0:lan" "6@eth0"
374 ;;
375 re6500)
376 ucidef_add_switch "switch0" \
377 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
378 ;;
379 rt-n56u)
380 ucidef_add_switch "switch0" \
381 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
382 ;;
383 tew-638apb-v2)
384 ucidef_add_switch "switch0" \
385 "4:lan" "6@eth0"
386 ;;
387 lava,lr-25g001|\
388 tew-691gr|\
389 tew-692gr|\
390 wlr-6000)
391 ucidef_add_switch "switch0" \
392 "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
393 ;;
394 tplink,tl-wr902ac-v3)
395 ucidef_add_switch "switch0" \
396 "4:lan" "6@eth0"
397 ;;
398 vonets,var11n-300|\
399 wt1520-4M|\
400 wt1520-8M)
401 ucidef_add_switch "switch0" \
402 "0:lan" "4:wan" "6@eth0"
403 ;;
404 vocore2|\
405 vocore2lite)
406 ucidef_add_switch "switch0" \
407 "0:lan" "2:lan" "6t@eth0"
408 ;;
409 f5d8235-v1|\
410 f5d8235-v2|\
411 tew-714tru|\
412 v11st-fe|\
413 wzr-agl300nh)
414 ucidef_add_switch "switch0" \
415 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
416 ;;
417 wcr-1166ds)
418 ucidef_add_switch "switch0" \
419 "3:lan" "4:wan" "6@eth0"
420 ;;
421 wcr-150gn|\
422 we1026-5g-16m)
423 ucidef_add_switch "switch0" \
424 "0:lan" "6t@eth0"
425 ;;
426 whr-1166d)
427 ucidef_add_switch "switch0" \
428 "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
429 ;;
430 wizfi630a)
431 ucidef_add_switch "switch0" \
432 "0:lan" "1:lan" "2:wan" "6@eth0"
433 ;;
434 wt3020-4M|\
435 wt3020-8M)
436 ucidef_add_switch "switch0" \
437 "4:lan" "0:wan" "6@eth0"
438 ;;
439 xiaomi,mir3p)
440 ucidef_add_switch "switch0" \
441 "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
442 ;;
443 zbtlink,zbt-we1226|\
444 y1)
445 ucidef_add_switch "switch0" \
446 "0:lan:2" "1:lan:1" "4:wan" "6@eth0"
447 ;;
448 *)
449 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
450 if [ -n "${RT3X5X}" ]; then
451 ramips_setup_rt3x5x_vlans
452 else
453 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
454 fi
455 ;;
456 esac
457 }
458
459 ramips_setup_macs()
460 {
461 local board="$1"
462 local lan_mac=""
463 local wan_mac=""
464
465 case $board in
466 a5-v11|\
467 ht-tm02|\
468 wmdr-143n)
469 lan_mac=$(cat /sys/class/net/eth0/address)
470 ;;
471 carambola|\
472 freestation5|\
473 w502u|\
474 wnce2001)
475 wan_mac=$(mtd_get_mac_binary factory 46)
476 ;;
477 bc2|\
478 broadway|\
479 d105|\
480 dir-300-b7|\
481 dir-320-b1|\
482 dir-620-a1|\
483 esr-9753|\
484 freestation5|\
485 hlk-rm04|\
486 mpr-a1|\
487 psr-680w|\
488 sl-r7205|\
489 y1|\
490 y1s)
491 lan_mac=$(cat /sys/class/net/eth0/address)
492 lan_mac=$(macaddr_setbit_la "$lan_mac")
493 wan_mac=$(macaddr_add "$lan_mac" 1)
494 ;;
495 belkin,f9k1109v1)
496 wan_mac=$(mtd_get_mac_ascii uboot-env HW_WAN_MAC)
497 lan_mac=$(mtd_get_mac_ascii uboot-env HW_LAN_MAC)
498 ;;
499 br-6475nd)
500 lan_mac=$(cat /sys/class/net/eth0/address)
501 wan_mac=$(mtd_get_mac_binary devdata 7)
502 ;;
503 cy-swr1100|\
504 dch-m225)
505 lan_mac=$(mtd_get_mac_ascii factory lanmac)
506 ;;
507 dir-645)
508 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
509 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
510 ;;
511 dir-860l-b1)
512 lan_mac=$(mtd_get_mac_ascii factory lanmac)
513 wan_mac=$(mtd_get_mac_ascii factory wanmac)
514 ;;
515 dlink,dwr-116-a1|\
516 dlink,dwr-118-a1|\
517 dlink,dwr-118-a2|\
518 dlink,dwr-921-c1|\
519 dlink,dwr-922-e2|\
520 lava,lr-25g001)
521 wan_mac=$(jboot_config_read -m -i $(find_mtd_part "config") -o 0xE000)
522 lan_mac=$(macaddr_add "$wan_mac" 1)
523 ;;
524 e1700)
525 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
526 ;;
527 edimax,br-6478ac-v2)
528 lan_mac=$(cat /sys/class/net/eth0/address)
529 wan_mac=$(macaddr_add "$lan_mac" 2)
530 ;;
531 elecom,wrc-1167ghbk2-s|\
532 elecom,wrc-2533gst|\
533 elecom,wrc-1900gst|\
534 sk-wb8)
535 wan_mac=$(mtd_get_mac_binary factory 57350)
536 ;;
537 gl-mt300n-v2|\
538 whr-g300n)
539 wan_mac=$(mtd_get_mac_binary factory 4)
540 ;;
541 hc5*61|\
542 hc5661a|\
543 hc5962|\
544 hiwifi,hc5861b)
545 lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
546 [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
547 wan_mac=$(macaddr_add "$lan_mac" 1)
548 ;;
549 iodata,wn-ac1167gr)
550 wan_mac=$(macaddr_add "$(mtd_get_mac_binary Factory 4)" -1)
551 ;;
552 iodata,wn-ax1167gr|\
553 iodata,wn-gx300gr)
554 wan_mac=$(macaddr_add "$(mtd_get_mac_binary Factory 4)" 1)
555 ;;
556 kn_rc|\
557 kn_rf|\
558 kng_rc)
559 wan_mac=$(mtd_get_mac_binary factory 40)
560 ;;
561 linkits7688)
562 wan_mac=$(mtd_get_mac_binary factory 4)
563 lan_mac=$(mtd_get_mac_binary factory 46)
564 ;;
565 mac1200rv2)
566 lan_mac=$(mtd_get_mac_binary factory_info 13)
567 wan_mac=$(macaddr_add "$lan_mac" 1)
568 ;;
569 mir3g|\
570 xiaomi,mir3p)
571 lan_mac=$(mtd_get_mac_binary Factory 0xe006)
572 ;;
573 miwifi-mini)
574 wan_mac=$(cat /sys/class/net/eth0/address)
575 lan_mac=$(macaddr_setbit_la "$wan_mac")
576 ;;
577 m3|\
578 m4-4M|\
579 m4-8M|\
580 x5|\
581 x8)
582 lan_mac=$(cat /sys/class/net/eth0/address)
583 lan_mac=$(macaddr_add "$lan_mac" -2)
584 ;;
585 newifi-d1)
586 lan_mac=$(cat /sys/class/net/eth0/address)
587 lan_mac=$(macaddr_add "$lan_mac" 2)
588 ;;
589 omega2|\
590 omega2p)
591 wan_mac=$(mtd_get_mac_binary factory 4)
592 lan_mac=$(mtd_get_mac_binary factory 46)
593 ;;
594 oy-0001|\
595 phicomm,k2g)
596 lan_mac=$(mtd_get_mac_binary factory 40)
597 wan_mac=$(mtd_get_mac_binary factory 46)
598 ;;
599 r6220|\
600 netgear,r6350)
601 wan_mac=$(mtd_get_mac_binary factory 4)
602 lan_mac=$(macaddr_add "$wan_mac" 1)
603 ;;
604 rt-n56u)
605 lan_mac=$(cat /sys/class/net/eth0/address)
606 lan_mac=$(macaddr_setbit_la "$lan_mac")
607 wan_mac=$(mtd_get_mac_binary factory 32772)
608 ;;
609 skylab,skw92a)
610 lan_mac=$(mtd_get_mac_binary factory 40)
611 wan_mac=$(mtd_get_mac_binary factory 46)
612 ;;
613 tew-691gr)
614 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
615 ;;
616 tew-692gr)
617 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
618 ;;
619 tiny-ac)
620 lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
621 wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
622 ;;
623 vr500)
624 lan_mac=$(mtd_get_mac_binary factory 57344)
625 wan_mac=$(mtd_get_mac_binary factory 57350)
626 ;;
627 w306r-v20)
628 lan_mac=$(cat /sys/class/net/eth0/address)
629 wan_mac=$(macaddr_add "$lan_mac" 5)
630 ;;
631 wcr-1166ds|\
632 wsr-1166)
633 local index="$(find_mtd_index "board_data")"
634 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
635 lan_mac=$wan_mac
636 ;;
637 wcr-150gn)
638 wan_mac=$(mtd_get_mac_binary factory 40)
639 ;;
640 whr-1166d|\
641 whr-300hp2|\
642 whr-600d|\
643 wsr-600)
644 wan_mac=$(mtd_get_mac_binary factory 4)
645 lan_mac=$wan_mac
646 ;;
647 wizfi630a)
648 lan_mac=$(mtd_get_mac_binary factory 4)
649 wan_mac=$(mtd_get_mac_binary factory 40)
650 ;;
651 wlr-6000)
652 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
653 ;;
654 *)
655 lan_mac=$(cat /sys/class/net/eth0/address)
656 wan_mac=$(macaddr_add "$lan_mac" 1)
657 ;;
658 esac
659
660 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
661 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
662 }
663
664 board_config_update
665 board=$(board_name)
666 ramips_setup_interfaces $board
667 ramips_setup_macs $board
668 board_config_flush
669
670 exit 0