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