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