ramips: explicitly disable built-in switch when needed
[openwrt/staging/stintel.git] / target / linux / ramips / rt305x / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/functions/uci-defaults.sh
5 . /lib/functions/system.sh
6
7 ramips_setup_rt3x5x_vlans()
8 {
9 if [ ! -x /sbin/swconfig ]; then
10 # legacy default
11 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
12 return
13 fi
14 local wanports=""
15 local lanports=""
16 for port in 5 4 3 2 1 0; do
17 if [ "$(swconfig dev rt305x port $port get disable)" = "1" ]; then
18 continue
19 fi
20 if [ "$(swconfig dev rt305x port $port get lan)" = "0" ]; then
21 wanports="$port:wan $wanports"
22 else
23 lanports="$port:lan $lanports"
24 fi
25 done
26 ucidef_add_switch "rt305x" $lanports $wanports "6t@eth0"
27 }
28
29 ramips_setup_interfaces()
30 {
31 local board="$1"
32
33 case $board in
34 accton,wr6202|\
35 alfa-network,w502u|\
36 netcore,nw718|\
37 petatel,psr-680w|\
38 skyline,sl-r7205|\
39 upvel,ur-336un)
40 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
41 ;;
42 allnet,all0256n-4m|\
43 allnet,all0256n-8m|\
44 allnet,all5002|\
45 allnet,all5003|\
46 dlink,dcs-930l-b1|\
47 dlink,dcs-930|\
48 hame,mpr-a2|\
49 hauppauge,broadway|\
50 hootoo,ht-tm02|\
51 intenso,memory2move|\
52 netgear,wnce2001|\
53 tenda,3g150b|\
54 tenda,3g300m|\
55 tenda,w150m|\
56 unbranded,a5-v11|\
57 wansview,ncs601w|\
58 zorlik,zl5900v2)
59 ucidef_add_switch "switch0"
60 ucidef_add_switch_attr "switch0" "enable" "false"
61 ucidef_set_interface_lan "eth0"
62 ;;
63 alphanetworks,asl26555-8m|\
64 alphanetworks,asl26555-16m)
65 ucidef_add_switch "switch0" \
66 "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
67 ;;
68 argus,atp-52b|\
69 asiarf,awm002-evb-4m|\
70 asiarf,awm002-evb-8m|\
71 jcg,jhr-n805r|\
72 jcg,jhr-n825r|\
73 jcg,jhr-n926r|\
74 planex,mzk-wdpr|\
75 upvel,ur-326n4g)
76 ucidef_add_switch "switch0" \
77 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
78 ;;
79 asiarf,awapn2403)
80 ucidef_add_switch "switch0" \
81 "0:lan" "1:wan" "6@eth0"
82 ;;
83 asus,wl-330n|\
84 easyacc,wizard-8800)
85 ucidef_set_interface_lan "eth0.1"
86 ;;
87 aximcom,mr-102n)
88 ucidef_set_interface_lan "eth0.2"
89 ;;
90 belkin,f5d8235-v2|\
91 trendnet,tew-714tru)
92 ucidef_add_switch "switch0" \
93 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
94 ;;
95 buffalo,whr-g300n|\
96 dlink,dir-300-b7|\
97 dlink,dir-320-b1|\
98 dlink,dir-610-a1|\
99 edimax,3g-6200n|\
100 hilink,hlk-rm04|\
101 nixcore,x1-16m|\
102 nixcore,x1-8m|\
103 planex,mzk-w300nh2|\
104 zyxel,keenetic)
105 ucidef_add_switch "switch0" \
106 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
107 ;;
108 dlink,dir-615-h1)
109 ucidef_add_switch "switch0" \
110 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
111 ;;
112 huawei,d105)
113 ucidef_add_switch "switch0"
114 ucidef_add_switch_attr "switch0" "enable" "false"
115 ucidef_set_interface_lan "eth0"
116 ;;
117 huawei,hg255d)
118 ucidef_add_switch "switch0" \
119 "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
120 ;;
121 nexx,wt1520-4m|\
122 nexx,wt1520-8m)
123 ucidef_add_switch "switch0" \
124 "0:lan" "4:wan" "6@eth0"
125 ;;
126 planex,mzk-dp150n|\
127 vocore,vocore-8m|\
128 vocore,vocore-16m)
129 ucidef_add_switch "switch0" \
130 "0:lan" "4:lan" "6t@eth0"
131 ;;
132 sitecom,wl-351)
133 ucidef_add_switch "switch0" \
134 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
135 ;;
136 sparklan,wcr-150gn)
137 ucidef_add_switch "switch0" \
138 "0:lan" "6t@eth0"
139 ;;
140 trendnet,tew-638apb-v2)
141 ucidef_add_switch "switch0" \
142 "4:lan" "6@eth0"
143 ;;
144 wiznet,wizfi630a)
145 ucidef_add_switch "switch0" \
146 "0:lan" "1:lan" "2:wan" "6@eth0"
147 ;;
148 zyxel,keenetic-start)
149 ucidef_add_switch "switch0" \
150 "0:lan:3" "1:lan:2" "2:lan:1" "3:lan:0" "4:wan" "6@eth0"
151 ;;
152 *)
153 RT3X5X=$(grep -E "(RT3.5|RT5350)" /proc/cpuinfo)
154 if [ -n "${RT3X5X}" ]; then
155 ramips_setup_rt3x5x_vlans
156 else
157 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
158 fi
159 ;;
160 esac
161 }
162
163 ramips_setup_macs()
164 {
165 local board="$1"
166 local lan_mac=""
167 local wan_mac=""
168 local label_mac=""
169
170 case $board in
171 7links,px-4885-4m|\
172 7links,px-4885-8m)
173 wan_mac=$(macaddr_add "$(mtd_get_mac_binary devconf 0x28)" 1)
174 ;;
175 8devices,carambola|\
176 alfa-network,w502u|\
177 arcwireless,freestation5|\
178 netgear,wnce2001)
179 wan_mac=$(mtd_get_mac_binary factory 0x2e)
180 ;;
181 accton,wr6202|\
182 asiarf,awm002-evb-4m|\
183 asiarf,awm002-evb-8m|\
184 asus,rt-n13u|\
185 aztech,hw550-3g|\
186 fon,fonera-20n|\
187 huawei,hg255d|\
188 omnima,miniembwifi|\
189 planex,mzk-wdpr|\
190 poray,ip2202|\
191 teltonika,rut5xx|\
192 unbranded,xdx-rn502j|\
193 zyxel,keenetic|\
194 zyxel,nbg-419n|\
195 zyxel,nbg-419n-v2)
196 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x28)" 1)
197 ;;
198 airlive,air3gii|\
199 argus,atp-52b|\
200 asus,wl-330n3g|\
201 dlink,dir-620-d1|\
202 edimax,3g-6200n|\
203 edimax,3g-6200nl|\
204 netcore,nw718|\
205 nexx,wt1520-4m|\
206 nexx,wt1520-8m|\
207 nixcore,x1-16m|\
208 nixcore,x1-8m|\
209 olimex,rt5350f-olinuxino|\
210 olimex,rt5350f-olinuxino-evb|\
211 omnima,miniembplug|\
212 planex,mzk-w300nh2|\
213 sitecom,wl-351|\
214 trendnet,tew-714tru)
215 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x4)" 1)
216 ;;
217 asus,rt-g32-b1|\
218 asus,rt-n10-plus)
219 wan_mac=$(macaddr_add "$(mtd_get_mac_binary devconf 0x4)" 1)
220 ;;
221 belkin,f5d8235-v2)
222 wan_mac=$(macaddr_add "$(mtd_get_mac_binary uboot 0x40004)" 1)
223 ;;
224 dlink,dir-300-b7|\
225 dlink,dir-320-b1|\
226 dlink,dir-620-a1|\
227 engenius,esr-9753|\
228 hame,mpr-a1|\
229 hauppauge,broadway|\
230 huawei,d105|\
231 hilink,hlk-rm04|\
232 nexaira,bc2|\
233 petatel,psr-680w|\
234 skyline,sl-r7205)
235 lan_mac=$(macaddr_setbit_la "$(cat /sys/class/net/eth0/address)")
236 wan_mac=$(macaddr_add "$lan_mac" 1)
237 ;;
238 dlink,dap-1350)
239 wan_mac=$(macaddr_add "$(mtd_get_mac_binary devdata 0x2e)" 1)
240 ;;
241 dlink,dir-300-b1|\
242 dlink,dir-600-b1|\
243 dlink,dir-610-a1)
244 wan_mac=$(macaddr_add "$(mtd_get_mac_binary devdata 0x4004)" 1)
245 ;;
246 dlink,dir-615-d)
247 label_mac=$(mtd_get_mac_binary devdata 0x4004)
248 ;;
249 dlink,dir-615-h1)
250 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x28)" 1)
251 label_mac=$(mtd_get_mac_binary factory 0x4)
252 ;;
253 dlink,dwr-512-b)
254 wan_mac=$(macaddr_add "$(mtd_get_mac_binary config 0xe07e)" 1)
255 ;;
256 jcg,jhr-n805r|\
257 jcg,jhr-n825r|\
258 jcg,jhr-n926r)
259 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x2e)" 1)
260 ;;
261 poray,m3|\
262 poray,m4-4m|\
263 poray,m4-8m|\
264 poray,x5|\
265 poray,x8)
266 lan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x4)" -2)
267 ;;
268 sparklan,wcr-150gn|\
269 wiznet,wizfi630a)
270 wan_mac=$(mtd_get_mac_binary factory 0x28)
271 ;;
272 tenda,w306r-v2)
273 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x28)" 5)
274 ;;
275 upvel,ur-326n4g|\
276 upvel,ur-336un)
277 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x4004)" 1)
278 ;;
279 esac
280
281 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
282 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
283 [ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
284 }
285
286 board_config_update
287 board=$(board_name)
288 ramips_setup_interfaces $board
289 ramips_setup_macs $board
290 board_config_flush
291
292 exit 0