598074bb1937268156b731ff4d37fe8dade6b28f
[openwrt/staging/dedeckeh.git] / target / linux / ramips / base-files / etc / uci-defaults / 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 all0256n | \
46 all5002 | \
47 broadway)
48 ucidef_set_interface_lan "eth0"
49 ;;
50
51 dir-615-h1 | \
52 wl-330n)
53 ucidef_set_interface_lan "eth0.1"
54 ;;
55
56 3g-6200n | \
57 argus-atp52b | \
58 b2c | \
59 nw718 | \
60 psr-680w | \
61 sl-r7205 | \
62 w502u | \
63 wr6202)
64 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
65 ;;
66
67 dir-645)
68 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
69 ucidef_add_switch "switch0" "1" "1"
70 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
71 ucidef_add_switch_vlan "switch0" "2" "0 6t"
72 ;;
73
74 mzk-w300nh2)
75 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
76 ucidef_add_switch "switch0" "1" "1"
77 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
78 ucidef_add_switch_vlan "switch0" "2" "4 6t"
79 ;;
80
81 f5d8235-v1 | \
82 f5d8235-v2 | \
83 ur-336un)
84 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
85 ;;
86
87 v11st-fe)
88 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
89 ucidef_add_switch "switch0" "1" "1"
90 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
91 ucidef_add_switch_vlan "switch0" "2" "0 5t"
92 ;;
93
94 rt-n15 | \
95 wl-351)
96 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
97 ucidef_add_switch "switch0" "1" "1"
98 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
99 ucidef_add_switch_vlan "switch0" "2" "4 5t"
100 ;;
101
102 rt-n56u)
103 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
104 ucidef_add_switch "switch0" "1" "1"
105 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
106 ucidef_add_switch_vlan "switch0" "2" "4 8t"
107 ;;
108
109 tew-691gr|\
110 tew-692gr)
111 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
112 ucidef_add_switch "switch0" "1" "1"
113 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
114 ucidef_add_switch_vlan "switch0" "2" "0t 5"
115 ;;
116
117 freestation5 | \
118 wcr-150gn)
119 ucidef_set_interfaces_lan_wan "eth0.2" "eth0.1"
120 ;;
121
122 wli-tx4-ag300n)
123 ucidef_set_interface_lan "eth0"
124 ;;
125
126 *)
127 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
128 if [ -n "${RT3X5X}" ]; then
129 ramips_setup_rt3x5x_vlans
130 else
131 ucidef_set_interfaces_lan_wan "eth0" "eth1"
132 fi
133 ;;
134 esac
135 }
136
137 ramips_setup_macs()
138 {
139 local board="$1"
140 local lan_mac=""
141 local wan_mac=""
142
143 case $board in
144 all0256n | \
145 all5002 | \
146 dir-615-h1)
147 lan_mac=$(ramips_get_mac_binary factory 40)
148 ;;
149 3g-6200n | \
150 air3gii | \
151 argus-atp52b | \
152 bc2 | \
153 broadway | \
154 f5d8235-v1 | \
155 mzk-w300nh2 | \
156 nw718 | \
157 psr-680w | \
158 rt-n15 | \
159 sl-r7205 | \
160 wl-351)
161 lan_mac=$(ramips_get_mac_binary factory 4)
162 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
163 ;;
164
165 w306r-v20)
166 lan_mac=$(ramips_get_mac_binary factory 4)
167 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 5)
168 ;;
169
170 rt-n13u | \
171 fonera20n)
172 lan_mac=$(ramips_get_mac_binary factory 40)
173 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
174 ;;
175
176 dir-300-b1 |\
177 dir-300-b2 |\
178 dir-600-b1)
179 lan_mac=$(ramips_get_mac_binary devdata 16388)
180 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
181 ;;
182
183 dir-620-a1)
184 lan_mac=$(ramips_get_mac_binary factory 4)
185 lan_mac=$(maccalc or "$lan_mac" "02:00:00:00:00:00")
186 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
187 ;;
188
189 dir-645)
190 lan_mac=$(ramips_get_mac_nvram nvram lanmac)
191 wan_mac=$(ramips_get_mac_nvram nvram wanmac)
192 ;;
193
194 esr-9753 | \
195 ur-336un)
196 lan_mac=$(ramips_get_mac_binary devdata 16388)
197 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
198 ;;
199
200 nbg-419n | \
201 wcr-150gn)
202 lan_mac=$(ramips_get_mac_binary factory 4)
203 wan_mac=$(ramips_get_mac_binary factory 40)
204 ;;
205
206 f5d8235-v2)
207 lan_mac=$(ramips_get_mac_binary "u-boot" 262148)
208 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
209 ;;
210
211 rt-n56u)
212 lan_mac=$(ramips_get_mac_binary factory 4)
213 wan_mac=$(ramips_get_mac_binary factory 32772)
214 ;;
215
216 tew-691gr)
217 lan_mac=$(ramips_get_mac_binary factory 40)
218 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 3)
219 ;;
220
221 tew-692gr)
222 lan_mac=$(ramips_get_mac_binary factory 40)
223 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 4)
224 ;;
225
226 all0239-3g | \
227 carambola | \
228 w502u)
229 lan_mac=$(ramips_get_mac_binary factory 40)
230 wan_mac=$(ramips_get_mac_binary factory 46)
231 ;;
232
233 wl341v3)
234 lan_mac=$(ramips_get_mac_binary board-nvram 65440)
235 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
236 ;;
237
238 wli-tx4-ag300n)
239 lan_mac=$(ramips_get_mac_binary factory 4)
240 ;;
241
242 esac
243
244 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
245 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
246 }
247
248 [ -e /etc/config/network ] && exit 0
249
250 touch /etc/config/network
251
252 board=$(ramips_board_name)
253
254 ramips_setup_interfaces $board
255 ramips_setup_macs $board
256
257 uci commit network
258
259 exit 0