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