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