a8e5ef9d7ca52a454cc81cffcb28fac4645833fa
[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 if [ ! -x /usr/sbin/maccalc ]; then
8         echo "$0: maccalc not found!"
9         return
10 fi
11
12 ramips_setup_rt3x5x_vlans()
13 {
14         if [ ! -x /sbin/swconfig ]; then
15                 # legacy default
16                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
17                 return
18         fi
19         local wanports=""
20         local lanports=""
21         swconfig dev rt305x set reset 1
22         for port in 5 4 3 2 1 0; do
23                 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
24                         continue
25                 fi
26                 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
27                         wanports="$port $wanports"
28                 else
29                         lanports="$port $lanports"
30                 fi
31         done
32         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
33         ucidef_add_switch "rt305x" "1" "1"
34         ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
35         ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
36 }
37
38 ramips_setup_interfaces()
39 {
40         local board="$1"
41
42         ucidef_set_interface_loopback
43
44         case $board in
45         3g300m | \
46         all0256n | \
47         all5002 | \
48         broadway)
49                 ucidef_set_interface_lan "eth0"
50                 ;;
51
52         dir-615-h1 | \
53         wl-330n)
54                 ucidef_set_interface_lan "eth0.1"
55                 ;;
56
57         3g-6200n | \
58         argus-atp52b | \
59         b2c | \
60         nw718 | \
61         psr-680w | \
62         sl-r7205 | \
63         w502u | \
64         wr6202)
65                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
66                 ;;
67
68         dir-645)
69                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
70                 ucidef_add_switch "switch0" "1" "1"
71                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
72                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
73                 ;;
74
75         mzk-w300nh2)
76                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
77                 ucidef_add_switch "switch0" "1" "1"
78                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
79                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
80                 ;;
81
82         f5d8235-v1 | \
83         f5d8235-v2 | \
84         ur-336un)
85                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
86                 ;;
87
88         br6524n | \
89         v11st-fe)
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 5t"
93                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
94                 ;;
95
96         rt-n15 | \
97         wl-351)
98                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
99                 ucidef_add_switch "switch0" "1" "1"
100                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
101                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
102                 ;;
103
104         rt-n56u)
105                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
106                 ucidef_add_switch "switch0" "1" "1"
107                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
108                 ucidef_add_switch_vlan "switch0" "2" "4 8t"
109                 ;;
110
111         tew-691gr|\
112         tew-692gr)
113                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
114                 ucidef_add_switch "switch0" "1" "1"
115                 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
116                 ucidef_add_switch_vlan "switch0" "2" "0t 5"
117                 ;;
118
119         freestation5 | \
120         wcr-150gn)
121                 ucidef_set_interfaces_lan_wan "eth0.2" "eth0.1"
122                 ;;
123
124         wli-tx4-ag300n)
125                 ucidef_set_interface_lan "eth0"
126                 ;;
127
128         *)
129                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
130                 if [ -n "${RT3X5X}" ]; then
131                         ramips_setup_rt3x5x_vlans
132                 else
133                         ucidef_set_interfaces_lan_wan "eth0" "eth1"
134                 fi
135                 ;;
136         esac
137 }
138
139 ramips_setup_macs()
140 {
141         local board="$1"
142         local lan_mac=""
143         local wan_mac=""
144
145         case $board in
146         all0256n | \
147         all5002 | \
148         dir-615-h1)
149                 lan_mac=$(ramips_get_mac_binary factory 40)
150                 ;;
151         3g-6200n | \
152         3g300m | \
153         air3gii | \
154         argus-atp52b | \
155         bc2 | \
156         broadway | \
157         f5d8235-v1 | \
158         mzk-w300nh2 | \
159         nw718 | \
160         psr-680w | \
161         rt-n15 | \
162         sl-r7205 | \
163         wl-351)
164                 lan_mac=$(ramips_get_mac_binary factory 4)
165                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
166                 ;;
167
168         w306r-v20)
169                 lan_mac=$(ramips_get_mac_binary factory 4)
170                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 5)
171                 ;;
172
173         rt-n13u | \
174         fonera20n)
175                 lan_mac=$(ramips_get_mac_binary factory 40)
176                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
177                 ;;
178
179         dir-300-b1 |\
180         dir-300-b2 |\
181         dir-600-b1)
182                 lan_mac=$(ramips_get_mac_binary devdata 16388)
183                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
184                 ;;
185
186         dir-620-a1)
187                 lan_mac=$(ramips_get_mac_binary factory 4)
188                 lan_mac=$(maccalc or "$lan_mac" "02:00:00:00:00:00")
189                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
190                 ;;
191
192         dir-645)
193                 lan_mac=$(ramips_get_mac_nvram nvram lanmac)
194                 wan_mac=$(ramips_get_mac_nvram nvram wanmac)
195                 ;;
196
197         esr-9753 | \
198         ur-336un)
199                 lan_mac=$(ramips_get_mac_binary devdata 16388)
200                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
201                 ;;
202
203         nbg-419n | \
204         wcr-150gn)
205                 lan_mac=$(ramips_get_mac_binary factory 4)
206                 wan_mac=$(ramips_get_mac_binary factory 40)
207                 ;;
208
209         f5d8235-v2)
210                 lan_mac=$(ramips_get_mac_binary "u-boot" 262148)
211                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
212                 ;;
213
214         rt-n56u)
215                 lan_mac=$(ramips_get_mac_binary factory 4)
216                 wan_mac=$(ramips_get_mac_binary factory 32772)
217                 ;;
218
219         tew-691gr)
220                 lan_mac=$(ramips_get_mac_binary factory 40)
221                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 3)
222                 ;;
223
224         tew-692gr)
225                 lan_mac=$(ramips_get_mac_binary factory 40)
226                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 4)
227                 ;;
228
229         all0239-3g | \
230         carambola | \
231         w502u)
232                 lan_mac=$(ramips_get_mac_binary factory 40)
233                 wan_mac=$(ramips_get_mac_binary factory 46)
234                 ;;
235
236         wl341v3)
237                 lan_mac=$(ramips_get_mac_binary board-nvram 65440)
238                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
239                 ;;
240
241         wli-tx4-ag300n)
242                 lan_mac=$(ramips_get_mac_binary factory 4)
243                 ;;
244
245         esac
246
247         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
248         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
249 }
250
251 [ -e /etc/config/network ] && exit 0
252
253 touch /etc/config/network
254
255 board=$(ramips_board_name)
256
257 ramips_setup_interfaces $board
258 ramips_setup_macs $board
259
260 uci commit network
261
262 exit 0