Commit | Line | Data |
---|---|---|
f2129354 JB |
1 | /* |
2 | * cfg80211 wext compat for managed mode. | |
3 | * | |
4 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> | |
5 | * Copyright (C) 2009 Intel Corporation. All rights reserved. | |
6 | */ | |
7 | ||
8 | #include <linux/etherdevice.h> | |
9 | #include <linux/if_arp.h> | |
10 | #include <net/cfg80211.h> | |
0e82ffe3 | 11 | #include "wext-compat.h" |
f2129354 JB |
12 | #include "nl80211.h" |
13 | ||
fffd0934 JB |
14 | int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev, |
15 | struct wireless_dev *wdev) | |
f2129354 | 16 | { |
fffd0934 JB |
17 | struct cfg80211_cached_keys *ck = NULL; |
18 | int err, i; | |
f2129354 | 19 | |
667503dd JB |
20 | ASSERT_RDEV_LOCK(rdev); |
21 | ASSERT_WDEV_LOCK(wdev); | |
22 | ||
f2129354 JB |
23 | if (!netif_running(wdev->netdev)) |
24 | return 0; | |
25 | ||
26 | wdev->wext.connect.ie = wdev->wext.ie; | |
27 | wdev->wext.connect.ie_len = wdev->wext.ie_len; | |
28 | wdev->wext.connect.privacy = wdev->wext.default_key != -1; | |
29 | ||
fffd0934 JB |
30 | if (wdev->wext.keys) { |
31 | wdev->wext.keys->def = wdev->wext.default_key; | |
32 | wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key; | |
33 | } | |
34 | ||
35 | if (!wdev->wext.connect.ssid_len) | |
36 | return 0; | |
37 | ||
38 | if (wdev->wext.keys) { | |
39 | ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL); | |
40 | if (!ck) | |
41 | return -ENOMEM; | |
42 | for (i = 0; i < 6; i++) | |
43 | ck->params[i].key = ck->data[i]; | |
44 | } | |
45 | err = __cfg80211_connect(rdev, wdev->netdev, | |
46 | &wdev->wext.connect, ck); | |
47 | if (err) | |
48 | kfree(ck); | |
f2129354 JB |
49 | |
50 | return err; | |
51 | } | |
52 | ||
53 | int cfg80211_mgd_wext_siwfreq(struct net_device *dev, | |
54 | struct iw_request_info *info, | |
59bbb6f7 | 55 | struct iw_freq *wextfreq, char *extra) |
f2129354 JB |
56 | { |
57 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
58 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
59bbb6f7 JB |
59 | struct ieee80211_channel *chan = NULL; |
60 | int err, freq; | |
f2129354 JB |
61 | |
62 | /* call only for station! */ | |
63 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) | |
64 | return -EINVAL; | |
65 | ||
59bbb6f7 JB |
66 | freq = cfg80211_wext_freq(wdev->wiphy, wextfreq); |
67 | if (freq < 0) | |
68 | return freq; | |
f2129354 | 69 | |
59bbb6f7 JB |
70 | if (freq) { |
71 | chan = ieee80211_get_channel(wdev->wiphy, freq); | |
72 | if (!chan) | |
73 | return -EINVAL; | |
74 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
75 | return -EINVAL; | |
76 | } | |
f2129354 | 77 | |
667503dd | 78 | cfg80211_lock_rdev(rdev); |
59bbb6f7 | 79 | mutex_lock(&rdev->devlist_mtx); |
667503dd JB |
80 | wdev_lock(wdev); |
81 | ||
f2129354 JB |
82 | if (wdev->sme_state != CFG80211_SME_IDLE) { |
83 | bool event = true; | |
25e83c49 JB |
84 | |
85 | if (wdev->wext.connect.channel == chan) { | |
86 | err = 0; | |
87 | goto out; | |
88 | } | |
89 | ||
f2129354 JB |
90 | /* if SSID set, we'll try right again, avoid event */ |
91 | if (wdev->wext.connect.ssid_len) | |
92 | event = false; | |
59bbb6f7 JB |
93 | err = __cfg80211_disconnect(rdev, dev, |
94 | WLAN_REASON_DEAUTH_LEAVING, event); | |
f2129354 | 95 | if (err) |
667503dd | 96 | goto out; |
f2129354 JB |
97 | } |
98 | ||
667503dd | 99 | |
f2129354 JB |
100 | wdev->wext.connect.channel = chan; |
101 | ||
102 | /* SSID is not set, we just want to switch channel */ | |
59bbb6f7 JB |
103 | if (chan && !wdev->wext.connect.ssid_len) { |
104 | err = rdev_set_freq(rdev, freq, NL80211_CHAN_NO_HT); | |
667503dd | 105 | goto out; |
f2129354 JB |
106 | } |
107 | ||
59bbb6f7 | 108 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
667503dd JB |
109 | out: |
110 | wdev_unlock(wdev); | |
59bbb6f7 | 111 | mutex_unlock(&rdev->devlist_mtx); |
667503dd JB |
112 | cfg80211_unlock_rdev(rdev); |
113 | return err; | |
f2129354 | 114 | } |
f2129354 JB |
115 | |
116 | int cfg80211_mgd_wext_giwfreq(struct net_device *dev, | |
117 | struct iw_request_info *info, | |
118 | struct iw_freq *freq, char *extra) | |
119 | { | |
120 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
121 | struct ieee80211_channel *chan = NULL; | |
122 | ||
123 | /* call only for station! */ | |
124 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) | |
125 | return -EINVAL; | |
126 | ||
667503dd | 127 | wdev_lock(wdev); |
f2129354 | 128 | if (wdev->current_bss) |
19957bb3 | 129 | chan = wdev->current_bss->pub.channel; |
f2129354 JB |
130 | else if (wdev->wext.connect.channel) |
131 | chan = wdev->wext.connect.channel; | |
667503dd | 132 | wdev_unlock(wdev); |
f2129354 JB |
133 | |
134 | if (chan) { | |
135 | freq->m = chan->center_freq; | |
136 | freq->e = 6; | |
137 | return 0; | |
138 | } | |
139 | ||
140 | /* no channel if not joining */ | |
141 | return -EINVAL; | |
142 | } | |
f2129354 JB |
143 | |
144 | int cfg80211_mgd_wext_siwessid(struct net_device *dev, | |
145 | struct iw_request_info *info, | |
146 | struct iw_point *data, char *ssid) | |
147 | { | |
148 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
59bbb6f7 | 149 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
f2129354 JB |
150 | size_t len = data->length; |
151 | int err; | |
152 | ||
153 | /* call only for station! */ | |
154 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) | |
155 | return -EINVAL; | |
156 | ||
157 | if (!data->flags) | |
158 | len = 0; | |
159 | ||
160 | /* iwconfig uses nul termination in SSID.. */ | |
161 | if (len > 0 && ssid[len - 1] == '\0') | |
162 | len--; | |
163 | ||
59bbb6f7 JB |
164 | cfg80211_lock_rdev(rdev); |
165 | mutex_lock(&rdev->devlist_mtx); | |
667503dd JB |
166 | wdev_lock(wdev); |
167 | ||
168 | err = 0; | |
169 | ||
f2129354 JB |
170 | if (wdev->sme_state != CFG80211_SME_IDLE) { |
171 | bool event = true; | |
25e83c49 JB |
172 | |
173 | if (wdev->wext.connect.ssid && len && | |
174 | len == wdev->wext.connect.ssid_len && | |
175 | memcmp(wdev->wext.connect.ssid, ssid, len) == 0) | |
176 | goto out; | |
177 | ||
f2129354 JB |
178 | /* if SSID set now, we'll try to connect, avoid event */ |
179 | if (len) | |
180 | event = false; | |
59bbb6f7 JB |
181 | err = __cfg80211_disconnect(rdev, dev, |
182 | WLAN_REASON_DEAUTH_LEAVING, event); | |
f2129354 | 183 | if (err) |
667503dd | 184 | goto out; |
f2129354 JB |
185 | } |
186 | ||
187 | wdev->wext.connect.ssid = wdev->wext.ssid; | |
188 | memcpy(wdev->wext.ssid, ssid, len); | |
189 | wdev->wext.connect.ssid_len = len; | |
190 | ||
191 | wdev->wext.connect.crypto.control_port = false; | |
192 | ||
59bbb6f7 | 193 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
667503dd JB |
194 | out: |
195 | wdev_unlock(wdev); | |
59bbb6f7 JB |
196 | mutex_unlock(&rdev->devlist_mtx); |
197 | cfg80211_unlock_rdev(rdev); | |
667503dd | 198 | return err; |
f2129354 | 199 | } |
f2129354 JB |
200 | |
201 | int cfg80211_mgd_wext_giwessid(struct net_device *dev, | |
202 | struct iw_request_info *info, | |
203 | struct iw_point *data, char *ssid) | |
204 | { | |
205 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
206 | ||
207 | /* call only for station! */ | |
208 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) | |
209 | return -EINVAL; | |
210 | ||
211 | data->flags = 0; | |
212 | ||
667503dd | 213 | wdev_lock(wdev); |
a42dd7ef ZY |
214 | if (wdev->current_bss) { |
215 | const u8 *ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, | |
216 | WLAN_EID_SSID); | |
217 | if (ie) { | |
218 | data->flags = 1; | |
219 | data->length = ie[1]; | |
220 | memcpy(ssid, ie + 2, data->length); | |
221 | } | |
222 | } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) { | |
f2129354 JB |
223 | data->flags = 1; |
224 | data->length = wdev->wext.connect.ssid_len; | |
225 | memcpy(ssid, wdev->wext.connect.ssid, data->length); | |
226 | } else | |
227 | data->flags = 0; | |
667503dd | 228 | wdev_unlock(wdev); |
f2129354 JB |
229 | |
230 | return 0; | |
231 | } | |
f2129354 JB |
232 | |
233 | int cfg80211_mgd_wext_siwap(struct net_device *dev, | |
234 | struct iw_request_info *info, | |
235 | struct sockaddr *ap_addr, char *extra) | |
236 | { | |
237 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
59bbb6f7 | 238 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
f2129354 JB |
239 | u8 *bssid = ap_addr->sa_data; |
240 | int err; | |
241 | ||
242 | /* call only for station! */ | |
243 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) | |
244 | return -EINVAL; | |
245 | ||
246 | if (ap_addr->sa_family != ARPHRD_ETHER) | |
247 | return -EINVAL; | |
248 | ||
249 | /* automatic mode */ | |
250 | if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid)) | |
251 | bssid = NULL; | |
252 | ||
59bbb6f7 JB |
253 | cfg80211_lock_rdev(rdev); |
254 | mutex_lock(&rdev->devlist_mtx); | |
667503dd JB |
255 | wdev_lock(wdev); |
256 | ||
25e83c49 JB |
257 | if (wdev->sme_state != CFG80211_SME_IDLE) { |
258 | err = 0; | |
259 | /* both automatic */ | |
260 | if (!bssid && !wdev->wext.connect.bssid) | |
261 | goto out; | |
f2129354 | 262 | |
25e83c49 JB |
263 | /* fixed already - and no change */ |
264 | if (wdev->wext.connect.bssid && bssid && | |
265 | compare_ether_addr(bssid, wdev->wext.connect.bssid) == 0) | |
266 | goto out; | |
f2129354 | 267 | |
59bbb6f7 JB |
268 | err = __cfg80211_disconnect(rdev, dev, |
269 | WLAN_REASON_DEAUTH_LEAVING, false); | |
f2129354 | 270 | if (err) |
667503dd | 271 | goto out; |
f2129354 JB |
272 | } |
273 | ||
274 | if (bssid) { | |
275 | memcpy(wdev->wext.bssid, bssid, ETH_ALEN); | |
276 | wdev->wext.connect.bssid = wdev->wext.bssid; | |
277 | } else | |
278 | wdev->wext.connect.bssid = NULL; | |
279 | ||
59bbb6f7 | 280 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
667503dd JB |
281 | out: |
282 | wdev_unlock(wdev); | |
59bbb6f7 JB |
283 | mutex_unlock(&rdev->devlist_mtx); |
284 | cfg80211_unlock_rdev(rdev); | |
667503dd | 285 | return err; |
f2129354 | 286 | } |
f2129354 JB |
287 | |
288 | int cfg80211_mgd_wext_giwap(struct net_device *dev, | |
289 | struct iw_request_info *info, | |
290 | struct sockaddr *ap_addr, char *extra) | |
291 | { | |
292 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
293 | ||
294 | /* call only for station! */ | |
295 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) | |
296 | return -EINVAL; | |
297 | ||
298 | ap_addr->sa_family = ARPHRD_ETHER; | |
299 | ||
667503dd | 300 | wdev_lock(wdev); |
f2129354 | 301 | if (wdev->current_bss) |
19957bb3 | 302 | memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN); |
f2129354 JB |
303 | else if (wdev->wext.connect.bssid) |
304 | memcpy(ap_addr->sa_data, wdev->wext.connect.bssid, ETH_ALEN); | |
305 | else | |
306 | memset(ap_addr->sa_data, 0, ETH_ALEN); | |
667503dd | 307 | wdev_unlock(wdev); |
f2129354 JB |
308 | |
309 | return 0; | |
310 | } | |
f2129354 JB |
311 | |
312 | int cfg80211_wext_siwgenie(struct net_device *dev, | |
313 | struct iw_request_info *info, | |
314 | struct iw_point *data, char *extra) | |
315 | { | |
316 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
317 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
318 | u8 *ie = extra; | |
319 | int ie_len = data->length, err; | |
320 | ||
321 | if (wdev->iftype != NL80211_IFTYPE_STATION) | |
322 | return -EOPNOTSUPP; | |
323 | ||
324 | if (!ie_len) | |
325 | ie = NULL; | |
326 | ||
667503dd JB |
327 | wdev_lock(wdev); |
328 | ||
f2129354 | 329 | /* no change */ |
667503dd | 330 | err = 0; |
f2129354 JB |
331 | if (wdev->wext.ie_len == ie_len && |
332 | memcmp(wdev->wext.ie, ie, ie_len) == 0) | |
667503dd | 333 | goto out; |
f2129354 JB |
334 | |
335 | if (ie_len) { | |
336 | ie = kmemdup(extra, ie_len, GFP_KERNEL); | |
667503dd JB |
337 | if (!ie) { |
338 | err = -ENOMEM; | |
339 | goto out; | |
340 | } | |
f2129354 JB |
341 | } else |
342 | ie = NULL; | |
343 | ||
344 | kfree(wdev->wext.ie); | |
345 | wdev->wext.ie = ie; | |
346 | wdev->wext.ie_len = ie_len; | |
347 | ||
348 | if (wdev->sme_state != CFG80211_SME_IDLE) { | |
667503dd JB |
349 | err = __cfg80211_disconnect(rdev, dev, |
350 | WLAN_REASON_DEAUTH_LEAVING, false); | |
f2129354 | 351 | if (err) |
667503dd | 352 | goto out; |
f2129354 JB |
353 | } |
354 | ||
355 | /* userspace better not think we'll reconnect */ | |
667503dd JB |
356 | err = 0; |
357 | out: | |
358 | wdev_unlock(wdev); | |
359 | return err; | |
f2129354 JB |
360 | } |
361 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwgenie); | |
362 | ||
363 | int cfg80211_wext_siwmlme(struct net_device *dev, | |
364 | struct iw_request_info *info, | |
365 | struct iw_point *data, char *extra) | |
366 | { | |
367 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
368 | struct iw_mlme *mlme = (struct iw_mlme *)extra; | |
369 | struct cfg80211_registered_device *rdev; | |
667503dd | 370 | int err; |
f2129354 JB |
371 | |
372 | if (!wdev) | |
373 | return -EOPNOTSUPP; | |
374 | ||
375 | rdev = wiphy_to_dev(wdev->wiphy); | |
376 | ||
377 | if (wdev->iftype != NL80211_IFTYPE_STATION) | |
378 | return -EINVAL; | |
379 | ||
380 | if (mlme->addr.sa_family != ARPHRD_ETHER) | |
381 | return -EINVAL; | |
382 | ||
667503dd | 383 | wdev_lock(wdev); |
f2129354 JB |
384 | switch (mlme->cmd) { |
385 | case IW_MLME_DEAUTH: | |
386 | case IW_MLME_DISASSOC: | |
667503dd JB |
387 | err = __cfg80211_disconnect(rdev, dev, mlme->reason_code, |
388 | true); | |
389 | break; | |
f2129354 | 390 | default: |
667503dd JB |
391 | err = -EOPNOTSUPP; |
392 | break; | |
f2129354 | 393 | } |
667503dd JB |
394 | wdev_unlock(wdev); |
395 | ||
396 | return err; | |
f2129354 JB |
397 | } |
398 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme); |