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