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