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