ramips: add support for Kingston MLW221
[openwrt/openwrt.git] / target / linux / ramips / base-files / etc / uci-defaults / 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 $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 3g300m | \
41 w150m | \
42 all0256n | \
43 all5002 | \
44 all5003 | \
45 broadway | \
46 dcs-930| \
47 ncs601w | \
48 wnce2001)
49 ucidef_add_switch "switch0" "1" "0"
50 ucidef_set_interface_lan "eth0"
51 ;;
52
53 3g-6200nl | \
54 mlw221)
55 ucidef_set_interface_lan "eth0.2"
56 ;;
57
58 wl-330n | \
59 wmr300)
60 ucidef_set_interface_lan "eth0.1"
61 ;;
62
63 3g-6200n | \
64 b2c | \
65 nw718 | \
66 psr-680w | \
67 sl-r7205 | \
68 w502u | \
69 wr6202)
70 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
71 ;;
72
73 awapn2403)
74 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
75 ucidef_add_switch "switch0" "1" "1"
76 ucidef_add_switch_vlan "switch0" "1" "0 6t"
77 ucidef_add_switch_vlan "switch0" "2" "1 6t"
78 ;;
79
80 br-6475nd)
81 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
82 ucidef_add_switch "switch0" "1" "1"
83 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
84 ucidef_add_switch_vlan "switch0" "2" "0 9t"
85 ;;
86
87 asl26555)
88 ucidef_set_interface_lan "eth0.1"
89 ucidef_add_switch "switch0" "1" "1"
90 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
91 ;;
92
93 cy-swr1100)
94 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
95 ucidef_add_switch "switch0" "1" "1"
96 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t"
97 ucidef_add_switch_vlan "switch0" "2" "4 9t"
98 ;;
99
100 dir-610-a1 | \
101 dir-300-b7 | \
102 dir-320-b1 | \
103 dir-615-h1 | \
104 hlk-rm04 | \
105 mzk-w300nh2 | \
106 mzk-750dhp)
107 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
108 ucidef_add_switch "switch0" "1" "1"
109 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
110 ucidef_add_switch_vlan "switch0" "2" "4 6t"
111 ;;
112
113 awm002-evb | \
114 awm003-evb | \
115 argus-atp52b | \
116 dir-645 | \
117 f5d8235-v1 | \
118 f5d8235-v2 | \
119 hg255d | \
120 rt-n14u | \
121 wrtnode | \
122 ur-326n4g | \
123 zbt-wa05)
124 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
125 ucidef_add_switch "switch0" "1" "1"
126 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
127 ucidef_add_switch_vlan "switch0" "2" "0 6t"
128 ;;
129
130 ur-336un)
131 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
132 ;;
133
134 br6524n | \
135 v11st-fe)
136 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
137 ucidef_add_switch "switch0" "1" "1"
138 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
139 ucidef_add_switch_vlan "switch0" "2" "0 5t"
140 ;;
141
142 ar725w | \
143 rt-n15 | \
144 wl-351)
145 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
146 ucidef_add_switch "switch0" "1" "1"
147 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
148 ucidef_add_switch_vlan "switch0" "2" "4 5t"
149 ;;
150
151 rt-n56u)
152 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
153 ucidef_add_switch "switch0" "1" "1"
154 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
155 ucidef_add_switch_vlan "switch0" "2" "4 8t"
156 ;;
157
158 tew-691gr|\
159 tew-692gr)
160 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
161 ucidef_add_switch "switch0" "1" "1"
162 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
163 ucidef_add_switch_vlan "switch0" "2" "0t 5"
164 ;;
165
166 wcr-150gn)
167 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
168 ucidef_add_switch "switch0" "1" "1"
169 ucidef_add_switch_vlan "switch0" "1" "0 6t"
170 ucidef_add_switch_vlan "switch0" "2" "6t"
171 ;;
172
173 wr8305rt)
174 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
175 ucidef_add_switch "switch0" "1" "1"
176 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
177 ucidef_add_switch_vlan "switch0" "2" "4 6t"
178 ;;
179
180 d105 | \
181 na930 | \
182 omni-emb-hpm|\
183 wli-tx4-ag300n)
184 ucidef_set_interface_lan "eth0"
185 ;;
186
187 *)
188 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
189 if [ -n "${RT3X5X}" ]; then
190 ramips_setup_rt3x5x_vlans
191 else
192 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
193 fi
194 ;;
195 esac
196 }
197
198 ramips_setup_macs()
199 {
200 local board="$1"
201 local lan_mac=""
202 local wan_mac=""
203
204 case $board in
205 br-6475nd)
206 lan_mac=$(cat /sys/class/net/eth0/address)
207 wan_mac=$(mtd_get_mac_binary devdata 7)
208 ;;
209
210 w306r-v20)
211 lan_mac=$(cat /sys/class/net/eth0/address)
212 wan_mac=$(macaddr_add "$lan_mac" 5)
213 ;;
214
215 tew-691gr)
216 lan_mac=$(cat /sys/class/net/eth0/address)
217 wan_mac=$(macaddr_add "$lan_mac" 3)
218 ;;
219
220 tew-692gr)
221 lan_mac=$(cat /sys/class/net/eth0/address)
222 wan_mac=$(macaddr_add "$lan_mac" 4)
223 ;;
224
225 m3 |\
226 m4 |\
227 x5 |\
228 x8)
229 lan_mac=$(cat /sys/class/net/eth0/address)
230 lan_mac=$(macaddr_add "$lan_mac" -2)
231 ;;
232
233 bc2 |\
234 broadway |\
235 d105 |\
236 dir-620-a1 |\
237 esr-9753 |\
238 freestation5 |\
239 hlk-rm04 | \
240 mpr-a1 | \
241 mpr-a2 | \
242 dir-300-b7 | \
243 dir-320-b1 | \
244 psr-680w |\
245 sl-r7205)
246 lan_mac=$(cat /sys/class/net/eth0/address)
247 lan_mac=$(macaddr_setbit_la "$lan_mac")
248 wan_mac=$(macaddr_add "$lan_mac" 1)
249 ;;
250
251 cy-swr1100 | \
252 dir-645)
253 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
254 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
255 ;;
256
257 wcr-150gn)
258 wan_mac=$(mtd_get_mac_binary factory 40)
259 ;;
260
261 rt-n56u)
262 lan_mac=$(cat /sys/class/net/eth0/address)
263 lan_mac=$(macaddr_setbit_la "$lan_mac")
264 wan_mac=$(mtd_get_mac_binary factory 32772)
265 ;;
266
267 all0239-3g | \
268 carambola | \
269 freestation5 | \
270 w502u | \
271 wnce2001)
272 wan_mac=$(mtd_get_mac_binary factory 46)
273 ;;
274
275 *)
276 lan_mac=$(cat /sys/class/net/eth0/address)
277 wan_mac=$(macaddr_add "$lan_mac" 1)
278 ;;
279
280 esac
281
282 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
283 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
284 }
285
286 [ -e /etc/config/network ] && exit 0
287
288 touch /etc/config/network
289
290 board=$(ramips_board_name)
291
292 ramips_setup_interfaces $board
293 ramips_setup_macs $board
294
295 uci commit network
296
297 exit 0