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