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