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