ramips: fix mac address of miwifi-mini
[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 wnce2001|\
62 zbt-cpe102|\
63 zte-q7)
64 ucidef_add_switch "switch0"
65 ucidef_add_switch_attr "switch0" "enable" "false"
66 ucidef_set_interface_lan "eth0"
67 ;;
68 mlw221|\
69 mr-102n)
70 ucidef_set_interface_lan "eth0.2"
71 ;;
72 3g-6200n|\
73 ac1200pro|\
74 ai-br100|\
75 db-wrt01|\
76 dir-300-b7|\
77 dir-320-b1|\
78 dir-610-a1|\
79 dir-615-h1|\
80 firewrt|\
81 hlk-rm04|\
82 mac1200rv2|\
83 miwifi-mini|\
84 miwifi-nano|\
85 mt7621|\
86 mt7628|\
87 mzk-750dhp|\
88 mzk-w300nh2|\
89 nixcore|\
90 oy-0001|\
91 pbr-m1|\
92 psg1208|\
93 psg1218|\
94 sap-g3200u3|\
95 sk-wb8|\
96 vr500|\
97 wf-2881|\
98 witi|\
99 wl-wn575a3|\
100 wndr3700v5|\
101 wt1520|\
102 y1|\
103 youku-yk1|\
104 zbt-ape522ii|\
105 zbt-we826|\
106 zbt-wg2626|\
107 zbt-wg3526|\
108 zbt-wr8305rt)
109 ucidef_add_switch "switch0" \
110 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
111 ;;
112 whr-300hp2|\
113 whr-600d|\
114 wsr-1166|\
115 wsr-600)
116 ucidef_add_switch "switch0" \
117 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
118 ;;
119 ar670w|\
120 ar725w|\
121 rt-n15|\
122 wl-351)
123 ucidef_add_switch "switch0" \
124 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
125 ;;
126 asl26555|\
127 rp-n53)
128 ucidef_add_switch "switch0" \
129 "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
130 ;;
131 atp-52b|\
132 awm002-evb|\
133 awm003-evb|\
134 c20i|\
135 c50|\
136 dir-645|\
137 dir-860l-b1|\
138 f5d8235-v2|\
139 gl-mt300a|\
140 gl-mt300n|\
141 gl-mt750|\
142 hg255d|\
143 jhr-n805r|\
144 jhr-n825r|\
145 jhr-n926r|\
146 mzk-wdpr|\
147 rb750gr3|\
148 rt-n14u|\
149 ubnt-erx|\
150 ur-326n4g|\
151 wrtnode|\
152 wrtnode2p | \
153 wrtnode2r | \
154 wt3020|\
155 zbt-wa05)
156 ucidef_add_switch "switch0" \
157 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
158 ;;
159 awapn2403)
160 ucidef_add_switch "switch0" \
161 "0:lan" "1:wan" "6@eth0"
162 ;;
163 b2c|\
164 nw718|\
165 psr-680w|\
166 sl-r7205|\
167 ur-336un|\
168 w502u|\
169 wr6202)
170 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
171 ;;
172 br-6475nd)
173 ucidef_add_switch "switch0" \
174 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
175 ;;
176 cf-wr800n|\
177 ex2700)
178 ucidef_add_switch "switch0" \
179 "4:lan" "6t@eth0"
180 ;;
181 cy-swr1100)
182 ucidef_add_switch "switch0" \
183 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
184 ;;
185 cs-qr10|\
186 d105|\
187 dch-m225|\
188 hpm|\
189 mzk-ex300np|\
190 mzk-ex750np|\
191 na930|\
192 pbr-d1|\
193 wli-tx4-ag300n|\
194 wmr-300|\
195 wn3000rpv3|\
196 wrh-300cr)
197 ucidef_set_interface_lan "eth0"
198 ;;
199 duzun-dm06)
200 ucidef_add_switch "switch0" \
201 "1:lan" "0:wan" "6@eth0"
202 ;;
203 e1700|\
204 mt7620a_mt7530)
205 ucidef_add_switch "switch1" \
206 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
207 ;;
208 hc5*61|\
209 y1s)
210 ucidef_add_switch "switch0" \
211 "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
212 ;;
213 kn_rc|\
214 kn_rf)
215 ucidef_add_switch "switch" \
216 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
217 ;;
218 kng_rc)
219 ucidef_add_switch "switch1" \
220 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
221 ;;
222 mlwg2|\
223 wizard8800|\
224 wl-330n)
225 ucidef_set_interface_lan "eth0.1"
226 ;;
227 mr200)
228 ucidef_add_switch "switch0" \
229 "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
230 ucidef_set_interface_wan "usb0"
231 ;;
232 mzk-dp150n|\
233 vocore)
234 ucidef_add_switch "switch0" \
235 "0:lan" "4:lan" "6t@eth0"
236 ;;
237 newifi-d1)
238 ucidef_add_switch "switch0" \
239 "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
240 ;;
241 re6500)
242 ucidef_add_switch "switch0" \
243 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@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 kng_rc)
350 wan_mac=$(mtd_get_mac_binary factory 28)
351 ;;
352 linkits7688 | \
353 linkits7688d)
354 wan_mac=$(mtd_get_mac_binary factory 4)
355 lan_mac=$(mtd_get_mac_binary factory 46)
356 ;;
357 mac1200rv2)
358 lan_mac=$(mtd_get_mac_binary factory_info 13)
359 wan_mac=$(macaddr_add "$lan_mac" 1)
360 ;;
361 miwifi-mini)
362 wan_mac=$(cat /sys/class/net/eth0/address)
363 lan_mac=$(macaddr_setbit_la "$wan_mac")
364 ;;
365 m3|\
366 m4|\
367 x5|\
368 x8)
369 lan_mac=$(cat /sys/class/net/eth0/address)
370 lan_mac=$(macaddr_add "$lan_mac" -2)
371 ;;
372 newifi-d1)
373 lan_mac=$(cat /sys/class/net/eth0/address)
374 lan_mac=$(macaddr_add "$lan_mac" 2)
375 ;;
376 omega2|\
377 omega2p)
378 wan_mac=$(mtd_get_mac_binary factory 4)
379 lan_mac=$(mtd_get_mac_binary factory 46)
380 ;;
381 oy-0001)
382 lan_mac=$(mtd_get_mac_binary factory 40)
383 wan_mac=$(mtd_get_mac_binary factory 46)
384 ;;
385 rt-n56u)
386 lan_mac=$(cat /sys/class/net/eth0/address)
387 lan_mac=$(macaddr_setbit_la "$lan_mac")
388 wan_mac=$(mtd_get_mac_binary factory 32772)
389 ;;
390 sk-wb8)
391 wan_mac=$(mtd_get_mac_binary factory 57350)
392 ;;
393 tew-691gr)
394 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
395 ;;
396 tew-692gr)
397 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
398 ;;
399 tiny-ac)
400 lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
401 wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
402 ;;
403 vr500)
404 lan_mac=$(mtd_get_mac_binary factory 57344)
405 wan_mac=$(mtd_get_mac_binary factory 57350)
406 ;;
407 w306r-v20)
408 lan_mac=$(cat /sys/class/net/eth0/address)
409 wan_mac=$(macaddr_add "$lan_mac" 5)
410 ;;
411 wcr-150gn)
412 wan_mac=$(mtd_get_mac_binary factory 40)
413 ;;
414 whr-1166d|\
415 whr-300hp2|\
416 whr-600d|\
417 wsr-600)
418 wan_mac=$(mtd_get_mac_binary factory 4)
419 lan_mac=$wan_mac
420 ;;
421 wizfi630a)
422 lan_mac=$(mtd_get_mac_binary factory 4)
423 wan_mac=$(mtd_get_mac_binary factory 40)
424 ;;
425 wlr-6000)
426 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
427 ;;
428 wsr-1166)
429 local index="$(find_mtd_index "board_data")"
430 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
431 lan_mac=$wan_mac
432 ;;
433 *)
434 lan_mac=$(cat /sys/class/net/eth0/address)
435 wan_mac=$(macaddr_add "$lan_mac" 1)
436 ;;
437 esac
438
439 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
440 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
441 }
442
443 board_config_update
444 board=$(ramips_board_name)
445 ramips_setup_interfaces $board
446 ramips_setup_macs $board
447 board_config_flush
448
449 exit 0