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