ramips: add user space support for the DIR-645
[openwrt.git] / target / linux / ramips / base-files / etc / uci-defaults / network
1 #!/bin/sh
2
3 . /etc/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         all0256n | \
46         all5002)
47                 ucidef_set_interface_lan "eth0"
48                 ;;
49
50         dir-615-h1 | \
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         dir-645)
67                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
68                 ucidef_add_switch "switch0" "1" "1"
69                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
70                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
71                 ;;
72
73         f5d8235-v1 | \
74         f5d8235-v2 | \
75         ur-336un)
76                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
77                 ;;
78
79         v11st-fe)
80                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
81                 ucidef_add_switch "switch0" "1" "1"
82                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
83                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
84                 ;;
85
86         rt-n15 | \
87         wl-351)
88                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
89                 ucidef_add_switch "switch0" "1" "1"
90                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
91                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
92                 ;;
93
94         rt-n56u)
95                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
96                 ucidef_add_switch "switch0" "1" "1"
97                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
98                 ucidef_add_switch_vlan "switch0" "2" "4 8t"
99                 ;;
100
101         freestation5 | \
102         wcr-150gn)
103                 ucidef_set_interfaces_lan_wan "eth0.2" "eth0.1"
104                 ;;
105
106         wli-tx4-ag300n)
107                 ucidef_set_interface_lan "eth0"
108                 ;;
109
110         *)
111                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
112                 if [ -n "${RT3X5X}" ]; then
113                         ramips_setup_rt3x5x_vlans
114                 else
115                         ucidef_set_interfaces_lan_wan "eth0" "eth1"
116                 fi
117                 ;;
118         esac
119 }
120
121 ramips_setup_macs()
122 {
123         local board="$1"
124         local lan_mac=""
125         local wan_mac=""
126
127         case $board in
128         all0256n | \
129         all5002 | \
130         dir-615-h1)
131                 lan_mac=$(ramips_get_mac_binary factory 40)
132                 ;;
133         3g-6200n | \
134         argus-atp52b | \
135         bc2 | \
136         f5d8235-v1 | \
137         nw718 | \
138         psr-680w | \
139         rt-n15 | \
140         sl-r7205 | \
141         wl-351)
142                 lan_mac=$(ramips_get_mac_binary factory 4)
143                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
144                 ;;
145
146         w306r-v20)
147                 lan_mac=$(ramips_get_mac_binary factory 4)
148                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 5)
149                 ;;
150
151         fonera20n)
152                 lan_mac=$(ramips_get_mac_binary factory 40)
153                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
154                 ;;
155
156         dir-300-b1 |\
157         dir-300-b2 |\
158         dir-600-b1)
159                 lan_mac=$(ramips_get_mac_binary devdata 16388)
160                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
161                 ;;
162
163         dir-620-a1)
164                 lan_mac=$(ramips_get_mac_binary factory 4)
165                 lan_mac=$(maccalc or "$lan_mac" "02:00:00:00:00:00")
166                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
167                 ;;
168
169         dir-645)
170                 lan_mac=$(ramips_get_mac_nvram nvram lanmac)
171                 wan_mac=$(ramips_get_mac_nvram nvram wanmac)
172                 ;;
173
174         esr-9753 | \
175         ur-336un)
176                 lan_mac=$(ramips_get_mac_binary devdata 16388)
177                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
178                 ;;
179
180         nbg-419n | \
181         wcr-150gn)
182                 lan_mac=$(ramips_get_mac_binary factory 4)
183                 wan_mac=$(ramips_get_mac_binary factory 40)
184                 ;;
185
186         f5d8235-v2)
187                 lan_mac=$(ramips_get_mac_binary "u-boot" 262148)
188                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
189                 ;;
190
191         rt-n56u)
192                 lan_mac=$(ramips_get_mac_binary factory 4)
193                 wan_mac=$(ramips_get_mac_binary factory 32772)
194                 ;;
195
196         all0239-3g | \
197         carambola | \
198         w502u)
199                 lan_mac=$(ramips_get_mac_binary factory 40)
200                 wan_mac=$(ramips_get_mac_binary factory 46)
201                 ;;
202
203         wl341v3)
204                 lan_mac=$(ramips_get_mac_binary board-nvram 65440)
205                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
206                 ;;
207
208         wli-tx4-ag300n)
209                 lan_mac=$(ramips_get_mac_binary factory 4)
210                 ;;
211
212         esac
213
214         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
215         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
216 }
217
218 [ -e /etc/config/network ] && exit 0
219
220 touch /etc/config/network
221
222 board=$(ramips_board_name)
223
224 ramips_setup_interfaces $board
225 ramips_setup_macs $board
226
227 uci commit network
228
229 exit 0