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