base-files: uci-defaults-new: remove reset/enable args of ucidef_add_switch()
[openwrt/staging/dedeckeh.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:wan $wanports"
23 else
24 lanports="$port:lan $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_ports "rt305x" $lanports $wanports "6@eth0"
30 }
31
32 ramips_setup_interfaces()
33 {
34 local board="$1"
35
36 ucidef_set_interface_loopback
37
38 case $board in
39 3g150b|\
40 3g300m|\
41 all0256n|\
42 all5002|\
43 all5003|\
44 broadway|\
45 dcs-930|\
46 dcs-930l-b1|\
47 ht-tm02|\
48 linkits7688 | \
49 linkits7688d | \
50 microwrt|\
51 ncs601w|\
52 w150m|\
53 wnce2001|\
54 zte-q7)
55 ucidef_add_switch "switch0"
56 ucidef_add_switch_attr "switch0" "reset" "false"
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_ports "switch0" \
93 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
94 ;;
95 a5-v11)
96 ucidef_set_interface_lan "eth0.1"
97 ucidef_add_switch "switch0" "1" "1"
98 ucidef_add_switch_ports "switch0" \
99 "0:lan" "6t@eth0"
100 ;;
101 ar670w|\
102 ar725w|\
103 rt-n15|\
104 wl-351)
105 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
106 ucidef_add_switch "switch0" "1" "1"
107 ucidef_add_switch_ports "switch0" \
108 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
109 ;;
110 asl26555|\
111 re6500|\
112 rp-n53)
113 ucidef_set_interface_lan "eth0.1"
114 ucidef_add_switch "switch0" "1" "1"
115 ucidef_add_switch_ports "switch0" \
116 "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
117 ;;
118 atp-52b|\
119 awm002-evb|\
120 awm003-evb|\
121 dir-645|\
122 dir-860l-b1|\
123 f5d8235-v1|\
124 f5d8235-v2|\
125 hg255d|\
126 rt-n14u|\
127 ur-326n4g|\
128 wrtnode|\
129 wt3020|\
130 zbt-wa05)
131 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
132 ucidef_add_switch "switch0" "1" "1"
133 ucidef_add_switch_ports "switch0" \
134 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
135 ;;
136 awapn2403)
137 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
138 ucidef_add_switch "switch0" "1" "1"
139 ucidef_add_switch_ports "switch0" \
140 "0:lan" "1:wan" "6@eth0"
141 ;;
142 b2c|\
143 nw718|\
144 psr-680w|\
145 sl-r7205|\
146 ur-336un|\
147 w502u|\
148 wr6202)
149 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
150 ;;
151 br-6475nd)
152 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
153 ucidef_add_switch "switch0" "1" "1"
154 ucidef_add_switch_ports "switch0" \
155 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
156 ;;
157 cf-wr800n)
158 ucidef_set_interface_lan "eth0.1"
159 ucidef_add_switch "switch0" "1" "1"
160 ucidef_add_switch_ports "switch0" \
161 "4:lan" "6t@eth0"
162 ;;
163 cy-swr1100)
164 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
165 ucidef_add_switch "switch0" "1" "1"
166 ucidef_add_switch_ports "switch0" \
167 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
168 ;;
169 d105|\
170 hpm|\
171 na930|\
172 wli-tx4-ag300n)
173 ucidef_set_interface_lan "eth0"
174 ;;
175 e1700|\
176 mt7620a_mt7530)
177 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
178 ucidef_add_switch "switch1" "1" "1"
179 ucidef_add_switch_ports "switch1" \
180 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
181 ;;
182 hc5*61|\
183 y1s)
184 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
185 ucidef_add_switch "switch0" "1" "1"
186 ucidef_add_switch_ports "switch0" \
187 "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
188 ;;
189 m2m)
190 ucidef_add_switch "switch0"
191 ucidef_add_switch_attr "switch0" "reset" "false"
192 ucidef_set_interface_lan "eth0"
193 ;;
194 mlwg2|\
195 wizard8800|\
196 wl-330n|\
197 wmr-300)
198 ucidef_set_interface_lan "eth0.1"
199 ;;
200 mzk-dp150n|\
201 vocore)
202 ucidef_set_interface_lan "eth0.1"
203 ucidef_add_switch "switch0" "1" "1"
204 ucidef_add_switch_ports "switch0" \
205 "0:lan" "4:lan" "6t@eth0"
206 ;;
207 rt-n56u)
208 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
209 ucidef_add_switch "switch0" "1" "1"
210 ucidef_add_switch_ports "switch0" \
211 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
212 ;;
213 tew-691gr|\
214 tew-692gr)
215 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
216 ucidef_add_switch "switch0" "1" "1"
217 ucidef_add_switch_ports "switch0" \
218 "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
219 ;;
220 v11st-fe|\
221 wzr-agl300nh)
222 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
223 ucidef_add_switch "switch0" "1" "1"
224 ucidef_add_switch_ports "switch0" \
225 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
226 ;;
227 wcr-150gn)
228 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
229 ucidef_add_switch "switch0" "1" "1"
230 ucidef_add_switch_ports "switch0" \
231 "0:lan" "6t@eth0"
232 ;;
233 whr-1166d)
234 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
235 ucidef_add_switch "switch0" "1" "1"
236 ucidef_add_switch_ports "switch0" \
237 "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
238 ;;
239 wizfi630a)
240 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
241 ucidef_add_switch "switch0" "1" "1"
242 ucidef_add_switch_ports "switch0" \
243 "1:lan" "2:lan" "0:wan" "6@eth0"
244 ;;
245 zbt-wr8305rt)
246 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
247 ucidef_add_switch "switch0" "1" "1"
248 ucidef_add_switch_ports "switch0" \
249 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
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 a5-v11|\
270 bc2|\
271 broadway|\
272 d105|\
273 dir-300-b7|\
274 dir-320-b1|\
275 dir-620-a1|\
276 esr-9753|\
277 freestation5|\
278 hlk-rm04|\
279 mpr-a1|\
280 mpr-a2|\
281 psr-680w|\
282 sl-r7205|\
283 y1|\
284 y1s)
285 lan_mac=$(cat /sys/class/net/eth0/address)
286 lan_mac=$(macaddr_setbit_la "$lan_mac")
287 wan_mac=$(macaddr_add "$lan_mac" 1)
288 ;;
289 all0239-3g|\
290 carambola|\
291 freestation5|\
292 w502u|\
293 wnce2001)
294 wan_mac=$(mtd_get_mac_binary factory 46)
295 ;;
296 br-6475nd)
297 lan_mac=$(cat /sys/class/net/eth0/address)
298 wan_mac=$(mtd_get_mac_binary devdata 7)
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 e1700)
306 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
307 ;;
308 hc5*61)
309 lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
310 [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
311 wan_mac=$(macaddr_add "$lan_mac" 1)
312 ;;
313 ht-tm02)
314 lan_mac=$(cat /sys/class/net/eth0/address)
315 ;;
316 linkits7688 | \
317 linkits7688d)
318 wan_mac=$(mtd_get_mac_binary factory 4)
319 lan_mac=$(mtd_get_mac_binary factory 46)
320 ;;
321 m3|\
322 m4|\
323 x5|\
324 x8)
325 lan_mac=$(cat /sys/class/net/eth0/address)
326 lan_mac=$(macaddr_add "$lan_mac" -2)
327 ;;
328 oy-0001)
329 lan_mac=$(mtd_get_mac_binary factory 40)
330 wan_mac=$(mtd_get_mac_binary factory 46)
331 ;;
332 rt-n56u)
333 lan_mac=$(cat /sys/class/net/eth0/address)
334 lan_mac=$(macaddr_setbit_la "$lan_mac")
335 wan_mac=$(mtd_get_mac_binary factory 32772)
336 ;;
337 tew-691gr)
338 lan_mac=$(cat /sys/class/net/eth0/address)
339 wan_mac=$(macaddr_add "$lan_mac" 3)
340 ;;
341 tew-692gr)
342 lan_mac=$(cat /sys/class/net/eth0/address)
343 wan_mac=$(macaddr_add "$lan_mac" 4)
344 ;;
345 tiny-ac)
346 lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
347 wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
348 ;;
349 w306r-v20)
350 lan_mac=$(cat /sys/class/net/eth0/address)
351 wan_mac=$(macaddr_add "$lan_mac" 5)
352 ;;
353 wcr-150gn)
354 wan_mac=$(mtd_get_mac_binary factory 40)
355 ;;
356 whr-1166d|\
357 whr-300hp2|\
358 whr-600d|\
359 wsr-600)
360 wan_mac=$(mtd_get_mac_binary factory 4)
361 lan_mac=$wan_mac
362 ;;
363 wizfi630a)
364 lan_mac=$(mtd_get_mac_binary factory 4)
365 wan_mac=$(mtd_get_mac_binary factory 40)
366 ;;
367 wsr-1166)
368 local index="$(find_mtd_index "board_data")"
369 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
370 lan_mac=$wan_mac
371 ;;
372 *)
373 lan_mac=$(cat /sys/class/net/eth0/address)
374 wan_mac=$(macaddr_add "$lan_mac" 1)
375 ;;
376 esac
377
378 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
379 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
380 }
381
382 board_config_update
383 board=$(ramips_board_name)
384 ramips_setup_interfaces $board
385 ramips_setup_macs $board
386 board_config_flush
387
388 exit 0