e444ef246dc2ef534af193632eed4d2690b282ef
[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         wnce2001)
47                 ucidef_add_switch "switch0" "1" "0"
48                 ucidef_set_interface_lan "eth0"
49                 ;;
50
51         3g-6200nl | \
52         wl-330n)
53                 ucidef_set_interface_lan "eth0.1"
54                 ;;
55
56         3g-6200n | \
57         argus-atp52b | \
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         asl26555)
68                 ucidef_set_interface_lan "eth0.1"
69                 ucidef_add_switch "switch0" "1" "1"
70                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
71                 ;;
72
73         dir-645)
74                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
75                 ucidef_add_switch "switch0" "1" "1"
76                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
77                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
78                 ;;
79
80         dir-610-a1 | \
81         dir-615-h1 | \
82         mzk-w300nh2)
83                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
84                 ucidef_add_switch "switch0" "1" "1"
85                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
86                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
87                 ;;
88
89         f5d8235-v1 | \
90         f5d8235-v2 | \
91         hg255d | \
92         ur-326n4g)
93                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
94                 ucidef_add_switch "switch0" "1" "1"
95                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
96                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
97                 ;;
98
99         ur-336un)
100                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
101                 ;;
102
103         br6524n | \
104         v11st-fe)
105                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
106                 ucidef_add_switch "switch0" "1" "1"
107                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
108                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
109                 ;;
110
111         rt-n15 | \
112         wl-351)
113                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
114                 ucidef_add_switch "switch0" "1" "1"
115                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
116                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
117                 ;;
118
119         rt-n56u)
120                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
121                 ucidef_add_switch "switch0" "1" "1"
122                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
123                 ucidef_add_switch_vlan "switch0" "2" "4 8t"
124                 ;;
125
126         tew-691gr|\
127         tew-692gr)
128                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
129                 ucidef_add_switch "switch0" "1" "1"
130                 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
131                 ucidef_add_switch_vlan "switch0" "2" "0t 5"
132                 ;;
133
134         wcr-150gn)
135                 ucidef_set_interfaces_lan_wan "eth0.2" "eth0.1"
136                 ;;
137
138         d105 | \
139         omni-emb-hpm|\
140         wli-tx4-ag300n)
141                 ucidef_set_interface_lan "eth0"
142                 ;;
143
144         *)
145                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
146                 if [ -n "${RT3X5X}" ]; then
147                         ramips_setup_rt3x5x_vlans
148                 else
149                         ucidef_set_interfaces_lan_wan "eth0" "eth1"
150                 fi
151                 ;;
152         esac
153 }
154
155 ramips_setup_macs()
156 {
157         local board="$1"
158         local lan_mac=""
159         local wan_mac=""
160
161         case $board in
162         all0256n | \
163         all5002 | \
164         dir-615-h1)
165                 lan_mac=$(mtd_get_mac_binary factory 40)
166                 ;;
167         3g-6200n | \
168         3g300m | \
169         w150m | \
170         air3gii | \
171         argus-atp52b | \
172         bc2 | \
173         br6425 | \
174         broadway | \
175         dir-620-d1 | \
176         f5d8235-v1 | \
177         ip2202 | \
178         mpr-a1 | \
179         mpr-a2 | \
180         mzk-w300nh2 | \
181         nw718 | \
182         psr-680w | \
183         rt-n15 | \
184         sl-r7205 | \
185         wl-351)
186                 lan_mac=$(mtd_get_mac_binary factory 4)
187                 wan_mac=$(macaddr_add "$lan_mac" 1)
188                 ;;
189
190         asl26555)
191                 lan_mac=$(mtd_get_mac_binary devdata 16388)
192                 ;;
193
194         w306r-v20)
195                 lan_mac=$(mtd_get_mac_binary factory 4)
196                 wan_mac=$(macaddr_add "$lan_mac" 5)
197                 ;;
198
199         rt-n13u | \
200         hg255d  | \
201         fonera20n | \
202         dir-810l)
203                 lan_mac=$(mtd_get_mac_binary factory 40)
204                 wan_mac=$(macaddr_add "$lan_mac" 1)
205                 ;;
206
207         dir-300-b1 |\
208         dir-300-b2 |\
209         dir-600-b1 |\
210         dir-610-a1)
211                 lan_mac=$(mtd_get_mac_binary devdata 16388)
212                 wan_mac=$(macaddr_add "$lan_mac" 1)
213                 ;;
214
215         dir-620-a1)
216                 lan_mac=$(mtd_get_mac_binary factory 4)
217                 lan_mac=$(macaddr_setbit_la "$lan_mac")
218                 wan_mac=$(macaddr_add "$lan_mac" 1)
219                 ;;
220
221         dir-645)
222                 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
223                 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
224                 ;;
225
226         esr-9753 | \
227         ur-326n4g | \
228         ur-336un)
229                 lan_mac=$(mtd_get_mac_binary devdata 16388)
230                 wan_mac=$(macaddr_add "$lan_mac" 1)
231                 ;;
232
233         m3 |\
234         m4 |\
235         x5 |\
236         x8)
237                 lan_mac=$(mtd_get_mac_binary factory 4)
238                 lan_mac=$(macaddr_add "$lan_mac" -1)
239                 ;;
240
241         nbg-419n | \
242         wcr-150gn)
243                 lan_mac=$(mtd_get_mac_binary factory 4)
244                 wan_mac=$(mtd_get_mac_binary factory 40)
245                 ;;
246
247         omni-emb-hpm)
248                 lan_mac=$(mtd_get_mac_binary factory 40)
249                 ;;
250
251         f5d8235-v2)
252                 lan_mac=$(mtd_get_mac_binary "u-boot" 262148)
253                 wan_mac=$(macaddr_add "$lan_mac" 1)
254                 ;;
255
256         rt-n56u)
257                 lan_mac=$(mtd_get_mac_binary factory 4)
258                 wan_mac=$(mtd_get_mac_binary factory 32772)
259                 ;;
260
261         tew-691gr)
262                 lan_mac=$(mtd_get_mac_binary factory 40)
263                 wan_mac=$(macaddr_add "$lan_mac" 3)
264                 ;;
265
266         tew-692gr)
267                 lan_mac=$(mtd_get_mac_binary factory 40)
268                 wan_mac=$(macaddr_add "$lan_mac" 4)
269                 ;;
270
271         all0239-3g | \
272         carambola | \
273         freestation5 | \
274         w502u | \
275         wnce2001)
276                 lan_mac=$(mtd_get_mac_binary factory 40)
277                 wan_mac=$(mtd_get_mac_binary factory 46)
278                 ;;
279
280         wl341v3)
281                 lan_mac=$(mtd_get_mac_binary board-nvram 65440)
282                 wan_mac=$(macaddr_add "$lan_mac" 1)
283                 ;;
284
285         d105 | \
286         wli-tx4-ag300n)
287                 lan_mac=$(mtd_get_mac_binary factory 4)
288                 ;;
289
290         esac
291
292         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
293         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
294 }
295
296 [ -e /etc/config/network ] && exit 0
297
298 touch /etc/config/network
299
300 board=$(ramips_board_name)
301
302 ramips_setup_interfaces $board
303 ramips_setup_macs $board
304
305 uci commit network
306
307 exit 0