ramips: extract MAC address on WHR-300HP2, WHR-1166D, WHR-600D
[openwrt/staging/yousong.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-new.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 $wanports"
23 else
24 lanports="$port $lanports"
25 fi
26 done
27 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
28 ucidef_add_switch "rt305x" "1" "1"
29 ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
30 ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
31 }
32
33 ramips_setup_interfaces()
34 {
35 local board="$1"
36
37 ucidef_set_interface_loopback
38
39 case $board in
40 a5-v11)
41 ucidef_set_interface_lan "eth0.1"
42 ucidef_add_switch "switch0" "1" "1"
43 ucidef_add_switch_vlan "switch0" "1" "0 6t"
44 ;;
45
46 3g150b | \
47 3g300m | \
48 microwrt | \
49 w150m | \
50 zte-q7 | \
51 all0256n | \
52 all5002 | \
53 all5003 | \
54 broadway | \
55 dcs-930| \
56 ht-tm02| \
57 ncs601w | \
58 wnce2001)
59 ucidef_add_switch "switch0" "1" "0"
60 ucidef_set_interface_lan "eth0"
61 ;;
62
63 3g-6200nl | \
64 mlw221 | \
65 mr-102n)
66 ucidef_set_interface_lan "eth0.2"
67 ;;
68 mlwg2)
69 ucidef_set_interface_lan "eth0.1"
70 ;;
71
72 m2m)
73 ucidef_add_switch "switch0" "4"
74 ucidef_set_interface_lan "eth0"
75 ;;
76
77 wizard8800 | \
78 wl-330n | \
79 wmr300)
80 ucidef_set_interface_lan "eth0.1"
81 ;;
82
83 b2c | \
84 nw718 | \
85 psr-680w | \
86 sl-r7205 | \
87 w502u | \
88 wr6202)
89 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
90 ;;
91
92 awapn2403)
93 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
94 ucidef_add_switch "switch0" "1" "1"
95 ucidef_add_switch_vlan "switch0" "1" "0 6t"
96 ucidef_add_switch_vlan "switch0" "2" "1 6t"
97 ;;
98
99 br-6475nd)
100 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
101 ucidef_add_switch "switch0" "1" "1"
102 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
103 ucidef_add_switch_vlan "switch0" "2" "0 9t"
104 ;;
105
106 asl26555)
107 ucidef_set_interface_lan "eth0.1"
108 ucidef_add_switch "switch0" "1" "1"
109 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
110 ;;
111
112 cf-wr800n)
113 ucidef_set_interface_lan "eth0.1"
114 ucidef_add_switch "switch0" "1" "1"
115 ucidef_add_switch_vlan "switch0" "1" "4 6t"
116 ;;
117
118 cy-swr1100)
119 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
120 ucidef_add_switch "switch0" "1" "1"
121 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t"
122 ucidef_add_switch_vlan "switch0" "2" "4 9t"
123 ;;
124
125 3g-6200n | \
126 ai-br100 | \
127 dir-610-a1 | \
128 dir-300-b7 | \
129 dir-320-b1 | \
130 dir-615-h1 | \
131 firewrt | \
132 hlk-rm04 | \
133 mt7621 | \
134 mt7628 | \
135 mzk-w300nh2 | \
136 mzk-750dhp | \
137 whr-300hp2 | \
138 whr-600d | \
139 wsr-600 | \
140 wsr-1166 | \
141 wt1520 | \
142 xiaomi-miwifi-mini |\
143 y1)
144 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
145 ucidef_add_switch "switch0" "1" "1"
146 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
147 ucidef_add_switch_vlan "switch0" "2" "4 6t"
148 ;;
149
150 whr-1166d)
151 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
152 ucidef_add_switch "switch0" "1" "1"
153 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
154 ucidef_add_switch_vlan "switch0" "2" "5 6t"
155 ;;
156
157 awm002-evb | \
158 awm003-evb | \
159 argus-atp52b | \
160 dir-645 | \
161 dir-860l-b1 | \
162 f5d8235-v1 | \
163 f5d8235-v2 | \
164 hg255d | \
165 rt-n14u | \
166 wrtnode | \
167 wt3020 | \
168 ur-326n4g | \
169 zbt-wa05)
170 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
171 ucidef_add_switch "switch0" "1" "1"
172 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
173 ucidef_add_switch_vlan "switch0" "2" "0 6t"
174 ;;
175
176 ur-336un)
177 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
178 ;;
179
180 br6524n | \
181 v11st-fe)
182 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
183 ucidef_add_switch "switch0" "1" "1"
184 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
185 ucidef_add_switch_vlan "switch0" "2" "0 5t"
186 ;;
187
188 ar670w | \
189 ar725w | \
190 rt-n15 | \
191 wl-351)
192 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
193 ucidef_add_switch "switch0" "1" "1"
194 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
195 ucidef_add_switch_vlan "switch0" "2" "4 5t"
196 ;;
197
198 rt-n56u)
199 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
200 ucidef_add_switch "switch0" "1" "1"
201 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
202 ucidef_add_switch_vlan "switch0" "2" "4 8t"
203 ;;
204
205 tew-691gr|\
206 tew-692gr)
207 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
208 ucidef_add_switch "switch0" "1" "1"
209 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
210 ucidef_add_switch_vlan "switch0" "2" "0t 5"
211 ;;
212
213 vocore)
214 ucidef_set_interface_lan "eth0.1"
215 ucidef_add_switch "switch0" "1" "1"
216 ucidef_add_switch_vlan "switch0" "1" "0 4 6t"
217 ;;
218
219 wcr-150gn)
220 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
221 ucidef_add_switch "switch0" "1" "1"
222 ucidef_add_switch_vlan "switch0" "1" "0 6t"
223 ucidef_add_switch_vlan "switch0" "2" "6t"
224 ;;
225
226 wr8305rt)
227 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
228 ucidef_add_switch "switch0" "1" "1"
229 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
230 ucidef_add_switch_vlan "switch0" "2" "4 6t"
231 ;;
232
233 y1s)
234 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
235 ucidef_add_switch "switch0" "1" "1"
236 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5 6t"
237 ucidef_add_switch_vlan "switch0" "2" "0 6t"
238 ;;
239 d105 | \
240 na930 | \
241 omni-emb-hpm|\
242 wli-tx4-ag300n)
243 ucidef_set_interface_lan "eth0"
244 ;;
245
246 e1700 | \
247 mt7620a_mt7530)
248 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
249 ucidef_add_switch "switch1" "1" "1"
250 ucidef_add_switch_vlan "switch1" "1" "0 1 2 3 6t"
251 ucidef_add_switch_vlan "switch1" "2" "4 6t"
252 ;;
253
254 wzr-agl300nh)
255 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
256 ucidef_add_switch "switch0" "1" "1"
257 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
258 ucidef_add_switch_vlan "switch0" "2" "0 5t"
259 ;;
260 *)
261 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
262 if [ -n "${RT3X5X}" ]; then
263 ramips_setup_rt3x5x_vlans
264 else
265 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
266 fi
267 ;;
268 esac
269 }
270
271 ramips_setup_macs()
272 {
273 local board="$1"
274 local lan_mac=""
275 local wan_mac=""
276
277 case $board in
278 br-6475nd)
279 lan_mac=$(cat /sys/class/net/eth0/address)
280 wan_mac=$(mtd_get_mac_binary devdata 7)
281 ;;
282
283 w306r-v20)
284 lan_mac=$(cat /sys/class/net/eth0/address)
285 wan_mac=$(macaddr_add "$lan_mac" 5)
286 ;;
287
288 tew-691gr)
289 lan_mac=$(cat /sys/class/net/eth0/address)
290 wan_mac=$(macaddr_add "$lan_mac" 3)
291 ;;
292
293 tew-692gr)
294 lan_mac=$(cat /sys/class/net/eth0/address)
295 wan_mac=$(macaddr_add "$lan_mac" 4)
296 ;;
297
298 m3 |\
299 m4 |\
300 x5 |\
301 x8)
302 lan_mac=$(cat /sys/class/net/eth0/address)
303 lan_mac=$(macaddr_add "$lan_mac" -2)
304 ;;
305
306 a5-v11 |\
307 bc2 |\
308 broadway |\
309 d105 |\
310 dir-620-a1 |\
311 esr-9753 |\
312 freestation5 |\
313 hlk-rm04 | \
314 mpr-a1 | \
315 mpr-a2 | \
316 dir-300-b7 | \
317 dir-320-b1 | \
318 psr-680w |\
319 sl-r7205 |\
320 y1 |\
321 y1s)
322 lan_mac=$(cat /sys/class/net/eth0/address)
323 lan_mac=$(macaddr_setbit_la "$lan_mac")
324 wan_mac=$(macaddr_add "$lan_mac" 1)
325 ;;
326
327 ht-tm02)
328 lan_mac=$(cat /sys/class/net/eth0/address)
329 ;;
330
331 cy-swr1100 | \
332 dir-645)
333 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
334 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
335 ;;
336
337 e1700)
338 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
339 ;;
340
341 wcr-150gn)
342 wan_mac=$(mtd_get_mac_binary factory 40)
343 ;;
344
345 rt-n56u)
346 lan_mac=$(cat /sys/class/net/eth0/address)
347 lan_mac=$(macaddr_setbit_la "$lan_mac")
348 wan_mac=$(mtd_get_mac_binary factory 32772)
349 ;;
350
351 all0239-3g | \
352 carambola | \
353 freestation5 | \
354 w502u | \
355 wnce2001)
356 wan_mac=$(mtd_get_mac_binary factory 46)
357 ;;
358
359 wsr-600|whr-300hp2|whr-600d|whr-1166d)
360 wan_mac=$(mtd_get_mac_binary factory 4)
361 lan_mac=$wan_mac
362 ;;
363 wsr-1166)
364 local index="$(find_mtd_index "board_data")"
365 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
366 lan_mac=$wan_mac
367 ;;
368 *)
369 lan_mac=$(cat /sys/class/net/eth0/address)
370 wan_mac=$(macaddr_add "$lan_mac" 1)
371 ;;
372
373 esac
374
375 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
376 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
377 }
378
379 board_config_update
380 board=$(ramips_board_name)
381 ramips_setup_interfaces $board
382 ramips_setup_macs $board
383 board_config_flush
384
385 exit 0