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