5d25cdba966999bacd88fd8a2fa4e3ea44d87654
[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 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 ravpower,wd03|\
212 wrtnode|\
213 wrtnode2p | \
214 wrtnode2r | \
215 youhua,wr1200js|\
216 zbt-wa05)
217 ucidef_add_switch "switch0" \
218 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
219 ;;
220 c50|\
221 tplink,c20-v1)
222 ucidef_add_switch "switch0" \
223 "1:lan:3" "2:lan:4" "3:lan:1" "4:lan:2" "0:wan" "6@eth0"
224 ;;
225 dir-860l-b1)
226 ucidef_add_switch "switch0" \
227 "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
228 ;;
229 gb-pc1|\
230 gnubee,gb-pc2)
231 ucidef_add_switch "switch0" \
232 "0:lan" "4:lan" "6@eth0"
233 ;;
234 gl-mt300n-v2)
235 ucidef_add_switch "switch0" \
236 "1:lan" "0:wan" "6@eth0"
237 ;;
238 awapn2403)
239 ucidef_add_switch "switch0" \
240 "0:lan" "1:wan" "6@eth0"
241 ;;
242 b2c|\
243 nw718|\
244 psr-680w|\
245 sl-r7205|\
246 ur-336un|\
247 w502u|\
248 wr6202)
249 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
250 ;;
251 br-6475nd)
252 ucidef_add_switch "switch0" \
253 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
254 ;;
255 c108|\
256 cf-wr800n)
257 ucidef_add_switch "switch0" \
258 "4:lan" "6t@eth0"
259 ;;
260 cy-swr1100)
261 ucidef_add_switch "switch0" \
262 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
263 ;;
264 duzun-dm06)
265 ucidef_add_switch "switch0" \
266 "1:lan" "0:wan" "6@eth0"
267 ;;
268 e1700|\
269 mt7620a_mt7530)
270 ucidef_add_switch "switch1" \
271 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
272 ;;
273 hc5*61|\
274 y1s)
275 ucidef_add_switch "switch0" \
276 "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
277 ;;
278 kn_rf)
279 ucidef_add_switch "switch0" \
280 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
281 ;;
282 kng_rc)
283 ucidef_add_switch "switch1" \
284 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
285 ;;
286 mlwg2|\
287 wizard8800|\
288 wl-330n)
289 ucidef_set_interface_lan "eth0.1"
290 ;;
291 mr200)
292 ucidef_add_switch "switch0" \
293 "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
294 ucidef_set_interface_wan "usb0"
295 ;;
296 mzk-dp150n|\
297 vocore-8M|\
298 vocore-16M)
299 ucidef_add_switch "switch0" \
300 "0:lan" "4:lan" "6t@eth0"
301 ;;
302 newifi-d1)
303 ucidef_add_switch "switch0" \
304 "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
305 ;;
306 re350-v1)
307 ucidef_add_switch "switch0" \
308 "0:lan" "6@eth0"
309 ;;
310 re6500)
311 ucidef_add_switch "switch0" \
312 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
313 ;;
314 rt-n56u)
315 ucidef_add_switch "switch0" \
316 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
317 ;;
318 tew-638apb-v2)
319 ucidef_add_switch "switch0" \
320 "4:lan" "6@eth0"
321 ;;
322 tew-691gr|\
323 tew-692gr|\
324 wlr-6000)
325 ucidef_add_switch "switch0" \
326 "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
327 ;;
328 tplink,tl-wr902ac-v3)
329 ucidef_add_switch "switch0" \
330 "4:lan" "6@eth0"
331 ;;
332 vonets,var11n-300|\
333 wt1520-4M|\
334 wt1520-8M)
335 ucidef_add_switch "switch0" \
336 "0:lan" "4:wan" "6@eth0"
337 ;;
338 vocore2|\
339 vocore2lite)
340 ucidef_add_switch "switch0" \
341 "0:lan" "2:lan" "6t@eth0"
342 ;;
343 f5d8235-v1|\
344 tew-714tru|\
345 v11st-fe|\
346 wzr-agl300nh)
347 ucidef_add_switch "switch0" \
348 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
349 ;;
350 wcr-1166ds)
351 ucidef_add_switch "switch0" \
352 "3:lan" "4:wan" "6@eth0"
353 ;;
354 wcr-150gn|\
355 we1026-5g-16m)
356 ucidef_add_switch "switch0" \
357 "0:lan" "6t@eth0"
358 ;;
359 whr-1166d)
360 ucidef_add_switch "switch0" \
361 "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
362 ;;
363 wizfi630a)
364 ucidef_add_switch "switch0" \
365 "1:lan" "2:lan" "0:wan" "6@eth0"
366 ;;
367 wt3020-4M|\
368 wt3020-8M)
369 ucidef_add_switch "switch0" \
370 "4:lan" "0:wan" "6@eth0"
371 ;;
372 zbtlink,zbt-we1226|\
373 y1)
374 ucidef_add_switch "switch0" \
375 "0:lan:2" "1:lan:1" "4:wan" "6@eth0"
376 ;;
377 *)
378 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
379 if [ -n "${RT3X5X}" ]; then
380 ramips_setup_rt3x5x_vlans
381 else
382 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
383 fi
384 ;;
385 esac
386 }
387
388 ramips_setup_macs()
389 {
390 local board="$1"
391 local lan_mac=""
392 local wan_mac=""
393
394 case $board in
395 a5-v11|\
396 ht-tm02|\
397 wmdr-143n)
398 lan_mac=$(cat /sys/class/net/eth0/address)
399 ;;
400 all0239-3g|\
401 carambola|\
402 freestation5|\
403 w502u|\
404 wnce2001)
405 wan_mac=$(mtd_get_mac_binary factory 46)
406 ;;
407 bc2|\
408 broadway|\
409 d105|\
410 dir-300-b7|\
411 dir-320-b1|\
412 dir-620-a1|\
413 esr-9753|\
414 freestation5|\
415 hlk-rm04|\
416 mpr-a1|\
417 psr-680w|\
418 sl-r7205|\
419 y1|\
420 y1s)
421 lan_mac=$(cat /sys/class/net/eth0/address)
422 lan_mac=$(macaddr_setbit_la "$lan_mac")
423 wan_mac=$(macaddr_add "$lan_mac" 1)
424 ;;
425 br-6475nd)
426 lan_mac=$(cat /sys/class/net/eth0/address)
427 wan_mac=$(mtd_get_mac_binary devdata 7)
428 ;;
429 cy-swr1100|\
430 dch-m225)
431 lan_mac=$(mtd_get_mac_ascii factory lanmac)
432 ;;
433 dir-645)
434 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
435 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
436 ;;
437 dir-860l-b1)
438 lan_mac=$(mtd_get_mac_ascii factory lanmac)
439 wan_mac=$(mtd_get_mac_ascii factory wanmac)
440 ;;
441 dlink,dwr-116-a1|\
442 dlink,dwr-921-c1)
443 wan_mac=$(jboot_config_read -m -i $(find_mtd_part "config") -o 0xE000)
444 lan_mac=$(macaddr_add "$wan_mac" 1)
445 ;;
446 e1700)
447 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
448 ;;
449 gl-mt300n-v2|\
450 whr-g300n)
451 wan_mac=$(mtd_get_mac_binary factory 4)
452 ;;
453 hc5*61|\
454 hc5661a|\
455 hc5962)
456 lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
457 [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
458 wan_mac=$(macaddr_add "$lan_mac" 1)
459 ;;
460 kn_rc|\
461 kn_rf|\
462 kng_rc)
463 wan_mac=$(mtd_get_mac_binary factory 40)
464 ;;
465 linkits7688)
466 wan_mac=$(mtd_get_mac_binary factory 4)
467 lan_mac=$(mtd_get_mac_binary factory 46)
468 ;;
469 mac1200rv2)
470 lan_mac=$(mtd_get_mac_binary factory_info 13)
471 wan_mac=$(macaddr_add "$lan_mac" 1)
472 ;;
473 mir3g)
474 lan_mac=$(mtd_get_mac_binary Factory 0xe006)
475 ;;
476 miwifi-mini)
477 wan_mac=$(cat /sys/class/net/eth0/address)
478 lan_mac=$(macaddr_setbit_la "$wan_mac")
479 ;;
480 m3|\
481 m4-4M|\
482 m4-8M|\
483 x5|\
484 x8)
485 lan_mac=$(cat /sys/class/net/eth0/address)
486 lan_mac=$(macaddr_add "$lan_mac" -2)
487 ;;
488 newifi-d1)
489 lan_mac=$(cat /sys/class/net/eth0/address)
490 lan_mac=$(macaddr_add "$lan_mac" 2)
491 ;;
492 omega2|\
493 omega2p)
494 wan_mac=$(mtd_get_mac_binary factory 4)
495 lan_mac=$(mtd_get_mac_binary factory 46)
496 ;;
497 oy-0001)
498 lan_mac=$(mtd_get_mac_binary factory 40)
499 wan_mac=$(mtd_get_mac_binary factory 46)
500 ;;
501 r6220)
502 wan_mac=$(mtd_get_mac_binary factory 4)
503 lan_mac=$(macaddr_add "$wan_mac" 1)
504 ;;
505 rt-n56u)
506 lan_mac=$(cat /sys/class/net/eth0/address)
507 lan_mac=$(macaddr_setbit_la "$lan_mac")
508 wan_mac=$(mtd_get_mac_binary factory 32772)
509 ;;
510 sk-wb8)
511 wan_mac=$(mtd_get_mac_binary factory 57350)
512 ;;
513 tew-691gr)
514 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
515 ;;
516 tew-692gr)
517 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
518 ;;
519 tiny-ac)
520 lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
521 wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
522 ;;
523 vr500)
524 lan_mac=$(mtd_get_mac_binary factory 57344)
525 wan_mac=$(mtd_get_mac_binary factory 57350)
526 ;;
527 w306r-v20)
528 lan_mac=$(cat /sys/class/net/eth0/address)
529 wan_mac=$(macaddr_add "$lan_mac" 5)
530 ;;
531 wcr-1166ds|\
532 wsr-1166)
533 local index="$(find_mtd_index "board_data")"
534 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
535 lan_mac=$wan_mac
536 ;;
537 wcr-150gn)
538 wan_mac=$(mtd_get_mac_binary factory 40)
539 ;;
540 whr-1166d|\
541 whr-300hp2|\
542 whr-600d|\
543 wsr-600)
544 wan_mac=$(mtd_get_mac_binary factory 4)
545 lan_mac=$wan_mac
546 ;;
547 wizfi630a)
548 lan_mac=$(mtd_get_mac_binary factory 4)
549 wan_mac=$(mtd_get_mac_binary factory 40)
550 ;;
551 wlr-6000)
552 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
553 ;;
554 *)
555 lan_mac=$(cat /sys/class/net/eth0/address)
556 wan_mac=$(macaddr_add "$lan_mac" 1)
557 ;;
558 esac
559
560 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
561 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
562 }
563
564 board_config_update
565 board=$(board_name)
566 ramips_setup_interfaces $board
567 ramips_setup_macs $board
568 board_config_flush
569
570 exit 0