ramips: fix Linksys RE6500 switch port mapping
[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_add_switch "rt305x" $lanports $wanports "6t@eth0"
28 }
29
30 ramips_setup_interfaces()
31 {
32 local board="$1"
33
34 case $board in
35 11acnas|\
36 w2914nsv2)
37 ucidef_add_switch "switch0" \
38 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
39 ;;
40 3g150b|\
41 3g300m|\
42 a5-v11|\
43 all0256n|\
44 all5002|\
45 all5003|\
46 broadway|\
47 dcs-930|\
48 dcs-930l-b1|\
49 ht-tm02|\
50 linkits7688 | \
51 linkits7688d | \
52 m2m|\
53 microwrt|\
54 mpr-a2|\
55 ncs601w|\
56 omega2 | \
57 omega2p | \
58 timecloud|\
59 w150m|\
60 widora-neo|\
61 wnce2001|\
62 zbt-cpe102|\
63 zte-q7)
64 ucidef_add_switch "switch0"
65 ucidef_add_switch_attr "switch0" "enable" "false"
66 ucidef_set_interface_lan "eth0"
67 ;;
68 mlw221|\
69 mr-102n)
70 ucidef_set_interface_lan "eth0.2"
71 ;;
72 3g-6200n|\
73 ac1200pro|\
74 ai-br100|\
75 db-wrt01|\
76 dir-300-b7|\
77 dir-320-b1|\
78 dir-610-a1|\
79 dir-615-h1|\
80 firewrt|\
81 hlk-rm04|\
82 mac1200rv2|\
83 miwifi-mini|\
84 miwifi-nano|\
85 mt7621|\
86 mt7628|\
87 mzk-750dhp|\
88 mzk-w300nh2|\
89 nixcore|\
90 oy-0001|\
91 pbr-m1|\
92 psg1208|\
93 psg1218|\
94 sap-g3200u3|\
95 sk-wb8|\
96 vr500|\
97 wf-2881|\
98 witi|\
99 wl-wn575a3|\
100 wndr3700v5|\
101 wt1520|\
102 y1|\
103 youku-yk1|\
104 zbt-ape522ii|\
105 zbt-we826|\
106 zbt-wg2626|\
107 zbt-wg3526|\
108 zbt-wr8305rt)
109 ucidef_add_switch "switch0" \
110 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
111 ;;
112 whr-300hp2|\
113 whr-600d|\
114 wsr-1166|\
115 wsr-600)
116 ucidef_add_switch "switch0" \
117 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
118 ;;
119 ar670w|\
120 ar725w|\
121 rt-n15|\
122 wl-351)
123 ucidef_add_switch "switch0" \
124 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
125 ;;
126 asl26555|\
127 rp-n53)
128 ucidef_add_switch "switch0" \
129 "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
130 ;;
131 atp-52b|\
132 awm002-evb|\
133 awm003-evb|\
134 c20i|\
135 c50|\
136 dir-645|\
137 dir-860l-b1|\
138 f5d8235-v2|\
139 gl-mt300a|\
140 gl-mt300n|\
141 gl-mt750|\
142 hg255d|\
143 jhr-n805r|\
144 jhr-n825r|\
145 jhr-n926r|\
146 mzk-wdpr|\
147 rb750gr3|\
148 rt-n14u|\
149 ubnt-erx|\
150 ur-326n4g|\
151 wrtnode|\
152 wrtnode2p | \
153 wrtnode2r | \
154 wt3020|\
155 zbt-wa05)
156 ucidef_add_switch "switch0" \
157 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
158 ;;
159 awapn2403)
160 ucidef_add_switch "switch0" \
161 "0:lan" "1:wan" "6@eth0"
162 ;;
163 b2c|\
164 nw718|\
165 psr-680w|\
166 sl-r7205|\
167 ur-336un|\
168 w502u|\
169 wr6202)
170 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
171 ;;
172 br-6475nd)
173 ucidef_add_switch "switch0" \
174 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
175 ;;
176 cf-wr800n|\
177 ex2700)
178 ucidef_add_switch "switch0" \
179 "4:lan" "6t@eth0"
180 ;;
181 cy-swr1100)
182 ucidef_add_switch "switch0" \
183 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
184 ;;
185 cs-qr10|\
186 d105|\
187 dch-m225|\
188 hpm|\
189 mzk-ex300np|\
190 mzk-ex750np|\
191 na930|\
192 pbr-d1|\
193 wli-tx4-ag300n|\
194 wmr-300|\
195 wrh-300cr)
196 ucidef_set_interface_lan "eth0"
197 ;;
198 duzun-dm06)
199 ucidef_add_switch "switch0" \
200 "1:lan" "0:wan" "6@eth0"
201 ;;
202 e1700|\
203 mt7620a_mt7530)
204 ucidef_add_switch "switch1" \
205 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
206 ;;
207 hc5*61|\
208 y1s)
209 ucidef_add_switch "switch0" \
210 "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
211 ;;
212 kn_rc|\
213 kn_rf)
214 ucidef_add_switch "switch" \
215 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
216 ;;
217 kng_rc)
218 ucidef_add_switch "switch1" \
219 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
220 ;;
221 mlwg2|\
222 wizard8800|\
223 wl-330n)
224 ucidef_set_interface_lan "eth0.1"
225 ;;
226 mr200)
227 ucidef_add_switch "switch0" \
228 "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
229 ucidef_set_interface_wan "usb0"
230 ;;
231 mzk-dp150n|\
232 vocore)
233 ucidef_add_switch "switch0" \
234 "0:lan" "4:lan" "6t@eth0"
235 ;;
236 newifi-d1)
237 ucidef_add_switch "switch0" \
238 "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
239 ;;
240 re6500)
241 ucidef_add_switch "switch0" \
242 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
243 ;;
244 rt-n56u)
245 ucidef_add_switch "switch0" \
246 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
247 ;;
248 tew-691gr|\
249 tew-692gr|\
250 wlr-6000)
251 ucidef_add_switch "switch0" \
252 "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
253 ;;
254 vocore2)
255 ucidef_add_switch "switch0" \
256 "0:lan" "2:lan" "6t@eth0"
257 ;;
258 f5d8235-v1|\
259 tew-714tru|\
260 v11st-fe|\
261 wzr-agl300nh)
262 ucidef_add_switch "switch0" \
263 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
264 ;;
265 wcr-150gn)
266 ucidef_add_switch "switch0" \
267 "0:lan" "6t@eth0"
268 ;;
269 whr-1166d)
270 ucidef_add_switch "switch0" \
271 "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
272 ;;
273 wizfi630a)
274 ucidef_add_switch "switch0" \
275 "1:lan" "2:lan" "0:wan" "6@eth0"
276 ;;
277 *)
278 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
279 if [ -n "${RT3X5X}" ]; then
280 ramips_setup_rt3x5x_vlans
281 else
282 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
283 fi
284 ;;
285 esac
286 }
287
288 ramips_setup_macs()
289 {
290 local board="$1"
291 local lan_mac=""
292 local wan_mac=""
293
294 case $board in
295 a5-v11|\
296 ht-tm02)
297 lan_mac=$(cat /sys/class/net/eth0/address)
298 ;;
299 all0239-3g|\
300 carambola|\
301 freestation5|\
302 w502u|\
303 wnce2001)
304 wan_mac=$(mtd_get_mac_binary factory 46)
305 ;;
306 bc2|\
307 broadway|\
308 d105|\
309 dir-300-b7|\
310 dir-320-b1|\
311 dir-620-a1|\
312 esr-9753|\
313 freestation5|\
314 hlk-rm04|\
315 mpr-a1|\
316 psr-680w|\
317 sl-r7205|\
318 y1|\
319 y1s)
320 lan_mac=$(cat /sys/class/net/eth0/address)
321 lan_mac=$(macaddr_setbit_la "$lan_mac")
322 wan_mac=$(macaddr_add "$lan_mac" 1)
323 ;;
324 br-6475nd)
325 lan_mac=$(cat /sys/class/net/eth0/address)
326 wan_mac=$(mtd_get_mac_binary devdata 7)
327 ;;
328 cy-swr1100|\
329 dch-m225)
330 lan_mac=$(mtd_get_mac_ascii factory lanmac)
331 ;;
332 dir-645)
333 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
334 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
335 ;;
336 dir-860l-b1)
337 lan_mac=$(mtd_get_mac_ascii factory lanmac)
338 wan_mac=$(mtd_get_mac_ascii factory wanmac)
339 ;;
340 e1700)
341 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
342 ;;
343 hc5*61)
344 lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
345 [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
346 wan_mac=$(macaddr_add "$lan_mac" 1)
347 ;;
348 kng_rc)
349 wan_mac=$(mtd_get_mac_binary factory 28)
350 ;;
351 linkits7688 | \
352 linkits7688d)
353 wan_mac=$(mtd_get_mac_binary factory 4)
354 lan_mac=$(mtd_get_mac_binary factory 46)
355 ;;
356 mac1200rv2)
357 lan_mac=$(mtd_get_mac_binary factory_info 13)
358 wan_mac=$(macaddr_add "$lan_mac" 1)
359 ;;
360 m3|\
361 m4|\
362 x5|\
363 x8)
364 lan_mac=$(cat /sys/class/net/eth0/address)
365 lan_mac=$(macaddr_add "$lan_mac" -2)
366 ;;
367 newifi-d1)
368 lan_mac=$(cat /sys/class/net/eth0/address)
369 lan_mac=$(macaddr_add "$lan_mac" 2)
370 ;;
371 omega2|\
372 omega2p)
373 wan_mac=$(mtd_get_mac_binary factory 4)
374 lan_mac=$(mtd_get_mac_binary factory 46)
375 ;;
376 oy-0001)
377 lan_mac=$(mtd_get_mac_binary factory 40)
378 wan_mac=$(mtd_get_mac_binary factory 46)
379 ;;
380 rt-n56u)
381 lan_mac=$(cat /sys/class/net/eth0/address)
382 lan_mac=$(macaddr_setbit_la "$lan_mac")
383 wan_mac=$(mtd_get_mac_binary factory 32772)
384 ;;
385 sk-wb8)
386 wan_mac=$(mtd_get_mac_binary factory 57350)
387 ;;
388 tew-691gr)
389 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
390 ;;
391 tew-692gr)
392 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
393 ;;
394 tiny-ac)
395 lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
396 wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
397 ;;
398 vr500)
399 lan_mac=$(mtd_get_mac_binary factory 57344)
400 wan_mac=$(mtd_get_mac_binary factory 57350)
401 ;;
402 w306r-v20)
403 lan_mac=$(cat /sys/class/net/eth0/address)
404 wan_mac=$(macaddr_add "$lan_mac" 5)
405 ;;
406 wcr-150gn)
407 wan_mac=$(mtd_get_mac_binary factory 40)
408 ;;
409 whr-1166d|\
410 whr-300hp2|\
411 whr-600d|\
412 wsr-600)
413 wan_mac=$(mtd_get_mac_binary factory 4)
414 lan_mac=$wan_mac
415 ;;
416 wizfi630a)
417 lan_mac=$(mtd_get_mac_binary factory 4)
418 wan_mac=$(mtd_get_mac_binary factory 40)
419 ;;
420 wlr-6000)
421 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
422 ;;
423 wsr-1166)
424 local index="$(find_mtd_index "board_data")"
425 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
426 lan_mac=$wan_mac
427 ;;
428 *)
429 lan_mac=$(cat /sys/class/net/eth0/address)
430 wan_mac=$(macaddr_add "$lan_mac" 1)
431 ;;
432 esac
433
434 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
435 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
436 }
437
438 board_config_update
439 board=$(ramips_board_name)
440 ramips_setup_interfaces $board
441 ramips_setup_macs $board
442 board_config_flush
443
444 exit 0