ramips: reset switch on single-port devices
[openwrt/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 broadway | \
158 f5d8235-v1 | \
159 mzk-w300nh2 | \
160 nw718 | \
161 psr-680w | \
162 rt-n15 | \
163 sl-r7205 | \
164 wl-351)
165 lan_mac=$(ramips_get_mac_binary factory 4)
166 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
167 ;;
168
169 w306r-v20)
170 lan_mac=$(ramips_get_mac_binary factory 4)
171 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 5)
172 ;;
173
174 rt-n13u | \
175 fonera20n)
176 lan_mac=$(ramips_get_mac_binary factory 40)
177 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
178 ;;
179
180 dir-300-b1 |\
181 dir-300-b2 |\
182 dir-600-b1)
183 lan_mac=$(ramips_get_mac_binary devdata 16388)
184 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
185 ;;
186
187 dir-620-a1)
188 lan_mac=$(ramips_get_mac_binary factory 4)
189 lan_mac=$(maccalc or "$lan_mac" "02:00:00:00:00:00")
190 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
191 ;;
192
193 dir-645)
194 lan_mac=$(ramips_get_mac_nvram nvram lanmac)
195 wan_mac=$(ramips_get_mac_nvram nvram wanmac)
196 ;;
197
198 esr-9753 | \
199 ur-336un)
200 lan_mac=$(ramips_get_mac_binary devdata 16388)
201 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
202 ;;
203
204 nbg-419n | \
205 wcr-150gn)
206 lan_mac=$(ramips_get_mac_binary factory 4)
207 wan_mac=$(ramips_get_mac_binary factory 40)
208 ;;
209
210 f5d8235-v2)
211 lan_mac=$(ramips_get_mac_binary "u-boot" 262148)
212 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
213 ;;
214
215 rt-n56u)
216 lan_mac=$(ramips_get_mac_binary factory 4)
217 wan_mac=$(ramips_get_mac_binary factory 32772)
218 ;;
219
220 tew-691gr)
221 lan_mac=$(ramips_get_mac_binary factory 40)
222 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 3)
223 ;;
224
225 tew-692gr)
226 lan_mac=$(ramips_get_mac_binary factory 40)
227 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 4)
228 ;;
229
230 all0239-3g | \
231 carambola | \
232 w502u)
233 lan_mac=$(ramips_get_mac_binary factory 40)
234 wan_mac=$(ramips_get_mac_binary factory 46)
235 ;;
236
237 wl341v3)
238 lan_mac=$(ramips_get_mac_binary board-nvram 65440)
239 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
240 ;;
241
242 wli-tx4-ag300n)
243 lan_mac=$(ramips_get_mac_binary factory 4)
244 ;;
245
246 esac
247
248 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
249 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
250 }
251
252 [ -e /etc/config/network ] && exit 0
253
254 touch /etc/config/network
255
256 board=$(ramips_board_name)
257
258 ramips_setup_interfaces $board
259 ramips_setup_macs $board
260
261 uci commit network
262
263 exit 0