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