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