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