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