ramips: rt305x: add user-space support for the Asus RT-N13U
[openwrt/openwrt.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-691gr|\
102 tew-692gr)
103 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
104 ucidef_add_switch "switch0" "1" "1"
105 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
106 ucidef_add_switch_vlan "switch0" "2" "0t 5"
107 ;;
108
109 freestation5 | \
110 wcr-150gn)
111 ucidef_set_interfaces_lan_wan "eth0.2" "eth0.1"
112 ;;
113
114 wli-tx4-ag300n)
115 ucidef_set_interface_lan "eth0"
116 ;;
117
118 *)
119 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
120 if [ -n "${RT3X5X}" ]; then
121 ramips_setup_rt3x5x_vlans
122 else
123 ucidef_set_interfaces_lan_wan "eth0" "eth1"
124 fi
125 ;;
126 esac
127 }
128
129 ramips_setup_macs()
130 {
131 local board="$1"
132 local lan_mac=""
133 local wan_mac=""
134
135 case $board in
136 all0256n | \
137 all5002 | \
138 dir-615-h1)
139 lan_mac=$(ramips_get_mac_binary factory 40)
140 ;;
141 3g-6200n | \
142 argus-atp52b | \
143 bc2 | \
144 f5d8235-v1 | \
145 nw718 | \
146 psr-680w | \
147 rt-n15 | \
148 sl-r7205 | \
149 wl-351)
150 lan_mac=$(ramips_get_mac_binary factory 4)
151 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
152 ;;
153
154 w306r-v20)
155 lan_mac=$(ramips_get_mac_binary factory 4)
156 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 5)
157 ;;
158
159 rt-n13u | \
160 fonera20n)
161 lan_mac=$(ramips_get_mac_binary factory 40)
162 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
163 ;;
164
165 dir-300-b1 |\
166 dir-300-b2 |\
167 dir-600-b1)
168 lan_mac=$(ramips_get_mac_binary devdata 16388)
169 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
170 ;;
171
172 dir-620-a1)
173 lan_mac=$(ramips_get_mac_binary factory 4)
174 lan_mac=$(maccalc or "$lan_mac" "02:00:00:00:00:00")
175 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
176 ;;
177
178 dir-645)
179 lan_mac=$(ramips_get_mac_nvram nvram lanmac)
180 wan_mac=$(ramips_get_mac_nvram nvram wanmac)
181 ;;
182
183 esr-9753 | \
184 ur-336un)
185 lan_mac=$(ramips_get_mac_binary devdata 16388)
186 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
187 ;;
188
189 nbg-419n | \
190 wcr-150gn)
191 lan_mac=$(ramips_get_mac_binary factory 4)
192 wan_mac=$(ramips_get_mac_binary factory 40)
193 ;;
194
195 f5d8235-v2)
196 lan_mac=$(ramips_get_mac_binary "u-boot" 262148)
197 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
198 ;;
199
200 rt-n56u)
201 lan_mac=$(ramips_get_mac_binary factory 4)
202 wan_mac=$(ramips_get_mac_binary factory 32772)
203 ;;
204
205 tew-691gr)
206 lan_mac=$(ramips_get_mac_binary factory 40)
207 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 3)
208 ;;
209
210 tew-692gr)
211 lan_mac=$(ramips_get_mac_binary factory 40)
212 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 4)
213 ;;
214
215 all0239-3g | \
216 carambola | \
217 w502u)
218 lan_mac=$(ramips_get_mac_binary factory 40)
219 wan_mac=$(ramips_get_mac_binary factory 46)
220 ;;
221
222 wl341v3)
223 lan_mac=$(ramips_get_mac_binary board-nvram 65440)
224 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
225 ;;
226
227 wli-tx4-ag300n)
228 lan_mac=$(ramips_get_mac_binary factory 4)
229 ;;
230
231 esac
232
233 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
234 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
235 }
236
237 [ -e /etc/config/network ] && exit 0
238
239 touch /etc/config/network
240
241 board=$(ramips_board_name)
242
243 ramips_setup_interfaces $board
244 ramips_setup_macs $board
245
246 uci commit network
247
248 exit 0