ramips: fix missing inclusion of system.sh for mtd_get_mac_binary and friends.
[openwrt/staging/yousong.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 . /lib/functions/system.sh
7
8 ramips_setup_rt3x5x_vlans()
9 {
10 if [ ! -x /sbin/swconfig ]; then
11 # legacy default
12 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
13 return
14 fi
15 local wanports=""
16 local lanports=""
17 for port in 5 4 3 2 1 0; do
18 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
19 continue
20 fi
21 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
22 wanports="$port $wanports"
23 else
24 lanports="$port $lanports"
25 fi
26 done
27 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
28 ucidef_add_switch "rt305x" "1" "1"
29 ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
30 ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
31 }
32
33 ramips_setup_interfaces()
34 {
35 local board="$1"
36
37 ucidef_set_interface_loopback
38
39 case $board in
40 3g300m | \
41 w150m | \
42 all0256n | \
43 all5002 | \
44 all5003 | \
45 broadway | \
46 dcs-930| \
47 ncs601w | \
48 wnce2001)
49 ucidef_add_switch "switch0" "1" "0"
50 ucidef_set_interface_lan "eth0"
51 ;;
52
53 3g-6200nl | \
54 wl-330n | \
55 wmr300)
56 ucidef_set_interface_lan "eth0.1"
57 ;;
58
59 3g-6200n | \
60 b2c | \
61 nw718 | \
62 psr-680w | \
63 sl-r7205 | \
64 w502u | \
65 wr6202)
66 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
67 ;;
68
69 awapn2403)
70 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
71 ucidef_add_switch "switch0" "1" "1"
72 ucidef_add_switch_vlan "switch0" "1" "0 6t"
73 ucidef_add_switch_vlan "switch0" "2" "1 6t"
74 ;;
75
76 br-6475nd)
77 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
78 ucidef_add_switch "switch0" "1" "1"
79 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
80 ucidef_add_switch_vlan "switch0" "2" "0 9t"
81 ;;
82
83 asl26555)
84 ucidef_set_interface_lan "eth0.1"
85 ucidef_add_switch "switch0" "1" "1"
86 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
87 ;;
88
89 cy-swr1100)
90 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
91 ucidef_add_switch "switch0" "1" "1"
92 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t"
93 ucidef_add_switch_vlan "switch0" "2" "4 9t"
94 ;;
95
96 dir-610-a1 | \
97 dir-300-b7 | \
98 dir-320-b1 | \
99 dir-615-h1 | \
100 hlk-rm04 | \
101 mzk-w300nh2 | \
102 mzk-750dhp)
103 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
104 ucidef_add_switch "switch0" "1" "1"
105 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
106 ucidef_add_switch_vlan "switch0" "2" "4 6t"
107 ;;
108
109 awm002-evb | \
110 argus-atp52b | \
111 dir-645 | \
112 f5d8235-v1 | \
113 f5d8235-v2 | \
114 hg255d | \
115 rt-n14u | \
116 wrtnode | \
117 ur-326n4g | \
118 zbt-wa05)
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 6t"
122 ucidef_add_switch_vlan "switch0" "2" "0 6t"
123 ;;
124
125 ur-336un)
126 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
127 ;;
128
129 br6524n | \
130 v11st-fe)
131 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
132 ucidef_add_switch "switch0" "1" "1"
133 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
134 ucidef_add_switch_vlan "switch0" "2" "0 5t"
135 ;;
136
137 ar725w | \
138 rt-n15 | \
139 wl-351)
140 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
141 ucidef_add_switch "switch0" "1" "1"
142 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
143 ucidef_add_switch_vlan "switch0" "2" "4 5t"
144 ;;
145
146 rt-n56u)
147 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
148 ucidef_add_switch "switch0" "1" "1"
149 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
150 ucidef_add_switch_vlan "switch0" "2" "4 8t"
151 ;;
152
153 tew-691gr|\
154 tew-692gr)
155 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
156 ucidef_add_switch "switch0" "1" "1"
157 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
158 ucidef_add_switch_vlan "switch0" "2" "0t 5"
159 ;;
160
161 wcr-150gn)
162 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
163 ucidef_add_switch "switch0" "1" "1"
164 ucidef_add_switch_vlan "switch0" "1" "0 6t"
165 ucidef_add_switch_vlan "switch0" "2" "6t"
166 ;;
167
168 wr8305rt)
169 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
170 ucidef_add_switch "switch0" "1" "1"
171 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
172 ucidef_add_switch_vlan "switch0" "2" "4 6t"
173 ;;
174
175 d105 | \
176 na930 | \
177 omni-emb-hpm|\
178 wli-tx4-ag300n)
179 ucidef_set_interface_lan "eth0"
180 ;;
181
182 *)
183 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
184 if [ -n "${RT3X5X}" ]; then
185 ramips_setup_rt3x5x_vlans
186 else
187 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
188 fi
189 ;;
190 esac
191 }
192
193 ramips_setup_macs()
194 {
195 local board="$1"
196 local lan_mac=""
197 local wan_mac=""
198
199 case $board in
200 br-6475nd)
201 lan_mac=$(mtd_get_mac_binary devdata 13)
202 wan_mac=$(mtd_get_mac_binary devdata 7)
203 ;;
204
205 w306r-v20)
206 wan_mac=$(macaddr_add "$lan_mac" 5)
207 ;;
208
209 tew-691gr)
210 wan_mac=$(macaddr_add "$lan_mac" 3)
211 ;;
212
213 tew-692gr)
214 wan_mac=$(macaddr_add "$lan_mac" 4)
215 ;;
216
217 m3 |\
218 m4 |\
219 x5 |\
220 x8)
221 lan_mac=$(macaddr_add "$lan_mac" -1)
222 ;;
223
224 dir-620-a1)
225 lan_mac=$(macaddr_setbit_la "$lan_mac")
226 wan_mac=$(macaddr_add "$lan_mac" 1)
227 ;;
228
229 cy-swr1100 | \
230 dir-645)
231 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
232 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
233 ;;
234
235 nbg-419n | \
236 wcr-150gn)
237 wan_mac=$(mtd_get_mac_binary factory 40)
238 ;;
239
240 rt-n56u)
241 wan_mac=$(mtd_get_mac_binary factory 32772)
242 ;;
243
244 all0239-3g | \
245 carambola | \
246 freestation5 | \
247 w502u | \
248 wnce2001)
249 wan_mac=$(mtd_get_mac_binary factory 46)
250 ;;
251
252 wl341v3)
253 lan_mac=$(mtd_get_mac_binary board-nvram 65440)
254 wan_mac=$(macaddr_add "$lan_mac" 1)
255 ;;
256
257 wr8305rt)
258 lan_mac=$(mtd_get_mac_binary factory 4)
259 wan_mac=$(macaddr_add "$lan_mac" 1)
260 ;;
261
262 *)
263 lan_mac=$(cat /sys/class/net/eth0/address)
264 wan_mac=$(macaddr_add "$lan_mac" 1)
265 ;;
266
267 esac
268
269 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
270 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
271 }
272
273 [ -e /etc/config/network ] && exit 0
274
275 touch /etc/config/network
276
277 board=$(ramips_board_name)
278
279 ramips_setup_interfaces $board
280 ramips_setup_macs $board
281
282 uci commit network
283
284 exit 0