ar71xx: base-files: rework etc/board.d/02_network
[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 . /lib/ar71xx.sh
9
10 ar71xx_setup_interfaces()
11 {
12 local board="$1"
13
14 case "$board" in
15 all0315n |\
16 all0258n |\
17 dr344 |\
18 ja76pf2|\
19 rocket-m-ti |\
20 ubnt-unifi-outdoor)
21 ucidef_set_interface_lan "eth0 eth1"
22 ;;
23
24 ap132 |\
25 ap152 |\
26 wlr8100)
27 ucidef_add_switch "switch0" \
28 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
29 ;;
30
31 esr1750 |\
32 epg5000)
33 ucidef_add_switch "switch0" \
34 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
35 ;;
36
37 cr5000)
38 ucidef_add_switch "switch0" \
39 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
40 ;;
41
42 ap136-010 |\
43 ap147-010)
44 ucidef_set_interfaces_lan_wan "eth0" "eth1"
45 ucidef_add_switch "switch0" \
46 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth1"
47 ;;
48
49 ap136-020 |\
50 ap135-020 |\
51 tew-823dru |\
52 tl-wr1043nd-v2 |\
53 wzr-450hp2)
54 ucidef_set_interfaces_lan_wan "eth1" "eth0"
55 ucidef_add_switch "switch0" \
56 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
57 ;;
58
59 archer-c5 |\
60 archer-c7 |\
61 tl-wdr4900-v2)
62 ucidef_set_interfaces_lan_wan "eth1" "eth0"
63 ucidef_add_switch "switch0" \
64 "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
65 ;;
66
67 bsb)
68 ucidef_set_interfaces_lan_wan "eth1" "eth0"
69 ucidef_add_switch "switch0" \
70 "0@eth1" "1:lan" "3:lan" # XXX: confirm cpu port!
71 ;;
72
73 cpe210|\
74 cpe510)
75 ucidef_add_switch "switch0" \
76 "0@eth0" "5:lan" "4:wan"
77 ;;
78
79 airgatewaypro)
80 ucidef_add_switch "switch0" \
81 "0@eth0" "4:lan" "5:wan"
82 ;;
83
84 db120 |\
85 rb-2011l | \
86 rb-2011uas |\
87 rb-2011uias |\
88 rb-2011uas-2hnd|\
89 rb-2011uias-2hnd)
90 case "$board" in
91 rb-2011uas* | rb-2011uias | rb-2011uias-2hnd)
92 ucidef_add_switch "switch0" \
93 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan" "6:sfp"
94 ;;
95 *)
96 ucidef_add_switch "switch0" \
97 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
98 ;;
99 esac
100
101 ucidef_add_switch "switch1" \
102 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:lan"
103 ;;
104
105 dir-825-b1|\
106 tew-673gru)
107 ucidef_set_interfaces_lan_wan "eth0" "eth1"
108 ucidef_add_switch "switch0" \
109 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
110 ;;
111
112 f9k1115v2)
113 ucidef_set_interfaces_lan_wan "eth1" "eth0"
114 ucidef_add_switch "switch0" \
115 "2:lan" "3:lan" "4:lan" "5:lan" "6@eth1" \
116 "0@eth0" "1:wan" # XXX: confirm cpu ports!
117 ;;
118
119 nbg460n_550n_550nh)
120 ucidef_set_interfaces_lan_wan "eth0" "eth1"
121 ucidef_add_switch "switch0" \
122 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
123 ;;
124
125 nbg6616 |\
126 nbg6716)
127 ucidef_set_interfaces_lan_wan "eth0" "eth1"
128 ucidef_add_switch "switch0" \
129 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" \
130 "5:wan" "6@eth1"
131 ;;
132
133 ap143 |\
134 rb-433 |\
135 rb-433u)
136 ucidef_set_interfaces_lan_wan "eth1" "eth0"
137 ucidef_add_switch "switch0" \
138 "1:lan" "2:lan" "5@eth1"
139 ;;
140
141 rb-435g)
142 ucidef_set_interfaces_lan_wan "eth1" "eth0"
143 ucidef_add_switch "switch0" \
144 "0@eth1" "1:lan" "2:lan" # XXX: confirm!
145 ;;
146
147 rb-450)
148 ucidef_set_interfaces_lan_wan "eth1" "eth0"
149 ucidef_add_switch "switch0" \
150 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth1"
151 ;;
152
153 rb-450g |\
154 routerstation-pro)
155 ucidef_set_interfaces_lan_wan "eth1" "eth0"
156 ucidef_add_switch "switch0" \
157 "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
158 ;;
159
160 ap136 |\
161 rb-750gl |\
162 rb-751g |\
163 rb-951g-2hnd |\
164 wzr-hp-g450h)
165 ucidef_add_switch "switch0" \
166 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
167 ;;
168
169 rb-951ui-2hnd)
170 ucidef_set_interfaces_lan_wan "eth1" "eth0"
171 ;;
172
173 rb-493g)
174 ucidef_set_interfaces_lan_wan "eth0 eth1.1" "eth1.2"
175 ucidef_add_switch "switch0" \
176 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan"
177 ucidef_add_switch "switch1" \
178 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
179 ;;
180
181 wzr-hp-g300nh2 |\
182 pb92 |\
183 ap113)
184 ucidef_add_switch "switch0" \
185 "0@eth0" "1:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "2:wan"
186 ;;
187
188 el-m150)
189 ucidef_set_interfaces_lan_wan "eth1" "eth0"
190 ucidef_add_switch "switch0" \
191 "0:lan" "1:lan" "3@eth1" # XXX: confirm!
192 ;;
193
194 tellstick-znet-lite)
195 ucidef_set_interface_wan "eth0"
196 ucidef_set_interface_raw "wlan" "wlan0" "dhcp"
197 ;;
198
199 tl-wdr4300|\
200 tl-wr1041n-v2)
201 ucidef_add_switch "switch0" \
202 "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
203 ;;
204
205 tl-wr1043nd)
206 ucidef_add_switch "switch0" \
207 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
208 ;;
209
210 tl-wr2543n)
211 ucidef_add_switch "switch0" \
212 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
213 ;;
214
215 tl-wr841n-v1|\
216 tl-wr941nd)
217 ucidef_set_interface_raw "eth" "eth0"
218 ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
219 ;;
220
221 dir-615-i1 |\
222 omy-g1 |\
223 r6100 |\
224 smart-300 |\
225 tl-mr3420-v2 |\
226 tl-wr841n-v8 |\
227 tl-wr842n-v2 |\
228 tl-wr941nd-v5 |\
229 tl-wr941nd-v6 |\
230 tl-wdr6500-v2 |\
231 wnr2000-v3 |\
232 wnr2000-v4 |\
233 wnr2200 |\
234 wnr612-v2 |\
235 wnr1000-v2 |\
236 wpn824n)
237 ucidef_set_interfaces_lan_wan "eth1" "eth0"
238 ucidef_add_switch "switch0" \
239 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4@eth1" # XXX: confirm!
240 ;;
241
242 uap-pro)
243 ucidef_add_switch "switch0" \
244 "0@eth0" "1:lan" "2:wan"
245 ;;
246
247 nanostation-m-xw)
248 ucidef_add_switch "switch0" \
249 "0@eth0" "5:lan" "1:wan"
250 ;;
251
252 wrt160nl)
253 ucidef_set_interfaces_lan_wan "eth0" "eth1"
254 ucidef_add_switch "switch0" \
255 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4@eth0"
256 ;;
257
258 wzr-hp-g300nh)
259 ucidef_set_interfaces_lan_wan "eth0" "eth1"
260 ucidef_add_switch "switch0" \
261 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
262 ;;
263
264 cr3000)
265 ucidef_set_interfaces_lan_wan "eth0" "eth1"
266 ucidef_add_switch "switch0" \
267 "0@eth0" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
268 ;;
269
270 dgl-5500-a1 |\
271 dir-825-c1)
272 ucidef_add_switch "switch0" \
273 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
274 ;;
275
276 mynet-n750)
277 ucidef_add_switch "switch0" \
278 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
279 ;;
280
281 onion-omega)
282 ucidef_set_interface_lan "wlan0"
283 ;;
284
285 dhp-1565-a1 |\
286 dir-835-a1 |\
287 wndr3700v4 | \
288 wndr4300)
289 ucidef_add_switch "switch0" \
290 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
291 ;;
292
293 esr900)
294 ucidef_add_switch "switch0" \
295 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
296 ;;
297
298 dlan-hotspot |\
299 dlan-pro-500-wp)
300 ucidef_set_interface_lan "eth0 eth1"
301 ;;
302
303 dlan-pro-1200-ac)
304 ucidef_set_interface_lan "eth0"
305 ucidef_add_switch "switch0" \
306 "0@eth0" "2:lan" "3:lan" "4:lan"
307 ucidef_add_switch_attr "switch0" "enable" "false"
308 ;;
309
310 alfa-ap120c |\
311 all0305 |\
312 antminer-s1 |\
313 antminer-s3 |\
314 antrouter-r1 |\
315 aw-nr580 |\
316 bullet-m |\
317 c-55 |\
318 cap4200ag |\
319 eap300v2 |\
320 eap7660d |\
321 el-mini |\
322 loco-m-xw |\
323 mr1750 |\
324 mr1750v2 |\
325 mr18 |\
326 mr600 |\
327 mr600v2 |\
328 mr900 |\
329 mr900v2 |\
330 rb-411 |\
331 rb-911g-2hpnd |\
332 rb-911g-5hpacd |\
333 rb-911g-5hpnd |\
334 rb-912uag-2hpnd |\
335 rb-912uag-5hpnd |\
336 rb-sxt2n |\
337 rb-sxt5n |\
338 rocket-m-xw |\
339 tl-mr10u |\
340 tl-mr11u |\
341 tl-mr12u |\
342 tl-mr13u |\
343 tl-mr3020 |\
344 tl-mr3040 |\
345 tl-mr3040-v2 |\
346 tl-wa701nd-v2 |\
347 tl-wa7210n-v2 |\
348 tl-wa750re |\
349 tl-wa850re |\
350 tl-wa830re-v2 |\
351 tl-wa801nd-v2 |\
352 tl-wa901nd |\
353 tl-wa901nd-v2 |\
354 tl-wa901nd-v3 |\
355 tl-wa901nd-v4 |\
356 tl-wr703n |\
357 tube2h |\
358 unifiac-lite |\
359 wndap360 |\
360 mynet-rext |\
361 wp543)
362 ucidef_set_interface_lan "eth0"
363 ;;
364
365 cap324)
366 ucidef_set_interface_lan "eth0" "dhcp"
367 ;;
368
369 arduino-yun |\
370 tl-wa801nd-v3 |\
371 dir-505-a1)
372 ucidef_set_interface_lan "eth1"
373 ;;
374
375 alfa-ap96 |\
376 alfa-nx |\
377 ap83 |\
378 gl-ar150 |\
379 gl-ar300m |\
380 gl-domino |\
381 gl-inet |\
382 gl-mifi |\
383 jwap003 |\
384 pb42 |\
385 pb44 |\
386 routerstation|\
387 tl-wr710n |\
388 tl-wr720n-v3|\
389 tl-wr810n |\
390 wpe72 |\
391 wrtnode2q)
392 ucidef_set_interfaces_lan_wan "eth1" "eth0"
393 ;;
394
395 gl-ar300)
396 ucidef_set_interfaces_lan_wan "eth1" "eth0"
397 ucidef_add_switch "switch0" \
398 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
399 ;;
400
401 jwap230)
402 ucidef_set_interfaces_lan_wan "eth0" "eth1"
403 ucidef_add_switch "switch0" \
404 "0@eth0" "1:lan" "5:wan" "6@eth1"
405 ;;
406
407 wpj342)
408 ucidef_add_switch "switch0" \
409 "0@eth0" "1:lan" "2:wan"
410 ;;
411
412 wpj344)
413 ucidef_add_switch "switch0" \
414 "0@eth0" "3:lan" "2:wan"
415 ;;
416
417 unifiac-pro)
418 ucidef_add_switch "switch0" \
419 "0@eth0" "2:lan" "3:wan"
420 ;;
421
422 dr531 |\
423 wpj531)
424 ucidef_set_interfaces_lan_wan "eth0" "eth1"
425 ;;
426
427 wpj558)
428 ucidef_add_switch "switch0" \
429 "5:lan" "1:wan" "6@eth0"
430 ;;
431
432 ap121 |\
433 ap121-mini |\
434 ap96 |\
435 airrouter |\
436 dir-600-a1 |\
437 dir-615-c1 |\
438 dir-615-e1 |\
439 dir-615-e4 |\
440 hiwifi-hc6361 |\
441 ja76pf |\
442 mc-mac1200r|\
443 minibox-v1 |\
444 mynet-n600 |\
445 oolite |\
446 qihoo-c301 |\
447 rb-750 |\
448 rb-751 |\
449 som9331 |\
450 tew-632brp |\
451 tew-712br |\
452 tew-732br |\
453 tl-mr3220 |\
454 tl-mr3220-v2 |\
455 tl-mr3420 |\
456 tl-wdr3320-v2 |\
457 tl-wdr3500 |\
458 tl-wr741nd |\
459 tl-wr741nd-v4 |\
460 tl-wr841n-v7 |\
461 tl-wr841n-v9 |\
462 tl-wr841n-v11 |\
463 tl-wr842n-v3 |\
464 whr-g301n |\
465 whr-hp-g300n |\
466 whr-hp-gn |\
467 wzr-hp-ag300h |\
468 zbt-we1526)
469 ucidef_set_interfaces_lan_wan "eth0" "eth1"
470 ucidef_add_switch "switch0" \
471 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
472 ;;
473
474 wzr-hp-g450h)
475 ucidef_add_switch "switch0" \
476 "0@eth0" "2:lan:1 3:lan:2 4:lan:3 5:lan:4" "1:wan"
477 ;;
478
479 ew-dorin)
480 ucidef_add_switch "switch0" \
481 "0@eth0" "1:lan" "2:lan" "3:wan"
482 ;;
483
484 ew-dorin-router)
485 ucidef_set_interfaces_lan_wan "eth0" "eth1"
486 ucidef_add_switch "switch0" "0@eth0" "2:lan" "3:lan"
487 ;;
488
489 wndr3700)
490 ucidef_set_interfaces_lan_wan "eth0" "eth1"
491 ucidef_add_switch "switch0" \
492 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
493
494 # Blinkrate: 0=43ms; 1=84ms; 2=120ms; 3=170ms; 4=340ms; 5=670ms
495 ucidef_add_switch_attr "switch0" "blinkrate" 2
496
497 # Port 1 controls the GREEN configuration of LEDs for
498 # the switch and the section does not correspond to a real
499 # switch port.
500 #
501 # 0=LED off; 1=Collision/FDX; 2=Link/activity; 3=1000 Mb/s;
502 # 4=100 Mb/s; 5=10 Mb/s; 6=1000 Mb/s+activity; 7=100 Mb/s+activity;
503 # 8=10 Mb/s+activity; 9=10/100 Mb/s+activity; 10: Fiber;
504 # 11: Fault; 12: Link/activity(tx); 13: Link/activity(rx);
505 # 14: Link (master); 15: separate register
506 ucidef_add_switch_port_attr "switch0" 1 led 6
507
508 # Port 2 controls the ORANGE configuration of LEDs for
509 # the switch and the section does not correspond to a real
510 # switch port.
511 #
512 # See the key above for switch port 1 for the meaning of the
513 # 'led' setting below.
514 ucidef_add_switch_port_attr "switch0" 2 led 9
515
516 # Port 5 controls the configuration of the WAN LED and the
517 # section does not correspond to a real switch port.
518 #
519 # To toggle the use of green or orange LEDs for the WAN port,
520 # see the LED setting for wndr3700:green:wan in /etc/config/system.
521 #
522 # See the key above for switch port 1 for the meaning of the
523 # 'led' setting below.
524 ucidef_add_switch_port_attr "switch0" 5 led 2
525 ;;
526
527 z1)
528 ucidef_set_interfaces_lan_wan "eth0" "eth1"
529 ucidef_add_switch "switch0" \
530 "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4" "5:wan"
531 ;;
532
533 *)
534 ucidef_set_interfaces_lan_wan "eth0" "eth1"
535 ;;
536 esac
537 }
538
539 ar71xx_setup_macs()
540 {
541 local board="$1"
542 local lan_mac=""
543 local wan_mac=""
544
545 case $board in
546 dgl-5500-a1|\
547 dir-825-c1)
548 wan_mac=$(mtd_get_mac_ascii nvram "wan_mac")
549 ;;
550 dhp-1565-a1|\
551 dir-835-a1|\
552 wndr3700v4|\
553 wndr4300)
554 lan_mac=$(mtd_get_mac_binary caldata 0)
555 wan_mac=$(mtd_get_mac_binary caldata 6)
556 ;;
557 esr900)
558 wan_mac=$(mtd_get_mac_ascii u-boot-env "wanaddr")
559 ;;
560 mynet-n750)
561 wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
562 ;;
563 esac
564
565 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
566 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
567 }
568
569 board_config_update
570 board=$(ar71xx_board_name)
571 ar71xx_setup_interfaces $board
572 ar71xx_setup_macs $board
573 board_config_flush
574
575 exit 0