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