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