703471838df7b8ea2ff057301307b96ddc550df6
[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 br-6475nd)
69 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
70 ucidef_add_switch "switch0" "1" "1"
71 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
72 ucidef_add_switch_vlan "switch0" "2" "0 9t"
73 ;;
74
75 asl26555)
76 ucidef_set_interface_lan "eth0.1"
77 ucidef_add_switch "switch0" "1" "1"
78 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
79 ;;
80
81 dir-610-a1 | \
82 dir-300-b7 | \
83 dir-320-b1 | \
84 dir-615-h1 | \
85 hlk-rm04 | \
86 mzk-w300nh2)
87 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
88 ucidef_add_switch "switch0" "1" "1"
89 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
90 ucidef_add_switch_vlan "switch0" "2" "4 6t"
91 ;;
92
93 argus-atp52b | \
94 dir-645 | \
95 f5d8235-v1 | \
96 f5d8235-v2 | \
97 hg255d | \
98 rt-n14u | \
99 ur-326n4g)
100 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
101 ucidef_add_switch "switch0" "1" "1"
102 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
103 ucidef_add_switch_vlan "switch0" "2" "0 6t"
104 ;;
105
106 ur-336un)
107 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
108 ;;
109
110 br6524n | \
111 v11st-fe)
112 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
113 ucidef_add_switch "switch0" "1" "1"
114 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
115 ucidef_add_switch_vlan "switch0" "2" "0 5t"
116 ;;
117
118 rt-n15 | \
119 wl-351)
120 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
121 ucidef_add_switch "switch0" "1" "1"
122 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
123 ucidef_add_switch_vlan "switch0" "2" "4 5t"
124 ;;
125
126 rt-n56u)
127 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
128 ucidef_add_switch "switch0" "1" "1"
129 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
130 ucidef_add_switch_vlan "switch0" "2" "4 8t"
131 ;;
132
133 tew-691gr|\
134 tew-692gr)
135 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
136 ucidef_add_switch "switch0" "1" "1"
137 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
138 ucidef_add_switch_vlan "switch0" "2" "0t 5"
139 ;;
140
141 wcr-150gn)
142 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
143 ucidef_add_switch "switch0" "1" "1"
144 ucidef_add_switch_vlan "switch0" "1" "0 6t"
145 ucidef_add_switch_vlan "switch0" "2" "6t"
146 ;;
147
148 d105 | \
149 na930 | \
150 omni-emb-hpm|\
151 wli-tx4-ag300n)
152 ucidef_set_interface_lan "eth0"
153 ;;
154
155 *)
156 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
157 if [ -n "${RT3X5X}" ]; then
158 ramips_setup_rt3x5x_vlans
159 else
160 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
161 fi
162 ;;
163 esac
164 }
165
166 ramips_setup_macs()
167 {
168 local board="$1"
169 local lan_mac=""
170 local wan_mac=""
171
172 case $board in
173 *)
174 wan_mac=$(macaddr_add "$lan_mac" 1)
175 ;;
176
177 br-6475nd)
178 lan_mac=$(mtd_get_mac_binary devdata 13)
179 wan_mac=$(mtd_get_mac_binary devdata 7)
180 ;;
181
182 w306r-v20)
183 wan_mac=$(macaddr_add "$lan_mac" 5)
184 ;;
185
186 tew-691gr)
187 wan_mac=$(macaddr_add "$lan_mac" 3)
188 ;;
189
190 tew-692gr)
191 wan_mac=$(macaddr_add "$lan_mac" 4)
192 ;;
193
194 m3 |\
195 m4 |\
196 x5 |\
197 x8)
198 lan_mac=$(macaddr_add "$lan_mac" -1)
199 ;;
200
201 dir-620-a1)
202 lan_mac=$(macaddr_setbit_la "$lan_mac")
203 wan_mac=$(macaddr_add "$lan_mac" 1)
204 ;;
205
206 dir-645)
207 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
208 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
209 ;;
210
211 nbg-419n | \
212 wcr-150gn)
213 wan_mac=$(mtd_get_mac_binary factory 40)
214 ;;
215
216 rt-n56u)
217 wan_mac=$(mtd_get_mac_binary factory 32772)
218 ;;
219
220 all0239-3g | \
221 carambola | \
222 freestation5 | \
223 w502u | \
224 wnce2001)
225 wan_mac=$(mtd_get_mac_binary factory 46)
226 ;;
227
228 wl341v3)
229 lan_mac=$(mtd_get_mac_binary board-nvram 65440)
230 wan_mac=$(macaddr_add "$lan_mac" 1)
231 ;;
232
233 esac
234
235 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
236 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
237 }
238
239 [ -e /etc/config/network ] && exit 0
240
241 touch /etc/config/network
242
243 board=$(ramips_board_name)
244
245 ramips_setup_interfaces $board
246 ramips_setup_macs $board
247
248 uci commit network
249
250 exit 0