f47d6f895dd923688cb5426c58d05717dd2d109e
[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 cs-qr10|\
151 d105|\
152 dlink,dap-1522-a1|\
153 dch-m225|\
154 ex2700|\
155 ex3700|\
156 hpm|\
157 mzk-ex300np|\
158 mzk-ex750np|\
159 na930|\
160 pbr-d1|\
161 ravpower,wd03|\
162 tama,w06|\
163 tplink,tl-mr3020-v3|\
164 u25awf-h1|\
165 wli-tx4-ag300n|\
166 wmdr-143n|\
167 wmr-300|\
168 wn3000rpv3|\
169 wrh-300cr)
170 ucidef_set_interface_lan "eth0"
171 ;;
172 dlink,dwr-118-a1)
173 ucidef_add_switch "switch0" \
174 "1:lan:2" "2:lan:3" "3:lan:1" "4:lan:0" "5:wan" "6@eth0"
175 ;;
176 dlink,dwr-118-a2)
177 ucidef_add_switch "switch0" \
178 "1:lan:2" "2:lan:1" "3:lan:3" "4:lan" "0:wan" "6@eth0"
179 ;;
180 mir3g)
181 ucidef_add_switch "switch0" \
182 "2:lan:2" "3:lan:1" "1:wan" "6t@eth0"
183 ;;
184 psg1218b)
185 ucidef_add_switch "switch0" \
186 "0:lan:3" "1:lan:2" "2:lan:1" "3:wan" "6@eth0"
187 ;;
188 whr-300hp2|\
189 whr-600d|\
190 wsr-1166|\
191 wsr-600)
192 ucidef_add_switch "switch0" \
193 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
194 ;;
195 ar670w|\
196 ar725w|\
197 rt-ac51u)
198 ucidef_add_switch "switch0" \
199 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
200 ;;
201 rt-n15|\
202 wl-351)
203 ucidef_add_switch "switch0" \
204 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
205 ;;
206 asl26555-8M|\
207 asl26555-16M|\
208 rp-n53)
209 ucidef_add_switch "switch0" \
210 "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
211 ;;
212 atp-52b|\
213 awm002-evb-4M|\
214 awm002-evb-8M|\
215 bdcom,wap2100-sk|\
216 c20i|\
217 dir-645|\
218 gl-mt300a|\
219 gl-mt300n|\
220 gl-mt750|\
221 hiwifi,hc5861b|\
222 jhr-n805r|\
223 jhr-n825r|\
224 jhr-n926r|\
225 mikrotik,rb750gr3|\
226 mikrotik,rbm33g|\
227 mzk-wdpr|\
228 rt-n14u|\
229 skylab,skw92a|\
230 tplink,c20-v4|\
231 tplink,c50-v3|\
232 tplink,c50-v4|\
233 tplink,tl-mr3420-v5|\
234 tplink,tl-wr842n-v5|\
235 tl-wr840n-v4|\
236 tl-wr840n-v5|\
237 tl-wr841n-v13|\
238 u7628-01-128M-16M|\
239 ubnt-erx|\
240 ubnt-erx-sfp|\
241 ur-326n4g|\
242 wrtnode|\
243 wrtnode2p | \
244 wrtnode2r | \
245 youhua,wr1200js|\
246 zbt-wa05|\
247 zyxel,keenetic-extra-ii)
248 ucidef_add_switch "switch0" \
249 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
250 ;;
251 c50|\
252 tplink,c20-v1)
253 ucidef_add_switch "switch0" \
254 "1:lan:3" "2:lan:4" "3:lan:1" "4:lan:2" "0:wan" "6@eth0"
255 ;;
256 dir-860l-b1|\
257 elecom,wrc-1167ghbk2-s|\
258 elecom,wrc-2533gst|\
259 elecom,wrc-1900gst|\
260 hg255d|\
261 iodata,wn-ax1167gr|\
262 iodata,wn-gx300gr)
263 ucidef_add_switch "switch0" \
264 "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
265 ;;
266 gnubee,gb-pc1|\
267 gnubee,gb-pc2)
268 ucidef_add_switch "switch0" \
269 "0:lan" "4:lan" "6@eth0"
270 ;;
271 gl-mt300n-v2)
272 ucidef_add_switch "switch0" \
273 "1:lan" "0:wan" "6@eth0"
274 ;;
275 awapn2403)
276 ucidef_add_switch "switch0" \
277 "0:lan" "1:wan" "6@eth0"
278 ;;
279 b2c|\
280 nw718|\
281 psr-680w|\
282 sl-r7205|\
283 ur-336un|\
284 w502u|\
285 wr6202)
286 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
287 ;;
288 br-6475nd)
289 ucidef_add_switch "switch0" \
290 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
291 ;;
292 c108|\
293 cf-wr800n)
294 ucidef_add_switch "switch0" \
295 "4:lan" "6t@eth0"
296 ;;
297 cy-swr1100)
298 ucidef_add_switch "switch0" \
299 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
300 ;;
301 duzun-dm06)
302 ucidef_add_switch "switch0" \
303 "1:lan" "0:wan" "6@eth0"
304 ;;
305 e1700|\
306 mt7620a_mt7530)
307 ucidef_add_switch "switch1" \
308 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
309 ;;
310 edimax,br-6478ac-v2|\
311 tplink,c2-v1)
312 ucidef_add_switch "switch1" \
313 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
314 ;;
315 hc5661|\
316 hc5861|\
317 y1s)
318 ucidef_add_switch "switch0" \
319 "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
320 ;;
321 iodata,wn-ac1167gr)
322 ucidef_add_switch "switch1" \
323 "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
324 ;;
325 kn_rf)
326 ucidef_add_switch "switch0" \
327 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
328 ;;
329 kng_rc)
330 ucidef_add_switch "switch1" \
331 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
332 ;;
333 mlwg2|\
334 wizard8800|\
335 wl-330n)
336 ucidef_set_interface_lan "eth0.1"
337 ;;
338 mr200)
339 ucidef_add_switch "switch0" \
340 "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
341 ucidef_set_interface_wan "usb0"
342 ;;
343 netgear,r6120)
344 ucidef_add_switch "switch0" \
345 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
346 ;;
347 hc5761)
348 ucidef_add_switch "switch0" \
349 "1:lan" "4:lan" "0:wan" "6@eth0"
350 ;;
351 mzk-dp150n|\
352 vocore-8M|\
353 vocore-16M)
354 ucidef_add_switch "switch0" \
355 "0:lan" "4:lan" "6t@eth0"
356 ;;
357 newifi-d1)
358 ucidef_add_switch "switch0" \
359 "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
360 ;;
361 phicomm,k2g)
362 ucidef_add_switch "switch0" \
363 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5:wan" "6@eth0"
364 ;;
365 re350-v1)
366 ucidef_add_switch "switch0" \
367 "0:lan" "6@eth0"
368 ;;
369 re6500)
370 ucidef_add_switch "switch0" \
371 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
372 ;;
373 rt-n56u)
374 ucidef_add_switch "switch0" \
375 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
376 ;;
377 tew-638apb-v2)
378 ucidef_add_switch "switch0" \
379 "4:lan" "6@eth0"
380 ;;
381 lava,lr-25g001|\
382 tew-691gr|\
383 tew-692gr|\
384 wlr-6000)
385 ucidef_add_switch "switch0" \
386 "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
387 ;;
388 tplink,tl-wr902ac-v3)
389 ucidef_add_switch "switch0" \
390 "4:lan" "6@eth0"
391 ;;
392 vonets,var11n-300|\
393 wt1520-4M|\
394 wt1520-8M)
395 ucidef_add_switch "switch0" \
396 "0:lan" "4:wan" "6@eth0"
397 ;;
398 vocore2|\
399 vocore2lite)
400 ucidef_add_switch "switch0" \
401 "0:lan" "2:lan" "6t@eth0"
402 ;;
403 f5d8235-v1|\
404 f5d8235-v2|\
405 tew-714tru|\
406 v11st-fe|\
407 wzr-agl300nh)
408 ucidef_add_switch "switch0" \
409 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
410 ;;
411 wcr-1166ds)
412 ucidef_add_switch "switch0" \
413 "3:lan" "4:wan" "6@eth0"
414 ;;
415 wcr-150gn|\
416 we1026-5g-16m)
417 ucidef_add_switch "switch0" \
418 "0:lan" "6t@eth0"
419 ;;
420 whr-1166d)
421 ucidef_add_switch "switch0" \
422 "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
423 ;;
424 wizfi630a)
425 ucidef_add_switch "switch0" \
426 "0:lan" "1:lan" "2:wan" "6@eth0"
427 ;;
428 wt3020-4M|\
429 wt3020-8M)
430 ucidef_add_switch "switch0" \
431 "4:lan" "0:wan" "6@eth0"
432 ;;
433 zbtlink,zbt-we1226|\
434 y1)
435 ucidef_add_switch "switch0" \
436 "0:lan:2" "1:lan:1" "4:wan" "6@eth0"
437 ;;
438 *)
439 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
440 if [ -n "${RT3X5X}" ]; then
441 ramips_setup_rt3x5x_vlans
442 else
443 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
444 fi
445 ;;
446 esac
447 }
448
449 ramips_setup_macs()
450 {
451 local board="$1"
452 local lan_mac=""
453 local wan_mac=""
454
455 case $board in
456 a5-v11|\
457 ht-tm02|\
458 wmdr-143n)
459 lan_mac=$(cat /sys/class/net/eth0/address)
460 ;;
461 carambola|\
462 freestation5|\
463 w502u|\
464 wnce2001)
465 wan_mac=$(mtd_get_mac_binary factory 46)
466 ;;
467 bc2|\
468 broadway|\
469 d105|\
470 dir-300-b7|\
471 dir-320-b1|\
472 dir-620-a1|\
473 esr-9753|\
474 freestation5|\
475 hlk-rm04|\
476 mpr-a1|\
477 psr-680w|\
478 sl-r7205|\
479 y1|\
480 y1s)
481 lan_mac=$(cat /sys/class/net/eth0/address)
482 lan_mac=$(macaddr_setbit_la "$lan_mac")
483 wan_mac=$(macaddr_add "$lan_mac" 1)
484 ;;
485 br-6475nd)
486 lan_mac=$(cat /sys/class/net/eth0/address)
487 wan_mac=$(mtd_get_mac_binary devdata 7)
488 ;;
489 cy-swr1100|\
490 dch-m225)
491 lan_mac=$(mtd_get_mac_ascii factory lanmac)
492 ;;
493 dir-645)
494 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
495 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
496 ;;
497 dir-860l-b1)
498 lan_mac=$(mtd_get_mac_ascii factory lanmac)
499 wan_mac=$(mtd_get_mac_ascii factory wanmac)
500 ;;
501 dlink,dwr-116-a1|\
502 dlink,dwr-118-a1|\
503 dlink,dwr-118-a2|\
504 dlink,dwr-921-c1|\
505 dlink,dwr-922-e2|\
506 lava,lr-25g001)
507 wan_mac=$(jboot_config_read -m -i $(find_mtd_part "config") -o 0xE000)
508 lan_mac=$(macaddr_add "$wan_mac" 1)
509 ;;
510 e1700)
511 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
512 ;;
513 edimax,br-6478ac-v2)
514 lan_mac=$(cat /sys/class/net/eth0/address)
515 wan_mac=$(macaddr_add "$lan_mac" 2)
516 ;;
517 elecom,wrc-1167ghbk2-s|\
518 elecom,wrc-2533gst|\
519 elecom,wrc-1900gst|\
520 sk-wb8)
521 wan_mac=$(mtd_get_mac_binary factory 57350)
522 ;;
523 gl-mt300n-v2|\
524 whr-g300n)
525 wan_mac=$(mtd_get_mac_binary factory 4)
526 ;;
527 hc5*61|\
528 hc5661a|\
529 hc5962|\
530 hiwifi,hc5861b)
531 lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
532 [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
533 wan_mac=$(macaddr_add "$lan_mac" 1)
534 ;;
535 iodata,wn-ac1167gr)
536 wan_mac=$(macaddr_add "$(mtd_get_mac_binary Factory 4)" -1)
537 ;;
538 iodata,wn-ax1167gr|\
539 iodata,wn-gx300gr)
540 wan_mac=$(macaddr_add "$(mtd_get_mac_binary Factory 4)" 1)
541 ;;
542 kn_rc|\
543 kn_rf|\
544 kng_rc)
545 wan_mac=$(mtd_get_mac_binary factory 40)
546 ;;
547 linkits7688)
548 wan_mac=$(mtd_get_mac_binary factory 4)
549 lan_mac=$(mtd_get_mac_binary factory 46)
550 ;;
551 mac1200rv2)
552 lan_mac=$(mtd_get_mac_binary factory_info 13)
553 wan_mac=$(macaddr_add "$lan_mac" 1)
554 ;;
555 mir3g)
556 lan_mac=$(mtd_get_mac_binary Factory 0xe006)
557 ;;
558 miwifi-mini)
559 wan_mac=$(cat /sys/class/net/eth0/address)
560 lan_mac=$(macaddr_setbit_la "$wan_mac")
561 ;;
562 m3|\
563 m4-4M|\
564 m4-8M|\
565 x5|\
566 x8)
567 lan_mac=$(cat /sys/class/net/eth0/address)
568 lan_mac=$(macaddr_add "$lan_mac" -2)
569 ;;
570 newifi-d1)
571 lan_mac=$(cat /sys/class/net/eth0/address)
572 lan_mac=$(macaddr_add "$lan_mac" 2)
573 ;;
574 omega2|\
575 omega2p)
576 wan_mac=$(mtd_get_mac_binary factory 4)
577 lan_mac=$(mtd_get_mac_binary factory 46)
578 ;;
579 oy-0001|\
580 phicomm,k2g)
581 lan_mac=$(mtd_get_mac_binary factory 40)
582 wan_mac=$(mtd_get_mac_binary factory 46)
583 ;;
584 r6220|\
585 netgear,r6350)
586 wan_mac=$(mtd_get_mac_binary factory 4)
587 lan_mac=$(macaddr_add "$wan_mac" 1)
588 ;;
589 rt-n56u)
590 lan_mac=$(cat /sys/class/net/eth0/address)
591 lan_mac=$(macaddr_setbit_la "$lan_mac")
592 wan_mac=$(mtd_get_mac_binary factory 32772)
593 ;;
594 skylab,skw92a)
595 lan_mac=$(mtd_get_mac_binary factory 40)
596 wan_mac=$(mtd_get_mac_binary factory 46)
597 ;;
598 tew-691gr)
599 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
600 ;;
601 tew-692gr)
602 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
603 ;;
604 tiny-ac)
605 lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
606 wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
607 ;;
608 vr500)
609 lan_mac=$(mtd_get_mac_binary factory 57344)
610 wan_mac=$(mtd_get_mac_binary factory 57350)
611 ;;
612 w306r-v20)
613 lan_mac=$(cat /sys/class/net/eth0/address)
614 wan_mac=$(macaddr_add "$lan_mac" 5)
615 ;;
616 wcr-1166ds|\
617 wsr-1166)
618 local index="$(find_mtd_index "board_data")"
619 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
620 lan_mac=$wan_mac
621 ;;
622 wcr-150gn)
623 wan_mac=$(mtd_get_mac_binary factory 40)
624 ;;
625 whr-1166d|\
626 whr-300hp2|\
627 whr-600d|\
628 wsr-600)
629 wan_mac=$(mtd_get_mac_binary factory 4)
630 lan_mac=$wan_mac
631 ;;
632 wizfi630a)
633 lan_mac=$(mtd_get_mac_binary factory 4)
634 wan_mac=$(mtd_get_mac_binary factory 40)
635 ;;
636 wlr-6000)
637 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
638 ;;
639 *)
640 lan_mac=$(cat /sys/class/net/eth0/address)
641 wan_mac=$(macaddr_add "$lan_mac" 1)
642 ;;
643 esac
644
645 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
646 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
647 }
648
649 board_config_update
650 board=$(board_name)
651 ramips_setup_interfaces $board
652 ramips_setup_macs $board
653 board_config_flush
654
655 exit 0