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