ar71xx: fix switch port mapping for TP-Link TL-WR74xN/D series
[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 airgatewaypro)
16 ucidef_add_switch "switch0" \
17 "0@eth0" "4:lan" "5:wan"
18 ;;
19 airrouter|\
20 ap121|\
21 ap121-mini|\
22 ap96|\
23 dir-600-a1|\
24 dir-615-c1|\
25 dir-615-e1|\
26 dir-615-e4|\
27 hiwifi-hc6361|\
28 ja76pf|\
29 mc-mac1200r|\
30 minibox-v1|\
31 mynet-n600|\
32 oolite|\
33 qihoo-c301|\
34 r602n|\
35 rb-750|\
36 rb-751|\
37 som9331|\
38 tew-632brp|\
39 tew-712br|\
40 tew-732br|\
41 tl-mr3220|\
42 tl-mr3220-v2|\
43 tl-mr3420|\
44 tl-wdr3320-v2|\
45 tl-wdr3500|\
46 tl-wr740n-v6|\
47 tl-wr741nd-v4|\
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 aw-nr580|\
68 bullet-m|\
69 c-55|\
70 cap4200ag|\
71 cf-e380ac-v1|\
72 cf-e380ac-v2|\
73 eap120|\
74 eap300v2|\
75 eap7660d|\
76 el-mini|\
77 fritz300e|\
78 hiveap-121|\
79 loco-m-xw|\
80 mr12|\
81 mr16|\
82 mr1750|\
83 mr1750v2|\
84 mr18|\
85 mr600|\
86 mr600v2|\
87 mr900|\
88 mr900v2|\
89 mynet-rext|\
90 pqi-air-pen|\
91 rb-411|\
92 rb-411u|\
93 rb-911g-2hpnd|\
94 rb-911g-5hpacd|\
95 rb-911g-5hpnd|\
96 rb-912uag-2hpnd|\
97 rb-912uag-5hpnd|\
98 rb-lhg-5nd|\
99 rb-mapl-2nd|\
100 rb-sxt2n|\
101 rb-sxt5n|\
102 re450|\
103 rocket-m-xw|\
104 sc300m |\
105 tl-mr10u|\
106 tl-mr11u|\
107 tl-mr12u|\
108 tl-mr13u|\
109 tl-mr3020|\
110 tl-mr3040|\
111 tl-mr3040-v2|\
112 tl-wa701nd-v2|\
113 tl-wa7210n-v2|\
114 tl-wa750re|\
115 tl-wa801nd-v2|\
116 tl-wa830re-v2|\
117 tl-wa850re|\
118 tl-wa850re-v2|\
119 tl-wa855re-v1)|\
120 tl-wa901nd|\
121 tl-wa901nd-v2|\
122 tl-wa901nd-v3|\
123 tl-wa901nd-v4|\
124 tl-wr703n|\
125 tl-wr802n-v1|\
126 tl-wr802n-v2|\
127 tube2h|\
128 unifiac-lite|\
129 wndap360|\
130 wp543)
131 ucidef_set_interface_lan "eth0"
132 ;;
133 a40|\
134 a60|\
135 alfa-ap96|\
136 alfa-nx|\
137 archer-c25-v1|\
138 dr344|\
139 gl-ar150|\
140 gl-ar300m|\
141 gl-domino|\
142 gl-inet|\
143 gl-mifi|\
144 jwap003|\
145 om2pv4|\
146 om2p-hsv4|\
147 pb42|\
148 pb44|\
149 rb-750-r2|\
150 rb-750up-r2|\
151 rb-951ui-2hnd|\
152 rb-951ui-2nd|\
153 rb-952ui-5ac2nd|\
154 routerstation|\
155 tl-wr710n|\
156 tl-wr720n-v3|\
157 tl-wr810n|\
158 wpe72|\
159 wrtnode2q)
160 ucidef_set_interfaces_lan_wan "eth1" "eth0"
161 ;;
162 all0258n|\
163 all0315n|\
164 dlan-hotspot|\
165 dlan-pro-500-wp|\
166 ja76pf2|\
167 rocket-m-ti|\
168 ubnt-unifi-outdoor)
169 ucidef_set_interface_lan "eth0 eth1"
170 ;;
171 wzr-hp-g300nh2)
172 ucidef_add_switch "switch0" \
173 "0@eth0" "1:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "2:wan"
174 ;;
175 ap132|\
176 ap136|\
177 ap152|\
178 rb-750gl|\
179 rb-751g|\
180 rb-951g-2hnd|\
181 rb-962uigs-5hact2hnt|\
182 wlr8100|\
183 wzr-hp-g450h)
184 ucidef_add_switch "switch0" \
185 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
186 ;;
187 ap135-020|\
188 ap136-020|\
189 bhr-4grv2|\
190 tew-823dru|\
191 tl-wr1043nd-v2|\
192 wzr-450hp2)
193 ucidef_set_interfaces_lan_wan "eth1.1" "eth0.2"
194 ucidef_add_switch "switch0" \
195 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
196 ;;
197 ap136-010|\
198 ap147-010|\
199 nbg6616|\
200 nbg6716)
201 ucidef_set_interfaces_lan_wan "eth0.1" "eth1.2"
202 ucidef_add_switch "switch0" \
203 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth1"
204 ;;
205 ap143|\
206 rb-433|\
207 rb-433u)
208 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
209 ucidef_add_switch "switch0" \
210 "1:lan" "2:lan" "5@eth1"
211 ;;
212 archer-c5|\
213 archer-c7|\
214 tl-wdr4900-v2)
215 ucidef_set_interfaces_lan_wan "eth1.1" "eth0.2"
216 ucidef_add_switch "switch0" \
217 "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
218 ;;
219 archer-c58-v1|\
220 archer-c59-v1|\
221 rb-450g)
222 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
223 ucidef_add_switch "switch0" \
224 "0@eth1" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
225 ;;
226 archer-c60-v1)
227 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
228 ucidef_add_switch "switch0" \
229 "0@eth1" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4"
230 ;;
231 arduino-yun|\
232 dir-505-a1|\
233 tl-wa801nd-v3)
234 ucidef_set_interface_lan "eth1"
235 ;;
236 bsb)
237 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
238 ucidef_add_switch "switch0" \
239 "0@eth1" "1:lan" "3:lan"
240 ;;
241 c-60)
242 ucidef_add_switch "switch0" \
243 "0@eth0" "3:wan" "4:lan"
244 ;;
245 cap324)
246 ucidef_set_interface_lan "eth0" "dhcp"
247 ;;
248 cpe210|\
249 cpe510|\
250 wbs210|\
251 wbs510)
252 ucidef_add_switch "switch0" \
253 "0@eth0" "5:lan" "4:wan"
254 ;;
255 cr3000)
256 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
257 ucidef_add_switch "switch0" \
258 "0@eth0" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
259 ;;
260 cr5000|\
261 dgl-5500-a1|\
262 dhp-1565-a1|\
263 dir-825-c1|\
264 dir-835-a1|\
265 esr900|\
266 mynet-n750|\
267 sr3200|\
268 wndr3700v4)
269 ucidef_add_switch "switch0" \
270 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
271 ;;
272 dap-2695-a1)
273 ucidef_add_switch "switch0" "0@eth0" "2:lan" "3:wan" "6@eth1"
274 ;;
275 rb-941-2nd)
276 ucidef_add_switch "switch0" \
277 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:wan:1"
278 ;;
279 db120|\
280 rb-2011il|\
281 rb-2011l|\
282 rb-2011uas|\
283 rb-2011uas-2hnd|\
284 rb-2011uias|\
285 rb-2011uias-2hnd)
286 case "$board" in
287 rb-2011uas*|\
288 rb-2011uias|\
289 rb-2011uias-2hnd)
290 ucidef_add_switch "switch0" \
291 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan" "6:sfp"
292 ;;
293 *)
294 ucidef_add_switch "switch0" \
295 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
296 ;;
297 esac
298
299 ucidef_add_switch "switch1" \
300 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:lan"
301 ;;
302 dir-615-i1|\
303 omy-g1|\
304 r6100|\
305 smart-300|\
306 tl-wdr6500-v2|\
307 tl-wr940n-v4|\
308 tl-wr941nd-v6|\
309 wnr1000-v2|\
310 wnr2000-v4|\
311 wnr2200|\
312 wnr612-v2|\
313 wpn824n)
314 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
315 ucidef_add_switch "switch0" \
316 "0@eth1" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4"
317 ;;
318 tl-mr6400)
319 ucidef_set_interfaces_lan_wan "eth0.1 eth1" "usb0"
320 ucidef_add_switch "switch0" \
321 "0@eth0" "1:lan" "2:lan" "3:lan"
322 ;;
323 dir-825-b1|\
324 nbg460n_550n_550nh|\
325 tew-673gru|\
326 wzr-hp-g300nh)
327 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
328 ucidef_add_switch "switch0" \
329 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
330 ;;
331 dlan-pro-1200-ac)
332 ucidef_set_interface_lan "eth0"
333 ucidef_add_switch "switch0" \
334 "0u@eth0" "2:lan" "3:lan" "4:lan"
335 ucidef_add_switch_attr "switch0" "enable" "false"
336 ;;
337 ebr-2310-c1)
338 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
339 ucidef_add_switch "switch0" \
340 "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4"
341 ;;
342 el-m150)
343 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
344 ucidef_add_switch "switch0" \
345 "0:lan" "1:lan" "3@eth1"
346 ;;
347 dir-869-a1|\
348 epg5000|\
349 esr1750|\
350 tl-wr1043nd-v4|\
351 wndr4300)
352 ucidef_add_switch "switch0" \
353 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
354 ;;
355 ew-dorin)
356 ucidef_add_switch "switch0" \
357 "0@eth0" "1:lan" "2:lan" "3:wan"
358 ;;
359 ew-dorin-router)
360 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
361 ucidef_add_switch "switch0" \
362 "0@eth0" "2:lan" "3:lan"
363 ;;
364 dw33d|\
365 f9k1115v2)
366 ucidef_set_interfaces_lan_wan "eth1.1" "eth0.2"
367 ucidef_add_switch "switch0" \
368 "2:lan" "3:lan" "4:lan" "5:lan" "6@eth1" "0@eth0" "1:wan"
369 ;;
370 gl-ar300|\
371 wnr2000-v3)
372 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
373 ucidef_add_switch "switch0" \
374 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
375 ;;
376 jwap230)
377 ucidef_set_interfaces_lan_wan "eth0.1" "eth1.2"
378 ucidef_add_switch "switch0" \
379 "0@eth0" "1:lan" "5:wan" "6@eth1"
380 ;;
381 nanostation-m-xw)
382 ucidef_add_switch "switch0" \
383 "0@eth0" "5:lan" "1:wan"
384 ;;
385 onion-omega)
386 ucidef_set_interface_lan "wlan0"
387 ;;
388 rb-435g)
389 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
390 ucidef_add_switch "switch0" \
391 "0@eth1" "1:lan" "2:lan"
392 ;;
393 rb-450)
394 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
395 ucidef_add_switch "switch0" \
396 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5@eth1"
397 ;;
398 routerstation-pro)
399 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
400 ucidef_add_switch "switch0" \
401 "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
402 ;;
403 rb-493g)
404 ucidef_set_interfaces_lan_wan "eth0.1 eth1.1" "eth1.2"
405 ucidef_add_switch "switch0" \
406 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan"
407 ucidef_add_switch "switch1" \
408 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
409 ;;
410 tellstick-znet-lite)
411 ucidef_set_interface_wan "eth0"
412 ucidef_set_interface_raw "wlan" "wlan0" "dhcp"
413 ;;
414 tl-mr3420-v2|\
415 tl-wr841n-v8|\
416 tl-wr842n-v2|\
417 tl-wr941nd-v5|\
418 tl-wr942n-v1)
419 ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
420 ucidef_add_switch "switch0" \
421 "0@eth1" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
422 ;;
423 tl-wdr4300|\
424 tl-wr1041n-v2)
425 ucidef_add_switch "switch0" \
426 "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
427 ;;
428 tl-wpa8630)
429 ucidef_add_switch "switch0" \
430 "0@eth0" "2:lan:3" "3:lan:2" "4:lan:1" "5:lan:4"
431 ;;
432 tl-wr1043nd)
433 ucidef_add_switch "switch0" \
434 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
435 ;;
436 tl-wr2543n)
437 ucidef_add_switch "switch0" \
438 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
439 ;;
440 tl-wr841n-v1|\
441 tl-wr941nd)
442 ucidef_set_interface_raw "eth" "eth0"
443 ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
444 ;;
445 tl-wr741nd|\
446 tl-wr841n-v7)
447 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
448 ucidef_add_switch "switch0" \
449 "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4"
450 ;;
451 uap-pro|\
452 wpj342)
453 ucidef_add_switch "switch0" \
454 "0@eth0" "1:lan" "2:wan"
455 ;;
456 unifiac-pro|\
457 xd3200)
458 ucidef_add_switch "switch0" \
459 "0@eth0" "2:lan" "3:wan"
460 ;;
461 wndr3700|\
462 wndr3700v2|\
463 wndr3800|\
464 wndr3800ch)
465 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
466 ucidef_add_switch "switch0" \
467 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5@eth0"
468
469 ucidef_add_switch_attr "switch0" "blinkrate" 2
470 ucidef_add_switch_port_attr "switch0" 1 led 6
471 ucidef_add_switch_port_attr "switch0" 2 led 9
472 ucidef_add_switch_port_attr "switch0" 5 led 2
473 ;;
474 wpj344)
475 ucidef_add_switch "switch0" \
476 "0@eth0" "3:lan" "2:wan"
477 ;;
478 wpj558)
479 ucidef_add_switch "switch0" \
480 "5:lan" "1:wan" "6@eth0"
481 ;;
482 wpj563)
483 ucidef_add_switch "switch0" \
484 "0@eth0" "2:lan" "3:wan"
485 ;;
486 wrt160nl)
487 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
488 ucidef_add_switch "switch0" \
489 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4@eth0"
490 ;;
491 wzr-hp-g450h)
492 ucidef_add_switch "switch0" \
493 "0@eth0" "2:lan:1 3:lan:2 4:lan:3 5:lan:4" "1:wan"
494 ;;
495 z1)
496 ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
497 ucidef_add_switch "switch0" \
498 "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4" "5:wan"
499 ;;
500 *)
501 ucidef_set_interfaces_lan_wan "eth0" "eth1"
502 ;;
503 esac
504 }
505
506 ar71xx_setup_macs()
507 {
508 local board="$1"
509 local lan_mac=""
510 local wan_mac=""
511
512 case $board in
513 dgl-5500-a1|\
514 dir-825-c1)
515 wan_mac=$(mtd_get_mac_ascii nvram "wan_mac")
516 ;;
517 dhp-1565-a1|\
518 dir-835-a1|\
519 wndr3700v4|\
520 wndr4300)
521 lan_mac=$(mtd_get_mac_binary caldata 0)
522 wan_mac=$(mtd_get_mac_binary caldata 6)
523 ;;
524 fritz300e)
525 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
526 ;;
527 tl-wr1043nd-v4)
528 wan_mac=$(mtd_get_mac_binary config 0x1017c)
529 ;;
530 esr900)
531 wan_mac=$(mtd_get_mac_ascii u-boot-env "wanaddr")
532 ;;
533 dir-869-a1|\
534 mynet-n750)
535 wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
536 ;;
537 wpj344)
538 wan_mac=$(mtd_get_mac_binary u-boot 0x2e018)
539 ;;
540 esac
541
542 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
543 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
544 }
545
546 board_config_update
547 board=$(ar71xx_board_name)
548 ar71xx_setup_interfaces $board
549 ar71xx_setup_macs $board
550 board_config_flush
551
552 exit 0