ramips: add support for Planex MZK-DP150N
[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 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 mzk-dp150n)
266 ucidef_set_interface_lan "eth0.1"
267 ucidef_add_switch "switch0" "1" "1"
268 ucidef_add_switch_vlan "switch0" "1" "0 4 6t"
269 ;;
270
271 *)
272 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
273 if [ -n "${RT3X5X}" ]; then
274 ramips_setup_rt3x5x_vlans
275 else
276 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
277 fi
278 ;;
279 esac
280 }
281
282 ramips_setup_macs()
283 {
284 local board="$1"
285 local lan_mac=""
286 local wan_mac=""
287
288 case $board in
289 br-6475nd)
290 lan_mac=$(cat /sys/class/net/eth0/address)
291 wan_mac=$(mtd_get_mac_binary devdata 7)
292 ;;
293
294 oy-0001)
295 lan_mac=$(mtd_get_mac_binary factory 40)
296 wan_mac=$(mtd_get_mac_binary factory 46)
297 ;;
298
299 w306r-v20)
300 lan_mac=$(cat /sys/class/net/eth0/address)
301 wan_mac=$(macaddr_add "$lan_mac" 5)
302 ;;
303
304 tew-691gr)
305 lan_mac=$(cat /sys/class/net/eth0/address)
306 wan_mac=$(macaddr_add "$lan_mac" 3)
307 ;;
308
309 tew-692gr)
310 lan_mac=$(cat /sys/class/net/eth0/address)
311 wan_mac=$(macaddr_add "$lan_mac" 4)
312 ;;
313
314 m3 |\
315 m4 |\
316 x5 |\
317 x8)
318 lan_mac=$(cat /sys/class/net/eth0/address)
319 lan_mac=$(macaddr_add "$lan_mac" -2)
320 ;;
321
322 a5-v11 |\
323 bc2 |\
324 broadway |\
325 d105 |\
326 dir-620-a1 |\
327 esr-9753 |\
328 freestation5 |\
329 hlk-rm04 | \
330 mpr-a1 | \
331 mpr-a2 | \
332 dir-300-b7 | \
333 dir-320-b1 | \
334 psr-680w |\
335 sl-r7205 |\
336 y1 |\
337 y1s)
338 lan_mac=$(cat /sys/class/net/eth0/address)
339 lan_mac=$(macaddr_setbit_la "$lan_mac")
340 wan_mac=$(macaddr_add "$lan_mac" 1)
341 ;;
342
343 ht-tm02)
344 lan_mac=$(cat /sys/class/net/eth0/address)
345 ;;
346
347 cy-swr1100 | \
348 dir-645)
349 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
350 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
351 ;;
352
353 e1700)
354 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
355 ;;
356
357 wcr-150gn)
358 wan_mac=$(mtd_get_mac_binary factory 40)
359 ;;
360
361 rt-n56u)
362 lan_mac=$(cat /sys/class/net/eth0/address)
363 lan_mac=$(macaddr_setbit_la "$lan_mac")
364 wan_mac=$(mtd_get_mac_binary factory 32772)
365 ;;
366
367 all0239-3g | \
368 carambola | \
369 freestation5 | \
370 w502u | \
371 wnce2001)
372 wan_mac=$(mtd_get_mac_binary factory 46)
373 ;;
374
375 wsr-600|whr-300hp2|whr-600d|whr-1166d)
376 wan_mac=$(mtd_get_mac_binary factory 4)
377 lan_mac=$wan_mac
378 ;;
379 wsr-1166)
380 local index="$(find_mtd_index "board_data")"
381 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
382 lan_mac=$wan_mac
383 ;;
384 *)
385 lan_mac=$(cat /sys/class/net/eth0/address)
386 wan_mac=$(macaddr_add "$lan_mac" 1)
387 ;;
388
389 esac
390
391 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
392 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
393 }
394
395 board_config_update
396 board=$(ramips_board_name)
397 ramips_setup_interfaces $board
398 ramips_setup_macs $board
399 board_config_flush
400
401 exit 0