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