ramips: Add support for VoCore
[14.07/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         vocore)
167                 ucidef_set_interface_lan "eth0.1"
168                 ucidef_add_switch "switch0" "1" "1"
169                 ucidef_add_switch_vlan "switch0" "1" "0 4 6t"
170                 ;;
171
172         wcr-150gn)
173                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
174                 ucidef_add_switch "switch0" "1" "1"
175                 ucidef_add_switch_vlan "switch0" "1" "0 6t"
176                 ucidef_add_switch_vlan "switch0" "2" "6t"
177                 ;;
178
179         wr8305rt)
180                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
181                 ucidef_add_switch "switch0" "1" "1"
182                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
183                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
184                 ;;
185
186         y1 |\
187         y1s)
188                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
189                 ucidef_add_switch "switch0" "1" "1"
190                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5 6t"
191                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
192                 ;;
193         d105 | \
194         na930 | \
195         omni-emb-hpm|\
196         wli-tx4-ag300n)
197                 ucidef_set_interface_lan "eth0"
198                 ;;
199
200         *)
201                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
202                 if [ -n "${RT3X5X}" ]; then
203                         ramips_setup_rt3x5x_vlans
204                 else
205                         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
206                 fi
207                 ;;
208         esac
209 }
210
211 ramips_setup_macs()
212 {
213         local board="$1"
214         local lan_mac=""
215         local wan_mac=""
216
217         case $board in
218         br-6475nd)
219                 lan_mac=$(cat /sys/class/net/eth0/address)
220                 wan_mac=$(mtd_get_mac_binary devdata 7)
221                 ;;
222
223         w306r-v20)
224                 lan_mac=$(cat /sys/class/net/eth0/address)
225                 wan_mac=$(macaddr_add "$lan_mac" 5)
226                 ;;
227
228         tew-691gr)
229                 lan_mac=$(cat /sys/class/net/eth0/address)
230                 wan_mac=$(macaddr_add "$lan_mac" 3)
231                 ;;
232
233         tew-692gr)
234                 lan_mac=$(cat /sys/class/net/eth0/address)
235                 wan_mac=$(macaddr_add "$lan_mac" 4)
236                 ;;
237
238         m3 |\
239         m4 |\
240         x5 |\
241         x8)
242                 lan_mac=$(cat /sys/class/net/eth0/address)
243                 lan_mac=$(macaddr_add "$lan_mac" -2)
244                 ;;
245
246         bc2 |\
247         broadway |\
248         d105 |\
249         dir-620-a1 |\
250         esr-9753 |\
251         freestation5 |\
252         hlk-rm04 | \
253         mpr-a1 | \
254         mpr-a2 | \
255         dir-300-b7 | \
256         dir-320-b1 | \
257         psr-680w |\
258         sl-r7205 |\
259         y1 |\
260         y1s)
261                 lan_mac=$(cat /sys/class/net/eth0/address)
262                 lan_mac=$(macaddr_setbit_la "$lan_mac")
263                 wan_mac=$(macaddr_add "$lan_mac" 1)
264                 ;;
265
266         cy-swr1100 | \
267         dir-645)
268                 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
269                 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
270                 ;;
271
272         wcr-150gn)
273                 wan_mac=$(mtd_get_mac_binary factory 40)
274                 ;;
275
276         rt-n56u)
277                 lan_mac=$(cat /sys/class/net/eth0/address)
278                 lan_mac=$(macaddr_setbit_la "$lan_mac")
279                 wan_mac=$(mtd_get_mac_binary factory 32772)
280                 ;;
281
282         all0239-3g | \
283         carambola | \
284         freestation5 | \
285         w502u | \
286         wnce2001)
287                 wan_mac=$(mtd_get_mac_binary factory 46)
288                 ;;
289
290         *)
291                 lan_mac=$(cat /sys/class/net/eth0/address)
292                 wan_mac=$(macaddr_add "$lan_mac" 1)
293                 ;;
294
295         esac
296
297         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
298         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
299 }
300
301 [ -e /etc/config/network ] && exit 0
302
303 touch /etc/config/network
304
305 board=$(ramips_board_name)
306
307 ramips_setup_interfaces $board
308 ramips_setup_macs $board
309
310 uci commit network
311
312 exit 0