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