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