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