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
);
94 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
97 if (wdev
->wext
.connect
.channel
== chan
) {
102 /* if SSID set, we'll try right again, avoid event */
103 if (wdev
->wext
.connect
.ssid_len
)
105 err
= __cfg80211_disconnect(rdev
, dev
,
106 WLAN_REASON_DEAUTH_LEAVING
, event
);
112 wdev
->wext
.connect
.channel
= chan
;
115 * SSID is not set, we just want to switch monitor channel,
116 * this is really just backward compatibility, if the SSID
117 * is set then we use the channel to select the BSS to use
118 * to connect to instead. If we were connected on another
119 * channel we disconnected above and reconnect below.
121 if (chan
&& !wdev
->wext
.connect
.ssid_len
) {
122 struct cfg80211_chan_def chandef
= {
123 .width
= NL80211_CHAN_WIDTH_20_NOHT
,
124 .center_freq1
= freq
,
127 chandef
.chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
129 err
= cfg80211_set_monitor_channel(rdev
, &chandef
);
135 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
138 mutex_unlock(&rdev
->devlist_mtx
);
139 cfg80211_unlock_rdev(rdev
);
143 int cfg80211_mgd_wext_giwfreq(struct net_device
*dev
,
144 struct iw_request_info
*info
,
145 struct iw_freq
*freq
, char *extra
)
147 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
148 struct ieee80211_channel
*chan
= NULL
;
150 /* call only for station! */
151 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
155 if (wdev
->current_bss
)
156 chan
= wdev
->current_bss
->pub
.channel
;
157 else if (wdev
->wext
.connect
.channel
)
158 chan
= wdev
->wext
.connect
.channel
;
162 freq
->m
= chan
->center_freq
;
167 /* no channel if not joining */
171 int cfg80211_mgd_wext_siwessid(struct net_device
*dev
,
172 struct iw_request_info
*info
,
173 struct iw_point
*data
, char *ssid
)
175 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
176 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
177 size_t len
= data
->length
;
180 /* call only for station! */
181 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
187 /* iwconfig uses nul termination in SSID.. */
188 if (len
> 0 && ssid
[len
- 1] == '\0')
191 cfg80211_lock_rdev(rdev
);
192 mutex_lock(&rdev
->devlist_mtx
);
197 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
200 if (wdev
->wext
.connect
.ssid
&& len
&&
201 len
== wdev
->wext
.connect
.ssid_len
&&
202 memcmp(wdev
->wext
.connect
.ssid
, ssid
, len
) == 0)
205 /* if SSID set now, we'll try to connect, avoid event */
208 err
= __cfg80211_disconnect(rdev
, dev
,
209 WLAN_REASON_DEAUTH_LEAVING
, event
);
214 wdev
->wext
.prev_bssid_valid
= false;
215 wdev
->wext
.connect
.ssid
= wdev
->wext
.ssid
;
216 memcpy(wdev
->wext
.ssid
, ssid
, len
);
217 wdev
->wext
.connect
.ssid_len
= len
;
219 wdev
->wext
.connect
.crypto
.control_port
= false;
220 wdev
->wext
.connect
.crypto
.control_port_ethertype
=
221 cpu_to_be16(ETH_P_PAE
);
223 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
226 mutex_unlock(&rdev
->devlist_mtx
);
227 cfg80211_unlock_rdev(rdev
);
231 int cfg80211_mgd_wext_giwessid(struct net_device
*dev
,
232 struct iw_request_info
*info
,
233 struct iw_point
*data
, char *ssid
)
235 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
237 /* call only for station! */
238 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
244 if (wdev
->current_bss
) {
248 ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
252 data
->length
= ie
[1];
253 memcpy(ssid
, ie
+ 2, data
->length
);
256 } else if (wdev
->wext
.connect
.ssid
&& wdev
->wext
.connect
.ssid_len
) {
258 data
->length
= wdev
->wext
.connect
.ssid_len
;
259 memcpy(ssid
, wdev
->wext
.connect
.ssid
, data
->length
);
266 int cfg80211_mgd_wext_siwap(struct net_device
*dev
,
267 struct iw_request_info
*info
,
268 struct sockaddr
*ap_addr
, char *extra
)
270 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
271 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
272 u8
*bssid
= ap_addr
->sa_data
;
275 /* call only for station! */
276 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
279 if (ap_addr
->sa_family
!= ARPHRD_ETHER
)
283 if (is_zero_ether_addr(bssid
) || is_broadcast_ether_addr(bssid
))
286 cfg80211_lock_rdev(rdev
);
287 mutex_lock(&rdev
->devlist_mtx
);
290 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
293 if (!bssid
&& !wdev
->wext
.connect
.bssid
)
296 /* fixed already - and no change */
297 if (wdev
->wext
.connect
.bssid
&& bssid
&&
298 ether_addr_equal(bssid
, wdev
->wext
.connect
.bssid
))
301 err
= __cfg80211_disconnect(rdev
, dev
,
302 WLAN_REASON_DEAUTH_LEAVING
, false);
308 memcpy(wdev
->wext
.bssid
, bssid
, ETH_ALEN
);
309 wdev
->wext
.connect
.bssid
= wdev
->wext
.bssid
;
311 wdev
->wext
.connect
.bssid
= NULL
;
313 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
316 mutex_unlock(&rdev
->devlist_mtx
);
317 cfg80211_unlock_rdev(rdev
);
321 int cfg80211_mgd_wext_giwap(struct net_device
*dev
,
322 struct iw_request_info
*info
,
323 struct sockaddr
*ap_addr
, char *extra
)
325 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
327 /* call only for station! */
328 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
331 ap_addr
->sa_family
= ARPHRD_ETHER
;
334 if (wdev
->current_bss
)
335 memcpy(ap_addr
->sa_data
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
);
337 memset(ap_addr
->sa_data
, 0, ETH_ALEN
);
343 int cfg80211_wext_siwgenie(struct net_device
*dev
,
344 struct iw_request_info
*info
,
345 struct iw_point
*data
, char *extra
)
347 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
348 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
350 int ie_len
= data
->length
, err
;
352 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
362 if (wdev
->wext
.ie_len
== ie_len
&&
363 memcmp(wdev
->wext
.ie
, ie
, ie_len
) == 0)
367 ie
= kmemdup(extra
, ie_len
, GFP_KERNEL
);
375 kfree(wdev
->wext
.ie
);
377 wdev
->wext
.ie_len
= ie_len
;
379 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
380 err
= __cfg80211_disconnect(rdev
, dev
,
381 WLAN_REASON_DEAUTH_LEAVING
, false);
386 /* userspace better not think we'll reconnect */
393 int cfg80211_wext_siwmlme(struct net_device
*dev
,
394 struct iw_request_info
*info
,
395 struct iw_point
*data
, char *extra
)
397 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
398 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
399 struct cfg80211_registered_device
*rdev
;
405 rdev
= wiphy_to_dev(wdev
->wiphy
);
407 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
410 if (mlme
->addr
.sa_family
!= ARPHRD_ETHER
)
416 case IW_MLME_DISASSOC
:
417 err
= __cfg80211_disconnect(rdev
, dev
, mlme
->reason_code
,