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