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