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