6542d021eecb17f63a14814b64051c1a6516598e
[openwrt/svn-archive/archive.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 for port in 5 4 3 2 1 0; do
22 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
23 continue
24 fi
25 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
26 wanports="$port $wanports"
27 else
28 lanports="$port $lanports"
29 fi
30 done
31 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
32 ucidef_add_switch "rt305x" "1" "1"
33 ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
34 ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
35 }
36
37 ramips_setup_interfaces()
38 {
39 local board="$1"
40
41 ucidef_set_interface_loopback
42
43 case $board in
44 all0256n | \
45 all5002 | \
46 dir-615-h1 | \
47 wl-330n)
48 ucidef_set_interface_lan "eth0.1"
49 ;;
50
51 3g-6200n | \
52 argus-atp52b | \
53 b2c | \
54 nw718 | \
55 psr-680w | \
56 sl-r7205 | \
57 w502u | \
58 wr6202)
59 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
60 ;;
61
62 f5d8235-v1 | \
63 f5d8235-v2 | \
64 ur-336un)
65 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
66 ;;
67
68 v11st-fe)
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 5t"
72 ucidef_add_switch_vlan "switch0" "2" "0 5t"
73 ;;
74
75 rt-n15 | \
76 wl-351)
77 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
78 ucidef_add_switch "switch0" "1" "1"
79 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
80 ucidef_add_switch_vlan "switch0" "2" "4 5t"
81 ;;
82
83 rt-n56u)
84 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
85 ucidef_add_switch "switch0" "1" "1"
86 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
87 ucidef_add_switch_vlan "switch0" "2" "4 8t"
88 ;;
89
90 freestation5 | \
91 wcr-150gn)
92 ucidef_set_interfaces_lan_wan "eth0.2" "eth0.1"
93 ;;
94
95 wli-tx4-ag300n)
96 ucidef_set_interface_lan "eth0"
97 ;;
98
99 *)
100 RT3X5X=`cat /proc/cpuinfo | grep RT3.5`
101 if [ -n "${RT3X5X}" ]; then
102 ramips_setup_rt3x5x_vlans
103 else
104 ucidef_set_interfaces_lan_wan "eth0" "eth1"
105 fi
106 ;;
107 esac
108 }
109
110 ramips_setup_macs()
111 {
112 local board="$1"
113 local lan_mac=""
114 local wan_mac=""
115
116 case $board in
117 all0256n | \
118 all5002 | \
119 dir-615-h1)
120 lan_mac=$(ramips_get_mac_binary factory 40)
121 ;;
122 3g-6200n | \
123 argus-atp52b | \
124 bc2 | \
125 f5d8235-v1 | \
126 nw718 | \
127 psr-680w | \
128 rt-n15 | \
129 sl-r7205 | \
130 wl-351)
131 lan_mac=$(ramips_get_mac_binary factory 4)
132 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
133 ;;
134
135 w306r-v20)
136 lan_mac=$(ramips_get_mac_binary factory 4)
137 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 5)
138 ;;
139
140 fonera20n)
141 lan_mac=$(ramips_get_mac_binary factory 40)
142 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
143 ;;
144
145 dir-300-b1 |\
146 dir-300-b2 |\
147 dir-600-b1)
148 lan_mac=$(ramips_get_mac_binary devdata 16388)
149 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
150 ;;
151
152 dir-620-a1)
153 lan_mac=$(ramips_get_mac_binary factory 4)
154 lan_mac=$(maccalc or "$lan_mac" "02:00:00:00:00:00")
155 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
156 ;;
157
158 esr-9753 | \
159 ur-336un)
160 lan_mac=$(ramips_get_mac_binary devdata 16388)
161 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
162 ;;
163
164 nbg-419n | \
165 wcr-150gn)
166 lan_mac=$(ramips_get_mac_binary factory 4)
167 wan_mac=$(ramips_get_mac_binary factory 40)
168 ;;
169
170 f5d8235-v2)
171 lan_mac=$(ramips_get_mac_binary "u-boot" 262148)
172 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
173 ;;
174
175 rt-n56u)
176 lan_mac=$(ramips_get_mac_binary factory 4)
177 wan_mac=$(ramips_get_mac_binary factory 32772)
178 ;;
179
180 all0239-3g | \
181 w502u)
182 lan_mac=$(ramips_get_mac_binary factory 40)
183 wan_mac=$(ramips_get_mac_binary factory 46)
184 ;;
185
186 wl341v3)
187 lan_mac=$(ramips_get_mac_binary board-nvram 65440)
188 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
189 ;;
190
191 wli-tx4-ag300n)
192 lan_mac=$(ramips_get_mac_binary factory 4)
193 ;;
194
195 esac
196
197 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
198 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
199 }
200
201 [ -e /etc/config/network ] && exit 0
202
203 touch /etc/config/network
204
205 board=$(ramips_board_name)
206
207 ramips_setup_interfaces $board
208 ramips_setup_macs $board
209
210 uci commit network
211
212 exit 0