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