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