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
;
114 /* SSID is not set, we just want to switch channel */
115 if (chan
&& !wdev
->wext
.connect
.ssid_len
) {
116 err
= cfg80211_set_freq(rdev
, wdev
, freq
, NL80211_CHAN_NO_HT
);
120 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
123 mutex_unlock(&rdev
->devlist_mtx
);
124 cfg80211_unlock_rdev(rdev
);
128 int cfg80211_mgd_wext_giwfreq(struct net_device
*dev
,
129 struct iw_request_info
*info
,
130 struct iw_freq
*freq
, char *extra
)
132 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
133 struct ieee80211_channel
*chan
= NULL
;
135 /* call only for station! */
136 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
140 if (wdev
->current_bss
)
141 chan
= wdev
->current_bss
->pub
.channel
;
142 else if (wdev
->wext
.connect
.channel
)
143 chan
= wdev
->wext
.connect
.channel
;
147 freq
->m
= chan
->center_freq
;
152 /* no channel if not joining */
156 int cfg80211_mgd_wext_siwessid(struct net_device
*dev
,
157 struct iw_request_info
*info
,
158 struct iw_point
*data
, char *ssid
)
160 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
161 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
162 size_t len
= data
->length
;
165 /* call only for station! */
166 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
172 /* iwconfig uses nul termination in SSID.. */
173 if (len
> 0 && ssid
[len
- 1] == '\0')
176 cfg80211_lock_rdev(rdev
);
177 mutex_lock(&rdev
->devlist_mtx
);
182 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
185 if (wdev
->wext
.connect
.ssid
&& len
&&
186 len
== wdev
->wext
.connect
.ssid_len
&&
187 memcmp(wdev
->wext
.connect
.ssid
, ssid
, len
) == 0)
190 /* if SSID set now, we'll try to connect, avoid event */
193 err
= __cfg80211_disconnect(rdev
, dev
,
194 WLAN_REASON_DEAUTH_LEAVING
, event
);
199 wdev
->wext
.prev_bssid_valid
= false;
200 wdev
->wext
.connect
.ssid
= wdev
->wext
.ssid
;
201 memcpy(wdev
->wext
.ssid
, ssid
, len
);
202 wdev
->wext
.connect
.ssid_len
= len
;
204 wdev
->wext
.connect
.crypto
.control_port
= false;
205 wdev
->wext
.connect
.crypto
.control_port_ethertype
=
206 cpu_to_be16(ETH_P_PAE
);
208 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
211 mutex_unlock(&rdev
->devlist_mtx
);
212 cfg80211_unlock_rdev(rdev
);
216 int cfg80211_mgd_wext_giwessid(struct net_device
*dev
,
217 struct iw_request_info
*info
,
218 struct iw_point
*data
, char *ssid
)
220 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
222 /* call only for station! */
223 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
229 if (wdev
->current_bss
) {
230 const u8
*ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
234 data
->length
= ie
[1];
235 memcpy(ssid
, ie
+ 2, data
->length
);
237 } else if (wdev
->wext
.connect
.ssid
&& wdev
->wext
.connect
.ssid_len
) {
239 data
->length
= wdev
->wext
.connect
.ssid_len
;
240 memcpy(ssid
, wdev
->wext
.connect
.ssid
, data
->length
);
247 int cfg80211_mgd_wext_siwap(struct net_device
*dev
,
248 struct iw_request_info
*info
,
249 struct sockaddr
*ap_addr
, char *extra
)
251 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
252 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
253 u8
*bssid
= ap_addr
->sa_data
;
256 /* call only for station! */
257 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
260 if (ap_addr
->sa_family
!= ARPHRD_ETHER
)
264 if (is_zero_ether_addr(bssid
) || is_broadcast_ether_addr(bssid
))
267 cfg80211_lock_rdev(rdev
);
268 mutex_lock(&rdev
->devlist_mtx
);
271 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
274 if (!bssid
&& !wdev
->wext
.connect
.bssid
)
277 /* fixed already - and no change */
278 if (wdev
->wext
.connect
.bssid
&& bssid
&&
279 ether_addr_equal(bssid
, wdev
->wext
.connect
.bssid
))
282 err
= __cfg80211_disconnect(rdev
, dev
,
283 WLAN_REASON_DEAUTH_LEAVING
, false);
289 memcpy(wdev
->wext
.bssid
, bssid
, ETH_ALEN
);
290 wdev
->wext
.connect
.bssid
= wdev
->wext
.bssid
;
292 wdev
->wext
.connect
.bssid
= NULL
;
294 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
297 mutex_unlock(&rdev
->devlist_mtx
);
298 cfg80211_unlock_rdev(rdev
);
302 int cfg80211_mgd_wext_giwap(struct net_device
*dev
,
303 struct iw_request_info
*info
,
304 struct sockaddr
*ap_addr
, char *extra
)
306 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
308 /* call only for station! */
309 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
312 ap_addr
->sa_family
= ARPHRD_ETHER
;
315 if (wdev
->current_bss
)
316 memcpy(ap_addr
->sa_data
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
);
318 memset(ap_addr
->sa_data
, 0, ETH_ALEN
);
324 int cfg80211_wext_siwgenie(struct net_device
*dev
,
325 struct iw_request_info
*info
,
326 struct iw_point
*data
, char *extra
)
328 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
329 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
331 int ie_len
= data
->length
, err
;
333 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
343 if (wdev
->wext
.ie_len
== ie_len
&&
344 memcmp(wdev
->wext
.ie
, ie
, ie_len
) == 0)
348 ie
= kmemdup(extra
, ie_len
, GFP_KERNEL
);
356 kfree(wdev
->wext
.ie
);
358 wdev
->wext
.ie_len
= ie_len
;
360 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
361 err
= __cfg80211_disconnect(rdev
, dev
,
362 WLAN_REASON_DEAUTH_LEAVING
, false);
367 /* userspace better not think we'll reconnect */
374 int cfg80211_wext_siwmlme(struct net_device
*dev
,
375 struct iw_request_info
*info
,
376 struct iw_point
*data
, char *extra
)
378 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
379 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
380 struct cfg80211_registered_device
*rdev
;
386 rdev
= wiphy_to_dev(wdev
->wiphy
);
388 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
391 if (mlme
->addr
.sa_family
!= ARPHRD_ETHER
)
397 case IW_MLME_DISASSOC
:
398 err
= __cfg80211_disconnect(rdev
, dev
, mlme
->reason_code
,