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