b7e5fb6ff935e725ba0192d42e57aeaf0de00273
[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 w2914nsv2|\
36 zbt-we2026)
37 ucidef_add_switch "switch0" \
38 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
39 ;;
40 3g150b|\
41 3g300m|\
42 a5-v11|\
43 all0256n-4M|\
44 all0256n-8M|\
45 all5002|\
46 all5003|\
47 broadway|\
48 dcs-930|\
49 dcs-930l-b1|\
50 ht-tm02|\
51 linkits7688 | \
52 m2m|\
53 microwrt|\
54 mpr-a2|\
55 ncs601w|\
56 omega2 | \
57 omega2p | \
58 timecloud|\
59 w150m|\
60 widora,neo-16m|\
61 widora,neo-32m|\
62 wnce2001|\
63 zbt-cpe102|\
64 zorlik,zl5900v2|\
65 zte-q7)
66 ucidef_add_switch "switch0"
67 ucidef_add_switch_attr "switch0" "enable" "false"
68 ucidef_set_interface_lan "eth0"
69 ;;
70 mlw221|\
71 mr-102n)
72 ucidef_set_interface_lan "eth0.2"
73 ;;
74 3g-6200n|\
75 ai-br100|\
76 alfa-network,ac1200rm|\
77 mediatek,ap-mt7621a-v60|\
78 d240|\
79 db-wrt01|\
80 dir-300-b7|\
81 dir-320-b1|\
82 dir-610-a1|\
83 dir-615-h1|\
84 dlink,dwr-116-a1|\
85 dlink,dwr-921-c1|\
86 ew1200|\
87 firewrt|\
88 hc5661a|\
89 hc5962|\
90 hlk-rm04|\
91 k2p|\
92 kn|\
93 kn_rc|\
94 mac1200rv2|\
95 miwifi-mini|\
96 miwifi-nano|\
97 mt7621|\
98 mt7628|\
99 mzk-750dhp|\
100 mzk-w300nh2|\
101 d-team,newifi-d2|\
102 nixcore-x1-8M|\
103 nixcore-x1-16M|\
104 oy-0001|\
105 pbr-m1|\
106 psg1208|\
107 psg1218a|\
108 r6220|\
109 rt-n12p|\
110 sap-g3200u3|\
111 sk-wb8|\
112 u7621-06-256M-16M|\
113 vr500|\
114 wf-2881|\
115 whr-g300n|\
116 witi|\
117 wl-wn575a3|\
118 wndr3700v5|\
119 youku-yk1|\
120 zbt-ape522ii|\
121 zbt-we1326|\
122 zbtlink,zbt-we3526|\
123 zbt-we826-16M|\
124 zbt-we826-32M|\
125 zbt-wg2626|\
126 zbt-wg3526-16M|\
127 zbt-wg3526-32M|\
128 zbt-wr8305rt)
129 ucidef_add_switch "switch0" \
130 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
131 ;;
132 alfa-network,awusfree1|\
133 cs-qr10|\
134 d105|\
135 dlink,dap-1522-a1|\
136 dch-m225|\
137 ex2700|\
138 ex3700|\
139 hpm|\
140 mzk-ex300np|\
141 mzk-ex750np|\
142 na930|\
143 pbr-d1|\
144 tama,w06|\
145 u25awf-h1|\
146 wli-tx4-ag300n|\
147 wmdr-143n|\
148 wmr-300|\
149 wn3000rpv3|\
150 wrh-300cr)
151 ucidef_set_interface_lan "eth0"
152 ;;
153 mir3g)
154 ucidef_add_switch "switch0" \
155 "2:lan:2" "3:lan:1" "1:wan" "6t@eth0"
156 ;;
157 psg1218b)
158 ucidef_add_switch "switch0" \
159 "0:lan:3" "1:lan:2" "2:lan:1" "3:wan" "6@eth0"
160 ;;
161 whr-300hp2|\
162 whr-600d|\
163 wsr-1166|\
164 wsr-600)
165 ucidef_add_switch "switch0" \
166 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
167 ;;
168 ar670w|\
169 ar725w|\
170 rt-ac51u)
171 ucidef_add_switch "switch0" \
172 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
173 ;;
174 rt-n15|\
175 wl-351)
176 ucidef_add_switch "switch0" \
177 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
178 ;;
179 asl26555-8M|\
180 asl26555-16M|\
181 rp-n53)
182 ucidef_add_switch "switch0" \
183 "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
184 ;;
185 atp-52b|\
186 awm002-evb-4M|\
187 awm002-evb-8M|\
188 c20i|\
189 dir-645|\
190 f5d8235-v2|\
191 gl-mt300a|\
192 gl-mt300n|\
193 gl-mt750|\
194 hg255d|\
195 jhr-n805r|\
196 jhr-n825r|\
197 jhr-n926r|\
198 mzk-wdpr|\
199 rb750gr3|\
200 rt-n14u|\
201 tplink,c20-v4|\
202 tplink,c50-v3|\
203 tplink,tl-mr3420-v5|\
204 tl-wr840n-v4|\
205 tl-wr840n-v5|\
206 tl-wr841n-v13|\
207 u7628-01-128M-16M|\
208 ubnt-erx|\
209 ubnt-erx-sfp|\
210 ur-326n4g|\
211 wrtnode|\
212 wrtnode2p | \
213 wrtnode2r | \
214 youhua,wr1200js|\
215 zbt-wa05)
216 ucidef_add_switch "switch0" \
217 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
218 ;;
219 c50|\
220 tplink,c20-v1)
221 ucidef_add_switch "switch0" \
222 "1:lan:3" "2:lan:4" "3:lan:1" "4:lan:2" "0:wan" "6@eth0"
223 ;;
224 dir-860l-b1)
225 ucidef_add_switch "switch0" \
226 "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
227 ;;
228 gb-pc1|\
229 gnubee,gb-pc2)
230 ucidef_add_switch "switch0" \
231 "0:lan" "4:lan" "6@eth0"
232 ;;
233 gl-mt300n-v2)
234 ucidef_add_switch "switch0" \
235 "1:lan" "0:wan" "6@eth0"
236 ;;
237 awapn2403)
238 ucidef_add_switch "switch0" \
239 "0:lan" "1:wan" "6@eth0"
240 ;;
241 b2c|\
242 nw718|\
243 psr-680w|\
244 sl-r7205|\
245 ur-336un|\
246 w502u|\
247 wr6202)
248 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
249 ;;
250 br-6475nd)
251 ucidef_add_switch "switch0" \
252 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
253 ;;
254 c108|\
255 cf-wr800n)
256 ucidef_add_switch "switch0" \
257 "4:lan" "6t@eth0"
258 ;;
259 cy-swr1100)
260 ucidef_add_switch "switch0" \
261 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
262 ;;
263 duzun-dm06)
264 ucidef_add_switch "switch0" \
265 "1:lan" "0:wan" "6@eth0"
266 ;;
267 e1700|\
268 mt7620a_mt7530)
269 ucidef_add_switch "switch1" \
270 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
271 ;;
272 hc5*61|\
273 y1s)
274 ucidef_add_switch "switch0" \
275 "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
276 ;;
277 kn_rf)
278 ucidef_add_switch "switch0" \
279 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
280 ;;
281 kng_rc)
282 ucidef_add_switch "switch1" \
283 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
284 ;;
285 mlwg2|\
286 wizard8800|\
287 wl-330n)
288 ucidef_set_interface_lan "eth0.1"
289 ;;
290 mr200)
291 ucidef_add_switch "switch0" \
292 "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
293 ucidef_set_interface_wan "usb0"
294 ;;
295 mzk-dp150n|\
296 vocore-8M|\
297 vocore-16M)
298 ucidef_add_switch "switch0" \
299 "0:lan" "4:lan" "6t@eth0"
300 ;;
301 newifi-d1)
302 ucidef_add_switch "switch0" \
303 "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
304 ;;
305 re350-v1)
306 ucidef_add_switch "switch0" \
307 "0:lan" "6@eth0"
308 ;;
309 re6500)
310 ucidef_add_switch "switch0" \
311 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
312 ;;
313 rt-n56u)
314 ucidef_add_switch "switch0" \
315 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
316 ;;
317 tew-638apb-v2)
318 ucidef_add_switch "switch0" \
319 "4:lan" "6@eth0"
320 ;;
321 tew-691gr|\
322 tew-692gr|\
323 wlr-6000)
324 ucidef_add_switch "switch0" \
325 "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
326 ;;
327 tplink,tl-wr902ac-v3)
328 ucidef_add_switch "switch0" \
329 "4:lan" "6@eth0"
330 ;;
331 vonets,var11n-300|\
332 wt1520-4M|\
333 wt1520-8M)
334 ucidef_add_switch "switch0" \
335 "0:lan" "4:wan" "6@eth0"
336 ;;
337 vocore2|\
338 vocore2lite)
339 ucidef_add_switch "switch0" \
340 "0:lan" "2:lan" "6t@eth0"
341 ;;
342 f5d8235-v1|\
343 tew-714tru|\
344 v11st-fe|\
345 wzr-agl300nh)
346 ucidef_add_switch "switch0" \
347 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
348 ;;
349 wcr-1166ds)
350 ucidef_add_switch "switch0" \
351 "3:lan" "4:wan" "6@eth0"
352 ;;
353 wcr-150gn|\
354 we1026-5g-16m)
355 ucidef_add_switch "switch0" \
356 "0:lan" "6t@eth0"
357 ;;
358 whr-1166d)
359 ucidef_add_switch "switch0" \
360 "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
361 ;;
362 wizfi630a)
363 ucidef_add_switch "switch0" \
364 "1:lan" "2:lan" "0:wan" "6@eth0"
365 ;;
366 wt3020-4M|\
367 wt3020-8M)
368 ucidef_add_switch "switch0" \
369 "4:lan" "0:wan" "6@eth0"
370 ;;
371 zbtlink,zbt-we1226|\
372 y1)
373 ucidef_add_switch "switch0" \
374 "0:lan:2" "1:lan:1" "4:wan" "6@eth0"
375 ;;
376 *)
377 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
378 if [ -n "${RT3X5X}" ]; then
379 ramips_setup_rt3x5x_vlans
380 else
381 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
382 fi
383 ;;
384 esac
385 }
386
387 ramips_setup_macs()
388 {
389 local board="$1"
390 local lan_mac=""
391 local wan_mac=""
392
393 case $board in
394 a5-v11|\
395 ht-tm02|\
396 wmdr-143n)
397 lan_mac=$(cat /sys/class/net/eth0/address)
398 ;;
399 all0239-3g|\
400 carambola|\
401 freestation5|\
402 w502u|\
403 wnce2001)
404 wan_mac=$(mtd_get_mac_binary factory 46)
405 ;;
406 bc2|\
407 broadway|\
408 d105|\
409 dir-300-b7|\
410 dir-320-b1|\
411 dir-620-a1|\
412 esr-9753|\
413 freestation5|\
414 hlk-rm04|\
415 mpr-a1|\
416 psr-680w|\
417 sl-r7205|\
418 y1|\
419 y1s)
420 lan_mac=$(cat /sys/class/net/eth0/address)
421 lan_mac=$(macaddr_setbit_la "$lan_mac")
422 wan_mac=$(macaddr_add "$lan_mac" 1)
423 ;;
424 br-6475nd)
425 lan_mac=$(cat /sys/class/net/eth0/address)
426 wan_mac=$(mtd_get_mac_binary devdata 7)
427 ;;
428 cy-swr1100|\
429 dch-m225)
430 lan_mac=$(mtd_get_mac_ascii factory lanmac)
431 ;;
432 dir-645)
433 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
434 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
435 ;;
436 dir-860l-b1)
437 lan_mac=$(mtd_get_mac_ascii factory lanmac)
438 wan_mac=$(mtd_get_mac_ascii factory wanmac)
439 ;;
440 dlink,dwr-116-a1|\
441 dlink,dwr-921-c1)
442 wan_mac=$(jboot_config_read -m -i $(find_mtd_part "config") -o 0xE000)
443 lan_mac=$(macaddr_add "$wan_mac" 1)
444 ;;
445 e1700)
446 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
447 ;;
448 gl-mt300n-v2|\
449 whr-g300n)
450 wan_mac=$(mtd_get_mac_binary factory 4)
451 ;;
452 hc5*61|\
453 hc5661a|\
454 hc5962)
455 lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
456 [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
457 wan_mac=$(macaddr_add "$lan_mac" 1)
458 ;;
459 kn_rc|\
460 kn_rf|\
461 kng_rc)
462 wan_mac=$(mtd_get_mac_binary factory 40)
463 ;;
464 linkits7688)
465 wan_mac=$(mtd_get_mac_binary factory 4)
466 lan_mac=$(mtd_get_mac_binary factory 46)
467 ;;
468 mac1200rv2)
469 lan_mac=$(mtd_get_mac_binary factory_info 13)
470 wan_mac=$(macaddr_add "$lan_mac" 1)
471 ;;
472 mir3g)
473 lan_mac=$(mtd_get_mac_binary Factory 0xe006)
474 ;;
475 miwifi-mini)
476 wan_mac=$(cat /sys/class/net/eth0/address)
477 lan_mac=$(macaddr_setbit_la "$wan_mac")
478 ;;
479 m3|\
480 m4-4M|\
481 m4-8M|\
482 x5|\
483 x8)
484 lan_mac=$(cat /sys/class/net/eth0/address)
485 lan_mac=$(macaddr_add "$lan_mac" -2)
486 ;;
487 newifi-d1)
488 lan_mac=$(cat /sys/class/net/eth0/address)
489 lan_mac=$(macaddr_add "$lan_mac" 2)
490 ;;
491 omega2|\
492 omega2p)
493 wan_mac=$(mtd_get_mac_binary factory 4)
494 lan_mac=$(mtd_get_mac_binary factory 46)
495 ;;
496 oy-0001)
497 lan_mac=$(mtd_get_mac_binary factory 40)
498 wan_mac=$(mtd_get_mac_binary factory 46)
499 ;;
500 r6220)
501 wan_mac=$(mtd_get_mac_binary factory 4)
502 lan_mac=$(macaddr_add "$wan_mac" 1)
503 ;;
504 rt-n56u)
505 lan_mac=$(cat /sys/class/net/eth0/address)
506 lan_mac=$(macaddr_setbit_la "$lan_mac")
507 wan_mac=$(mtd_get_mac_binary factory 32772)
508 ;;
509 sk-wb8)
510 wan_mac=$(mtd_get_mac_binary factory 57350)
511 ;;
512 tew-691gr)
513 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
514 ;;
515 tew-692gr)
516 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
517 ;;
518 tiny-ac)
519 lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
520 wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
521 ;;
522 vr500)
523 lan_mac=$(mtd_get_mac_binary factory 57344)
524 wan_mac=$(mtd_get_mac_binary factory 57350)
525 ;;
526 w306r-v20)
527 lan_mac=$(cat /sys/class/net/eth0/address)
528 wan_mac=$(macaddr_add "$lan_mac" 5)
529 ;;
530 wcr-1166ds|\
531 wsr-1166)
532 local index="$(find_mtd_index "board_data")"
533 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
534 lan_mac=$wan_mac
535 ;;
536 wcr-150gn)
537 wan_mac=$(mtd_get_mac_binary factory 40)
538 ;;
539 whr-1166d|\
540 whr-300hp2|\
541 whr-600d|\
542 wsr-600)
543 wan_mac=$(mtd_get_mac_binary factory 4)
544 lan_mac=$wan_mac
545 ;;
546 wizfi630a)
547 lan_mac=$(mtd_get_mac_binary factory 4)
548 wan_mac=$(mtd_get_mac_binary factory 40)
549 ;;
550 wlr-6000)
551 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
552 ;;
553 *)
554 lan_mac=$(cat /sys/class/net/eth0/address)
555 wan_mac=$(macaddr_add "$lan_mac" 1)
556 ;;
557 esac
558
559 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
560 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
561 }
562
563 board_config_update
564 board=$(board_name)
565 ramips_setup_interfaces $board
566 ramips_setup_macs $board
567 board_config_flush
568
569 exit 0