ramips: Fix initial network configuration for few boards
[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 awm002-evb | \
45 broadway | \
46 dcs-930| \
47 wnce2001)
48 ucidef_add_switch "switch0" "1" "0"
49 ucidef_set_interface_lan "eth0"
50 ;;
51
52 3g-6200nl | \
53 wl-330n | \
54 wmr300)
55 ucidef_set_interface_lan "eth0.1"
56 ;;
57
58 3g-6200n | \
59 b2c | \
60 nw718 | \
61 psr-680w | \
62 sl-r7205 | \
63 w502u | \
64 wr6202)
65 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
66 ;;
67
68 asl26555)
69 ucidef_set_interface_lan "eth0.1"
70 ucidef_add_switch "switch0" "1" "1"
71 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
72 ;;
73
74 dir-610-a1 | \
75 dir-300-b7 | \
76 dir-320-b1 | \
77 dir-615-h1 | \
78 mzk-w300nh2)
79 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
80 ucidef_add_switch "switch0" "1" "1"
81 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
82 ucidef_add_switch_vlan "switch0" "2" "4 6t"
83 ;;
84
85 argus-atp52b | \
86 dir-645 | \
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.1" "eth0.2"
134 ucidef_add_switch "switch0" "1" "1"
135 ucidef_add_switch_vlan "switch0" "1" "0 6t"
136 ucidef_add_switch_vlan "switch0" "2" "6t"
137 ;;
138
139 d105 | \
140 omni-emb-hpm|\
141 wli-tx4-ag300n)
142 ucidef_set_interface_lan "eth0"
143 ;;
144
145 *)
146 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
147 if [ -n "${RT3X5X}" ]; then
148 ramips_setup_rt3x5x_vlans
149 else
150 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
151 fi
152 ;;
153 esac
154 }
155
156 ramips_setup_macs()
157 {
158 local board="$1"
159 local lan_mac=""
160 local wan_mac=""
161
162 case $board in
163 *)
164 wan_mac=$(macaddr_add "$lan_mac" 1)
165 ;;
166
167 w306r-v20)
168 wan_mac=$(macaddr_add "$lan_mac" 5)
169 ;;
170
171 tew-691gr)
172 wan_mac=$(macaddr_add "$lan_mac" 3)
173 ;;
174
175 tew-692gr)
176 wan_mac=$(macaddr_add "$lan_mac" 4)
177 ;;
178
179 m3 |\
180 m4 |\
181 x5 |\
182 x8)
183 lan_mac=$(macaddr_add "$lan_mac" -1)
184 ;;
185
186 dir-620-a1)
187 lan_mac=$(macaddr_setbit_la "$lan_mac")
188 wan_mac=$(macaddr_add "$lan_mac" 1)
189 ;;
190
191 dir-645)
192 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
193 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
194 ;;
195
196 nbg-419n | \
197 wcr-150gn)
198 wan_mac=$(mtd_get_mac_binary factory 40)
199 ;;
200
201 rt-n56u)
202 wan_mac=$(mtd_get_mac_binary factory 32772)
203 ;;
204
205 all0239-3g | \
206 carambola | \
207 freestation5 | \
208 w502u | \
209 wnce2001)
210 wan_mac=$(mtd_get_mac_binary factory 46)
211 ;;
212
213 wl341v3)
214 lan_mac=$(mtd_get_mac_binary board-nvram 65440)
215 wan_mac=$(macaddr_add "$lan_mac" 1)
216 ;;
217
218 esac
219
220 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
221 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
222 }
223
224 [ -e /etc/config/network ] && exit 0
225
226 touch /etc/config/network
227
228 board=$(ramips_board_name)
229
230 ramips_setup_interfaces $board
231 ramips_setup_macs $board
232
233 uci commit network
234
235 exit 0