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