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