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