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