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