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