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