ramips: add userspace support for the Edimax BR-6425
[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 if [ ! -x /usr/sbin/maccalc ]; then
8         echo "$0: maccalc not found!"
9         return
10 fi
11
12 ramips_setup_rt3x5x_vlans()
13 {
14         if [ ! -x /sbin/swconfig ]; then
15                 # legacy default
16                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
17                 return
18         fi
19         local wanports=""
20         local lanports=""
21         swconfig dev rt305x set reset 1
22         for port in 5 4 3 2 1 0; do
23                 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
24                         continue
25                 fi
26                 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
27                         wanports="$port $wanports"
28                 else
29                         lanports="$port $lanports"
30                 fi
31         done
32         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
33         ucidef_add_switch "rt305x" "1" "1"
34         ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
35         ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
36 }
37
38 ramips_setup_interfaces()
39 {
40         local board="$1"
41
42         ucidef_set_interface_loopback
43
44         case $board in
45         3g300m | \
46         all0256n | \
47         all5002 | \
48         broadway)
49                 ucidef_add_switch "switch0" "1" "0"
50                 ucidef_set_interface_lan "eth0"
51                 ;;
52
53         dir-615-h1 | \
54         wl-330n)
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         dir-645)
70                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
71                 ucidef_add_switch "switch0" "1" "1"
72                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
73                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
74                 ;;
75
76         mzk-w300nh2)
77                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
78                 ucidef_add_switch "switch0" "1" "1"
79                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
80                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
81                 ;;
82
83         f5d8235-v1 | \
84         f5d8235-v2 | \
85         ur-336un)
86                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
87                 ;;
88
89         br6524n | \
90         v11st-fe)
91                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
92                 ucidef_add_switch "switch0" "1" "1"
93                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
94                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
95                 ;;
96
97         rt-n15 | \
98         wl-351)
99                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
100                 ucidef_add_switch "switch0" "1" "1"
101                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
102                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
103                 ;;
104
105         rt-n56u)
106                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
107                 ucidef_add_switch "switch0" "1" "1"
108                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
109                 ucidef_add_switch_vlan "switch0" "2" "4 8t"
110                 ;;
111
112         tew-691gr|\
113         tew-692gr)
114                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
115                 ucidef_add_switch "switch0" "1" "1"
116                 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
117                 ucidef_add_switch_vlan "switch0" "2" "0t 5"
118                 ;;
119
120         freestation5 | \
121         wcr-150gn)
122                 ucidef_set_interfaces_lan_wan "eth0.2" "eth0.1"
123                 ;;
124
125         wli-tx4-ag300n)
126                 ucidef_set_interface_lan "eth0"
127                 ;;
128
129         *)
130                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
131                 if [ -n "${RT3X5X}" ]; then
132                         ramips_setup_rt3x5x_vlans
133                 else
134                         ucidef_set_interfaces_lan_wan "eth0" "eth1"
135                 fi
136                 ;;
137         esac
138 }
139
140 ramips_setup_macs()
141 {
142         local board="$1"
143         local lan_mac=""
144         local wan_mac=""
145
146         case $board in
147         all0256n | \
148         all5002 | \
149         dir-615-h1)
150                 lan_mac=$(ramips_get_mac_binary factory 40)
151                 ;;
152         3g-6200n | \
153         3g300m | \
154         air3gii | \
155         argus-atp52b | \
156         bc2 | \
157         br6425 | \
158         broadway | \
159         f5d8235-v1 | \
160         mzk-w300nh2 | \
161         nw718 | \
162         psr-680w | \
163         rt-n15 | \
164         sl-r7205 | \
165         wl-351)
166                 lan_mac=$(ramips_get_mac_binary factory 4)
167                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
168                 ;;
169
170         w306r-v20)
171                 lan_mac=$(ramips_get_mac_binary factory 4)
172                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 5)
173                 ;;
174
175         rt-n13u | \
176         fonera20n)
177                 lan_mac=$(ramips_get_mac_binary factory 40)
178                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
179                 ;;
180
181         dir-300-b1 |\
182         dir-300-b2 |\
183         dir-600-b1)
184                 lan_mac=$(ramips_get_mac_binary devdata 16388)
185                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
186                 ;;
187
188         dir-620-a1)
189                 lan_mac=$(ramips_get_mac_binary factory 4)
190                 lan_mac=$(maccalc or "$lan_mac" "02:00:00:00:00:00")
191                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
192                 ;;
193
194         dir-645)
195                 lan_mac=$(ramips_get_mac_nvram nvram lanmac)
196                 wan_mac=$(ramips_get_mac_nvram nvram wanmac)
197                 ;;
198
199         esr-9753 | \
200         ur-336un)
201                 lan_mac=$(ramips_get_mac_binary devdata 16388)
202                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
203                 ;;
204
205         nbg-419n | \
206         wcr-150gn)
207                 lan_mac=$(ramips_get_mac_binary factory 4)
208                 wan_mac=$(ramips_get_mac_binary factory 40)
209                 ;;
210
211         f5d8235-v2)
212                 lan_mac=$(ramips_get_mac_binary "u-boot" 262148)
213                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
214                 ;;
215
216         rt-n56u)
217                 lan_mac=$(ramips_get_mac_binary factory 4)
218                 wan_mac=$(ramips_get_mac_binary factory 32772)
219                 ;;
220
221         tew-691gr)
222                 lan_mac=$(ramips_get_mac_binary factory 40)
223                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 3)
224                 ;;
225
226         tew-692gr)
227                 lan_mac=$(ramips_get_mac_binary factory 40)
228                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 4)
229                 ;;
230
231         all0239-3g | \
232         carambola | \
233         w502u)
234                 lan_mac=$(ramips_get_mac_binary factory 40)
235                 wan_mac=$(ramips_get_mac_binary factory 46)
236                 ;;
237
238         wl341v3)
239                 lan_mac=$(ramips_get_mac_binary board-nvram 65440)
240                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
241                 ;;
242
243         wli-tx4-ag300n)
244                 lan_mac=$(ramips_get_mac_binary factory 4)
245                 ;;
246
247         esac
248
249         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
250         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
251 }
252
253 [ -e /etc/config/network ] && exit 0
254
255 touch /etc/config/network
256
257 board=$(ramips_board_name)
258
259 ramips_setup_interfaces $board
260 ramips_setup_macs $board
261
262 uci commit network
263
264 exit 0