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