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