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