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