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