2 * cfg80211 wext compat for managed mode.
4 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright (C) 2009 Intel Corporation. All rights reserved.
8 #include <linux/export.h>
9 #include <linux/etherdevice.h>
10 #include <linux/if_arp.h>
11 #include <linux/slab.h>
12 #include <net/cfg80211.h>
13 #include <net/cfg80211-wext.h>
14 #include "wext-compat.h"
17 int cfg80211_mgd_wext_connect(struct cfg80211_registered_device
*rdev
,
18 struct wireless_dev
*wdev
)
20 struct cfg80211_cached_keys
*ck
= NULL
;
21 const u8
*prev_bssid
= NULL
;
24 ASSERT_RDEV_LOCK(rdev
);
25 ASSERT_WDEV_LOCK(wdev
);
27 if (!netif_running(wdev
->netdev
))
30 wdev
->wext
.connect
.ie
= wdev
->wext
.ie
;
31 wdev
->wext
.connect
.ie_len
= wdev
->wext
.ie_len
;
33 /* Use default background scan period */
34 wdev
->wext
.connect
.bg_scan_period
= -1;
36 if (wdev
->wext
.keys
) {
37 wdev
->wext
.keys
->def
= wdev
->wext
.default_key
;
38 wdev
->wext
.keys
->defmgmt
= wdev
->wext
.default_mgmt_key
;
39 if (wdev
->wext
.default_key
!= -1)
40 wdev
->wext
.connect
.privacy
= true;
43 if (!wdev
->wext
.connect
.ssid_len
)
46 if (wdev
->wext
.keys
) {
47 ck
= kmemdup(wdev
->wext
.keys
, sizeof(*ck
), GFP_KERNEL
);
50 for (i
= 0; i
< 6; i
++)
51 ck
->params
[i
].key
= ck
->data
[i
];
54 if (wdev
->wext
.prev_bssid_valid
)
55 prev_bssid
= wdev
->wext
.prev_bssid
;
57 err
= __cfg80211_connect(rdev
, wdev
->netdev
,
58 &wdev
->wext
.connect
, ck
, prev_bssid
);
65 int cfg80211_mgd_wext_siwfreq(struct net_device
*dev
,
66 struct iw_request_info
*info
,
67 struct iw_freq
*wextfreq
, char *extra
)
69 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
70 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
71 struct ieee80211_channel
*chan
= NULL
;
74 /* call only for station! */
75 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
78 freq
= cfg80211_wext_freq(wdev
->wiphy
, wextfreq
);
83 chan
= ieee80211_get_channel(wdev
->wiphy
, freq
);
86 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
90 cfg80211_lock_rdev(rdev
);
91 mutex_lock(&rdev
->devlist_mtx
);
92 mutex_lock(&rdev
->sched_scan_mtx
);
95 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
98 if (wdev
->wext
.connect
.channel
== chan
) {
103 /* if SSID set, we'll try right again, avoid event */
104 if (wdev
->wext
.connect
.ssid_len
)
106 err
= __cfg80211_disconnect(rdev
, dev
,
107 WLAN_REASON_DEAUTH_LEAVING
, event
);
113 wdev
->wext
.connect
.channel
= chan
;
116 * SSID is not set, we just want to switch monitor channel,
117 * this is really just backward compatibility, if the SSID
118 * is set then we use the channel to select the BSS to use
119 * to connect to instead. If we were connected on another
120 * channel we disconnected above and reconnect below.
122 if (chan
&& !wdev
->wext
.connect
.ssid_len
) {
123 struct cfg80211_chan_def chandef
= {
124 .width
= NL80211_CHAN_WIDTH_20_NOHT
,
125 .center_freq1
= freq
,
128 chandef
.chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
130 err
= cfg80211_set_monitor_channel(rdev
, &chandef
);
136 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
139 mutex_unlock(&rdev
->sched_scan_mtx
);
140 mutex_unlock(&rdev
->devlist_mtx
);
141 cfg80211_unlock_rdev(rdev
);
145 int cfg80211_mgd_wext_giwfreq(struct net_device
*dev
,
146 struct iw_request_info
*info
,
147 struct iw_freq
*freq
, char *extra
)
149 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
150 struct ieee80211_channel
*chan
= NULL
;
152 /* call only for station! */
153 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
157 if (wdev
->current_bss
)
158 chan
= wdev
->current_bss
->pub
.channel
;
159 else if (wdev
->wext
.connect
.channel
)
160 chan
= wdev
->wext
.connect
.channel
;
164 freq
->m
= chan
->center_freq
;
169 /* no channel if not joining */
173 int cfg80211_mgd_wext_siwessid(struct net_device
*dev
,
174 struct iw_request_info
*info
,
175 struct iw_point
*data
, char *ssid
)
177 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
178 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
179 size_t len
= data
->length
;
182 /* call only for station! */
183 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
189 /* iwconfig uses nul termination in SSID.. */
190 if (len
> 0 && ssid
[len
- 1] == '\0')
193 cfg80211_lock_rdev(rdev
);
194 mutex_lock(&rdev
->devlist_mtx
);
195 mutex_lock(&rdev
->sched_scan_mtx
);
200 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
203 if (wdev
->wext
.connect
.ssid
&& len
&&
204 len
== wdev
->wext
.connect
.ssid_len
&&
205 memcmp(wdev
->wext
.connect
.ssid
, ssid
, len
) == 0)
208 /* if SSID set now, we'll try to connect, avoid event */
211 err
= __cfg80211_disconnect(rdev
, dev
,
212 WLAN_REASON_DEAUTH_LEAVING
, event
);
217 wdev
->wext
.prev_bssid_valid
= false;
218 wdev
->wext
.connect
.ssid
= wdev
->wext
.ssid
;
219 memcpy(wdev
->wext
.ssid
, ssid
, len
);
220 wdev
->wext
.connect
.ssid_len
= len
;
222 wdev
->wext
.connect
.crypto
.control_port
= false;
223 wdev
->wext
.connect
.crypto
.control_port_ethertype
=
224 cpu_to_be16(ETH_P_PAE
);
226 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
229 mutex_unlock(&rdev
->sched_scan_mtx
);
230 mutex_unlock(&rdev
->devlist_mtx
);
231 cfg80211_unlock_rdev(rdev
);
235 int cfg80211_mgd_wext_giwessid(struct net_device
*dev
,
236 struct iw_request_info
*info
,
237 struct iw_point
*data
, char *ssid
)
239 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
241 /* call only for station! */
242 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
248 if (wdev
->current_bss
) {
252 ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
256 data
->length
= ie
[1];
257 memcpy(ssid
, ie
+ 2, data
->length
);
260 } else if (wdev
->wext
.connect
.ssid
&& wdev
->wext
.connect
.ssid_len
) {
262 data
->length
= wdev
->wext
.connect
.ssid_len
;
263 memcpy(ssid
, wdev
->wext
.connect
.ssid
, data
->length
);
270 int cfg80211_mgd_wext_siwap(struct net_device
*dev
,
271 struct iw_request_info
*info
,
272 struct sockaddr
*ap_addr
, char *extra
)
274 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
275 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
276 u8
*bssid
= ap_addr
->sa_data
;
279 /* call only for station! */
280 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
283 if (ap_addr
->sa_family
!= ARPHRD_ETHER
)
287 if (is_zero_ether_addr(bssid
) || is_broadcast_ether_addr(bssid
))
290 cfg80211_lock_rdev(rdev
);
291 mutex_lock(&rdev
->devlist_mtx
);
292 mutex_lock(&rdev
->sched_scan_mtx
);
295 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
298 if (!bssid
&& !wdev
->wext
.connect
.bssid
)
301 /* fixed already - and no change */
302 if (wdev
->wext
.connect
.bssid
&& bssid
&&
303 ether_addr_equal(bssid
, wdev
->wext
.connect
.bssid
))
306 err
= __cfg80211_disconnect(rdev
, dev
,
307 WLAN_REASON_DEAUTH_LEAVING
, false);
313 memcpy(wdev
->wext
.bssid
, bssid
, ETH_ALEN
);
314 wdev
->wext
.connect
.bssid
= wdev
->wext
.bssid
;
316 wdev
->wext
.connect
.bssid
= NULL
;
318 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
321 mutex_unlock(&rdev
->sched_scan_mtx
);
322 mutex_unlock(&rdev
->devlist_mtx
);
323 cfg80211_unlock_rdev(rdev
);
327 int cfg80211_mgd_wext_giwap(struct net_device
*dev
,
328 struct iw_request_info
*info
,
329 struct sockaddr
*ap_addr
, char *extra
)
331 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
333 /* call only for station! */
334 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
337 ap_addr
->sa_family
= ARPHRD_ETHER
;
340 if (wdev
->current_bss
)
341 memcpy(ap_addr
->sa_data
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
);
343 memset(ap_addr
->sa_data
, 0, ETH_ALEN
);
349 int cfg80211_wext_siwgenie(struct net_device
*dev
,
350 struct iw_request_info
*info
,
351 struct iw_point
*data
, char *extra
)
353 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
354 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
356 int ie_len
= data
->length
, err
;
358 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
368 if (wdev
->wext
.ie_len
== ie_len
&&
369 memcmp(wdev
->wext
.ie
, ie
, ie_len
) == 0)
373 ie
= kmemdup(extra
, ie_len
, GFP_KERNEL
);
381 kfree(wdev
->wext
.ie
);
383 wdev
->wext
.ie_len
= ie_len
;
385 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
386 err
= __cfg80211_disconnect(rdev
, dev
,
387 WLAN_REASON_DEAUTH_LEAVING
, false);
392 /* userspace better not think we'll reconnect */
399 int cfg80211_wext_siwmlme(struct net_device
*dev
,
400 struct iw_request_info
*info
,
401 struct iw_point
*data
, char *extra
)
403 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
404 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
405 struct cfg80211_registered_device
*rdev
;
411 rdev
= wiphy_to_dev(wdev
->wiphy
);
413 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
416 if (mlme
->addr
.sa_family
!= ARPHRD_ETHER
)
422 case IW_MLME_DISASSOC
:
423 err
= __cfg80211_disconnect(rdev
, dev
, mlme
->reason_code
,