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