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