13dfd2b000c56222d8b4ae2485085e2d01c16eb1
[openwrt/openwrt.git] / target / linux / ar71xx / base-files / etc / board.d / 02_network
1 #!/bin/sh
2 #
3 # Copyright (C) 2011-2015 OpenWrt.org
4 #
5
6 . /lib/functions/system.sh
7 . /lib/functions/uci-defaults.sh
8
9 ar71xx_setup_interfaces()
10 {
11 local board="$1"
12
13 case "$board" in
14 airgatewaypro)
15 ucidef_add_switch "switch0" \
16 "0@eth0" "4:lan" "5:wan"
17 ;;
18 airrouter|\
19 ap121|\
20 ap121-mini|\
21 ap96|\
22 dir-600-a1|\
23 dir-615-c1|\
24 dir-615-e1|\
25 dir-615-e4|\
26 hiwifi-hc6361|\
27 ja76pf|\
28 mc-mac1200r|\
29 minibox-v1|\
30 mynet-n600|\
31 oolite-v1|\
32 oolite-v5.2|\
33 oolite-v5.2-dev|\
34 qihoo-c301|\
35 r602n|\
36 rb-750|\
37 rb-751|\
38 som9331|\
39 t830|\
40 tew-632brp|\
41 tew-712br|\
42 tew-732br|\
43 tl-mr3220|\
44 tl-mr3420|\
45 tl-wdr3320-v2|\
46 tl-wdr3500|\
47 tl-wr740n-v6|\
48 tl-wr840n-v2|\
49 tl-wr840n-v3|\
50 tl-wr841n-v11|\
51 tl-wr841n-v9|\
52 tl-wr842n-v3|\
53 whr-g301n|\
54 whr-hp-g300n|\
55 whr-hp-gn|\
56 wzr-hp-ag300h|\
57 zbt-we1526)
58 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
59 ucidef_add_switch "switch0" \
60 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
61 ;;
62 alfa-ap120c|\
63 all0305|\
64 antminer-s1|\
65 antminer-s3|\
66 antrouter-r1|\
67 ap121f|\
68 ap91-5g|\
69 aw-nr580|\
70 bullet-m|\
71 c-55|\
72 cap324|\
73 cap4200ag|\
74 cf-e380ac-v1|\
75 cf-e380ac-v2|\
76 cpe210-v2|\
77 dr342|\
78 eap120|\
79 eap300v2|\
80 eap7660d|\
81 el-mini|\
82 fritz300e|\
83 fritz450e|\
84 gl-usb150|\
85 hiveap-121|\
86 koala|\
87 lbe-m5|\
88 loco-m-xw|\
89 mr12|\
90 mr16|\
91 mr1750|\
92 mr1750v2|\
93 mr18|\
94 mr600|\
95 mr600v2|\
96 mr900|\
97 mr900v2|\
98 mynet-rext|\
99 pqi-air-pen|\
100 rb-411|\
101 rb-411u|\
102 rb-911-2hn|\
103 rb-911-5hn|\
104 rb-911g-2hpnd|\
105 rb-911g-5hpacd|\
106 rb-911g-5hpnd|\
107 rb-912uag-2hpnd|\
108 rb-912uag-5hpnd|\
109 rb-921gs-5hpacd-r2|\
110 rb-lhg-5nd|\
111 rb-mapl-2nd|\
112 rb-sxt2n|\
113 rb-sxt5n|\
114 rb-wap-2nd|\
115 rb-wapr-2nd|\
116 rb-wapg-5hact2hnd|\
117 re355|\
118 re450|\
119 rocket-m-xw|\
120 sc300m |\
121 tl-mr10u|\
122 tl-mr11u|\
123 tl-mr12u|\
124 tl-mr13u|\
125 tl-mr3020|\
126 tl-mr3040|\
127 tl-mr3040-v2|\
128 tl-wa701nd-v2|\
129 tl-wa7210n-v2|\
130 tl-wa750re|\
131 tl-wa801nd-v2|\
132 tl-wa830re-v2|\
133 tl-wa850re|\
134 tl-wa850re-v2|\
135 tl-wa855re-v1|\
136 tl-wa901nd|\
137 tl-wa901nd-v2|\
138 tl-wa901nd-v3|\
139 tl-wa901nd-v4|\
140 tl-wa901nd-v5|\
141 tl-wr703n|\
142 tl-wr802n-v1|\
143 tl-wr802n-v2|\
144 tl-wr902ac-v1|\
145 ts-d084|\
146 tube2h|\
147 unifi|\
148 unifiac-lite|\
149 wi2a-ac200i|\
150 wifi-pineapple-nano|\
151 wndap360|\
152 wp543)
153 ucidef_set_interface_lan "eth0"
154 ;;
155 a40|\
156 a60|\
157 alfa-ap96|\
158 alfa-nx|\
159 archer-c25-v1|\
160 dr344|\
161 gl-ar150|\
162 gl-ar300m|\
163 gl-domino|\
164 gl-inet|\
165 gl-mifi|\
166 jwap003|\
167 om2p-hsv4|\
168 om2pv4|\
169 pb42|\
170 pb44|\
171 rb-951ui-2hnd|\
172 routerstation|\
173 tl-wr710n|\
174 tl-wr720n-v3|\
175 tl-wr810n|\
176 tl-wr810n-v2|\
177 wpe72|\
178 wrtnode2q)
179 ucidef_set_interfaces_lan_wan "eth1" "eth0"
180 ;;
181 rb-750-r2|\
182 rb-750p-pbr2|\
183 rb-750up-r2|\
184 rb-951ui-2nd|\
185 rb-952ui-5ac2nd)
186 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
187 ucidef_add_switch "switch0" \
188 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
189 ;;
190 all0258n|\
191 all0315n|\
192 dlan-hotspot|\
193 dlan-pro-500-wp|\
194 ens202ext|\
195 ja76pf2|\
196 rocket-m-ti|\
197 ubnt-unifi-outdoor)
198 ucidef_set_interface_lan "eth0 eth1"
199 ;;
200 wzr-hp-g300nh2)
201 ucidef_add_switch "switch0" \
202 "0@eth0" "1:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "2:wan"
203 ;;
204 ap132|\
205 ap136|\
206 ap152|\
207 rb-750gl|\
208 rb-751g|\
209 rb-951g-2hnd|\
210 rb-962uigs-5hact2hnt|\
211 wlr8100|\
212 wzr-hp-g450h)
213 ucidef_add_switch "switch0" \
214 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
215 ;;
216 ap135-020|\
217 ap136-020|\
218 bhr-4grv2|\
219 tew-823dru|\
220 tl-wr1043nd-v2|\
221 wzr-450hp2)
222 ucidef_set_interfaces_lan_wan "eth1.1" "eth0.2"
223 ucidef_add_switch "switch0" \
224 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
225 ;;
226 ap136-010|\
227 ap147-010|\
228 nbg6616|\
229 nbg6716)
230 ucidef_set_interfaces_lan_wan "eth0.1" "eth1.2"
231 ucidef_add_switch "switch0" \
232 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth1"
233 ;;
234 ap143|\
235 rb-433|\
236 rb-433u)
237 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
238 ucidef_add_switch "switch0" \
239 "1:lan" "2:lan" "5@eth1"
240 ;;
241 archer-c5|\
242 archer-c7|\
243 tl-wdr4900-v2)
244 ucidef_set_interfaces_lan_wan "eth1.1" "eth0.2"
245 ucidef_add_switch "switch0" \
246 "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
247 ;;
248 archer-c58-v1|\
249 archer-c59-v1|\
250 archer-c59-v2|\
251 fritz4020|\
252 rb-450g)
253 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
254 ucidef_add_switch "switch0" \
255 "0@eth1" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
256 ;;
257 archer-c60-v1|\
258 archer-c60-v2)
259 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
260 ucidef_add_switch "switch0" \
261 "0@eth1" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4"
262 ;;
263 arduino-yun|\
264 dir-505-a1|\
265 tl-wa801nd-v3)
266 ucidef_set_interface_lan "eth1"
267 ;;
268 bsb)
269 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
270 ucidef_add_switch "switch0" \
271 "0@eth1" "1:lan" "3:lan"
272 ;;
273 c-60)
274 ucidef_add_switch "switch0" \
275 "0@eth0" "3:wan" "4:lan"
276 ;;
277 rme-eg200)
278 ucidef_set_interface_lan "eth0" "dhcp"
279 ;;
280 cf-e375ac|\
281 rb-map-2nd)
282 ucidef_add_switch "switch0" \
283 "0@eth0" "1:wan" "2:lan"
284 ;;
285 cf-e385ac)
286 ucidef_set_interfaces_lan_wan "eth0.1" "eth1.2"
287 ucidef_add_switch "switch0" \
288 "0@eth0" "2:lan" "1:wan" "6@eth1"
289 ;;
290 cpe210|\
291 cpe510|\
292 wbs210|\
293 wbs510)
294 ucidef_add_switch "switch0" \
295 "0@eth0" "5:lan" "4:wan"
296 ;;
297 cr3000)
298 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
299 ucidef_add_switch "switch0" \
300 "0@eth0" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
301 ;;
302 cr5000|\
303 dgl-5500-a1|\
304 dhp-1565-a1|\
305 dir-825-c1|\
306 dir-835-a1|\
307 esr900|\
308 mynet-n750|\
309 sr3200)
310 ucidef_add_switch "switch0" \
311 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
312 ;;
313 tl-wr1043n-v5)
314 ucidef_add_switch "switch0" \
315 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
316 ;;
317 dap-2695-a1)
318 ucidef_add_switch "switch0" "0@eth0" "2:lan" "3:wan" "6@eth1"
319 ;;
320 rb-931-2nd)
321 ucidef_add_switch "switch0" \
322 "0@eth0" "1:lan:3" "2:lan:2" "3:wan:1"
323 ;;
324 rb-941-2nd)
325 ucidef_add_switch "switch0" \
326 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:wan:1"
327 ;;
328 db120|\
329 rb-2011il|\
330 rb-2011ils|\
331 rb-2011l|\
332 rb-2011uas|\
333 rb-2011uas-2hnd|\
334 rb-2011uias|\
335 rb-2011uias-2hnd)
336 case "$board" in
337 rb-2011ils|\
338 rb-2011uas*|\
339 rb-2011uias|\
340 rb-2011uias-2hnd)
341 ucidef_add_switch "switch0" \
342 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan" "6:sfp"
343 ;;
344 *)
345 ucidef_add_switch "switch0" \
346 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
347 ;;
348 esac
349
350 ucidef_add_switch "switch1" \
351 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:lan"
352 ;;
353 dir-615-i1|\
354 omy-g1|\
355 r6100|\
356 smart-300|\
357 tl-wdr6500-v2|\
358 tl-wr940n-v4|\
359 tl-wr940n-v6|\
360 tl-wr941nd-v6|\
361 wnr1000-v2|\
362 wnr2000-v4|\
363 wnr2200|\
364 wnr612-v2|\
365 wpn824n)
366 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
367 ucidef_add_switch "switch0" \
368 "0@eth1" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4"
369 ;;
370 tl-mr6400)
371 ucidef_set_interfaces_lan_wan "eth0.1 eth1" "usb0"
372 ucidef_add_switch "switch0" \
373 "0@eth0" "1:lan" "2:lan" "3:lan"
374 ;;
375 dir-825-b1|\
376 nbg460n_550n_550nh|\
377 tew-673gru|\
378 wzr-hp-g300nh)
379 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
380 ucidef_add_switch "switch0" \
381 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
382 ;;
383 dlan-pro-1200-ac)
384 ucidef_set_interface_lan "eth0"
385 ucidef_add_switch "switch0" \
386 "0u@eth0" "2:lan" "3:lan" "4:lan"
387 ucidef_add_switch_attr "switch0" "enable" "false"
388 ;;
389 e1700ac-v2|\
390 e750g-v8|\
391 unifiac-pro|\
392 xd3200)
393 ucidef_add_switch "switch0" \
394 "0@eth0" "2:lan" "3:wan"
395 ;;
396 e558-v2)
397 ucidef_set_interfaces_lan_wan "eth1.1" "eth0.2"
398 ucidef_add_switch "switch0" \
399 "0@eth1" "4:lan" "5:lan" "6@eth0" "3:wan"
400 ;;
401 ebr-2310-c1)
402 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
403 ucidef_add_switch "switch0" \
404 "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4"
405 ;;
406 el-m150)
407 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
408 ucidef_add_switch "switch0" \
409 "0:lan" "1:lan" "3@eth1"
410 ;;
411 dir-869-a1|\
412 epg5000|\
413 esr1750|\
414 tl-wr1043nd-v4|\
415 wndr3700v4|\
416 wndr4300)
417 ucidef_add_switch "switch0" \
418 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
419 ;;
420 ew-balin)
421 ucidef_set_interface "usb2" ifname "usb0" protocol "static"
422 ucidef_add_switch "switch0" \
423 "0@eth0" "5:lan:4" "4:lan:5" "3:wan"
424 ;;
425 ew-dorin)
426 ucidef_add_switch "switch0" \
427 "0@eth0" "1:lan" "2:lan" "3:wan"
428 ;;
429 ew-dorin-router)
430 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
431 ucidef_add_switch "switch0" \
432 "0@eth0" "2:lan" "3:lan"
433 ;;
434 dw33d|\
435 f9k1115v2)
436 ucidef_set_interfaces_lan_wan "eth1.1" "eth0.2"
437 ucidef_add_switch "switch0" \
438 "2:lan" "3:lan" "4:lan" "5:lan" "6@eth1" "0@eth0" "1:wan"
439 ;;
440 gl-ar300|\
441 wnr2000-v3)
442 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
443 ucidef_add_switch "switch0" \
444 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
445 ;;
446 gl-ar750|\
447 rb-435g)
448 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
449 ucidef_add_switch "switch0" \
450 "0@eth1" "1:lan" "2:lan"
451 ;;
452 gl-ar750s)
453 ucidef_add_switch "switch0" \
454 "0@eth0" "2:lan:2" "3:lan:1" "1:wan"
455 ;;
456 jwap230)
457 ucidef_set_interfaces_lan_wan "eth0.1" "eth1.2"
458 ucidef_add_switch "switch0" \
459 "0@eth0" "1:lan" "5:wan" "6@eth1"
460 ;;
461 nanostation-m-xw)
462 ucidef_add_switch "switch0" \
463 "0@eth0" "5:lan" "1:wan"
464 ;;
465 onion-omega)
466 ucidef_set_interface_lan "wlan0"
467 ;;
468 rb-450)
469 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
470 ucidef_add_switch "switch0" \
471 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5@eth1"
472 ;;
473 routerstation-pro)
474 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
475 ucidef_add_switch "switch0" \
476 "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
477 ;;
478 rb-493g)
479 ucidef_set_interfaces_lan_wan "eth0.1 eth1.1" "eth1.2"
480 ucidef_add_switch "switch0" \
481 "0@eth0" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
482 ucidef_add_switch "switch1" \
483 "0@eth1" "1:lan:4" "2:lan:1" "3:lan:3" "4:lan:2" "5:wan"
484 ;;
485 rut900)
486 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
487 ucidef_add_switch "switch0" \
488 "0@eth0" "2:lan:3" "3:lan:2" "4:lan:1"
489 ;;
490 tellstick-znet-lite)
491 ucidef_set_interface_wan "eth0"
492 ucidef_set_interface "wlan" ifname "wlan0" protocol "dhcp"
493 ;;
494 tl-mr3420-v2|\
495 tl-wr841n-v8|\
496 tl-wr842n-v2|\
497 tl-wr941nd-v5|\
498 tl-wr942n-v1)
499 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
500 ucidef_add_switch "switch0" \
501 "0@eth1" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
502 ;;
503 archer-c7-v4|\
504 archer-c7-v5|\
505 tl-wdr4300|\
506 tl-wr1041n-v2)
507 ucidef_add_switch "switch0" \
508 "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
509 ;;
510 tl-wpa8630)
511 ucidef_add_switch "switch0" \
512 "0@eth0" "2:lan:3" "3:lan:2" "4:lan:1" "5:lan:4"
513 ;;
514 tl-wr1043nd)
515 ucidef_add_switch "switch0" \
516 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
517 ;;
518 tl-wr2543n)
519 ucidef_add_switch "switch0" \
520 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
521 ;;
522 tl-mr3220-v2|\
523 tl-wr741nd-v4)
524 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
525 ucidef_add_switch "switch0" \
526 "0@eth0" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
527 ;;
528 tl-wr841n-v1|\
529 tl-wr941nd)
530 ucidef_set_interface "eth" ifname "eth0"
531 ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
532 ;;
533 tl-wr741nd|\
534 tl-wr841n-v7)
535 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
536 ucidef_add_switch "switch0" \
537 "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4"
538 ;;
539 uap-pro|\
540 wpj342)
541 ucidef_add_switch "switch0" \
542 "0@eth0" "1:lan" "2:wan"
543 ;;
544 wndr3700|\
545 wndr3700v2|\
546 wndr3800|\
547 wndr3800ch)
548 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
549 ucidef_add_switch "switch0" \
550 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5@eth0"
551
552 ucidef_add_switch_attr "switch0" "blinkrate" 2
553 ucidef_add_switch_port_attr "switch0" 1 led 6
554 ucidef_add_switch_port_attr "switch0" 2 led 9
555 ucidef_add_switch_port_attr "switch0" 5 led 2
556 ;;
557 wpj344)
558 ucidef_add_switch "switch0" \
559 "0@eth0" "3:lan" "2:wan"
560 ;;
561 wpj558)
562 ucidef_add_switch "switch0" \
563 "5:lan" "1:wan" "6@eth0"
564 ;;
565 wpj563)
566 ucidef_add_switch "switch0" \
567 "0@eth0" "2:lan" "3:wan"
568 ;;
569 wrt160nl)
570 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
571 ucidef_add_switch "switch0" \
572 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4@eth0"
573 ;;
574 wzr-hp-g450h)
575 ucidef_add_switch "switch0" \
576 "0@eth0" "2:lan:1 3:lan:2 4:lan:3 5:lan:4" "1:wan"
577 ;;
578 z1)
579 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
580 ucidef_add_switch "switch0" \
581 "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4" "5:wan"
582 ;;
583 *)
584 ucidef_set_interfaces_lan_wan "eth0" "eth1"
585 ;;
586 esac
587 }
588
589 ar71xx_setup_macs()
590 {
591 local board="$1"
592 local lan_mac=""
593 local wan_mac=""
594
595 case $board in
596 archer-c7-v4)
597 base_mac=$(mtd_get_mac_binary config 8)
598 wan_mac=$(macaddr_add "$base_mac" 1)
599 ;;
600 dgl-5500-a1|\
601 dir-825-c1)
602 wan_mac=$(mtd_get_mac_ascii nvram "wan_mac")
603 ;;
604 dhp-1565-a1|\
605 dir-835-a1|\
606 wndr3700v4|\
607 wndr4300)
608 lan_mac=$(mtd_get_mac_binary caldata 0)
609 wan_mac=$(mtd_get_mac_binary caldata 6)
610 ;;
611 dir-869-a1|\
612 mynet-n750)
613 wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
614 ;;
615 esr900)
616 wan_mac=$(mtd_get_mac_ascii u-boot-env "wanaddr")
617 ;;
618 fritz300e)
619 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
620 ;;
621 tl-wr1043n-v5|\
622 tl-wr1043nd-v4)
623 lan_mac=$(mtd_get_mac_binary product-info 8)
624 wan_mac=$(macaddr_add "$lan_mac" 1)
625 ;;
626 wlr8100)
627 lan_mac=$(mtd_get_mac_ascii u-boot-env "ethaddr")
628 wan_mac=$(mtd_get_mac_ascii u-boot-env "wanaddr")
629 ;;
630 wpj344|\
631 wpj558)
632 wan_mac=$(mtd_get_mac_binary u-boot 0x2e018)
633 ;;
634 esac
635
636 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
637 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
638 }
639
640 board_config_update
641 board=$(board_name)
642 ar71xx_setup_interfaces $board
643 ar71xx_setup_macs $board
644 board_config_flush
645
646 exit 0