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/etherdevice.h>
9 #include <linux/if_arp.h>
10 #include <net/cfg80211.h>
11 #include "wext-compat.h"
14 int cfg80211_mgd_wext_connect(struct cfg80211_registered_device
*rdev
,
15 struct wireless_dev
*wdev
)
17 struct cfg80211_cached_keys
*ck
= NULL
;
18 const u8
*prev_bssid
= NULL
;
21 ASSERT_RDEV_LOCK(rdev
);
22 ASSERT_WDEV_LOCK(wdev
);
24 if (!netif_running(wdev
->netdev
))
27 wdev
->wext
.connect
.ie
= wdev
->wext
.ie
;
28 wdev
->wext
.connect
.ie_len
= wdev
->wext
.ie_len
;
29 wdev
->wext
.connect
.privacy
= wdev
->wext
.default_key
!= -1;
31 if (wdev
->wext
.keys
) {
32 wdev
->wext
.keys
->def
= wdev
->wext
.default_key
;
33 wdev
->wext
.keys
->defmgmt
= wdev
->wext
.default_mgmt_key
;
36 if (!wdev
->wext
.connect
.ssid_len
)
39 if (wdev
->wext
.keys
) {
40 ck
= kmemdup(wdev
->wext
.keys
, sizeof(*ck
), GFP_KERNEL
);
43 for (i
= 0; i
< 6; i
++)
44 ck
->params
[i
].key
= ck
->data
[i
];
47 if (wdev
->wext
.prev_bssid_valid
)
48 prev_bssid
= wdev
->wext
.prev_bssid
;
50 err
= __cfg80211_connect(rdev
, wdev
->netdev
,
51 &wdev
->wext
.connect
, ck
, prev_bssid
);
58 int cfg80211_mgd_wext_siwfreq(struct net_device
*dev
,
59 struct iw_request_info
*info
,
60 struct iw_freq
*wextfreq
, char *extra
)
62 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
63 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
64 struct ieee80211_channel
*chan
= NULL
;
67 /* call only for station! */
68 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
71 freq
= cfg80211_wext_freq(wdev
->wiphy
, wextfreq
);
76 chan
= ieee80211_get_channel(wdev
->wiphy
, freq
);
79 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
83 cfg80211_lock_rdev(rdev
);
84 mutex_lock(&rdev
->devlist_mtx
);
87 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
90 if (wdev
->wext
.connect
.channel
== chan
) {
95 /* if SSID set, we'll try right again, avoid event */
96 if (wdev
->wext
.connect
.ssid_len
)
98 err
= __cfg80211_disconnect(rdev
, dev
,
99 WLAN_REASON_DEAUTH_LEAVING
, event
);
105 wdev
->wext
.connect
.channel
= chan
;
107 /* SSID is not set, we just want to switch channel */
108 if (chan
&& !wdev
->wext
.connect
.ssid_len
) {
109 err
= rdev_set_freq(rdev
, wdev
, freq
, NL80211_CHAN_NO_HT
);
113 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
116 mutex_unlock(&rdev
->devlist_mtx
);
117 cfg80211_unlock_rdev(rdev
);
121 int cfg80211_mgd_wext_giwfreq(struct net_device
*dev
,
122 struct iw_request_info
*info
,
123 struct iw_freq
*freq
, char *extra
)
125 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
126 struct ieee80211_channel
*chan
= NULL
;
128 /* call only for station! */
129 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
133 if (wdev
->current_bss
)
134 chan
= wdev
->current_bss
->pub
.channel
;
135 else if (wdev
->wext
.connect
.channel
)
136 chan
= wdev
->wext
.connect
.channel
;
140 freq
->m
= chan
->center_freq
;
145 /* no channel if not joining */
149 int cfg80211_mgd_wext_siwessid(struct net_device
*dev
,
150 struct iw_request_info
*info
,
151 struct iw_point
*data
, char *ssid
)
153 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
154 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
155 size_t len
= data
->length
;
158 /* call only for station! */
159 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
165 /* iwconfig uses nul termination in SSID.. */
166 if (len
> 0 && ssid
[len
- 1] == '\0')
169 cfg80211_lock_rdev(rdev
);
170 mutex_lock(&rdev
->devlist_mtx
);
175 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
178 if (wdev
->wext
.connect
.ssid
&& len
&&
179 len
== wdev
->wext
.connect
.ssid_len
&&
180 memcmp(wdev
->wext
.connect
.ssid
, ssid
, len
) == 0)
183 /* if SSID set now, we'll try to connect, avoid event */
186 err
= __cfg80211_disconnect(rdev
, dev
,
187 WLAN_REASON_DEAUTH_LEAVING
, event
);
192 wdev
->wext
.prev_bssid_valid
= false;
193 wdev
->wext
.connect
.ssid
= wdev
->wext
.ssid
;
194 memcpy(wdev
->wext
.ssid
, ssid
, len
);
195 wdev
->wext
.connect
.ssid_len
= len
;
197 wdev
->wext
.connect
.crypto
.control_port
= false;
199 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
202 mutex_unlock(&rdev
->devlist_mtx
);
203 cfg80211_unlock_rdev(rdev
);
207 int cfg80211_mgd_wext_giwessid(struct net_device
*dev
,
208 struct iw_request_info
*info
,
209 struct iw_point
*data
, char *ssid
)
211 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
213 /* call only for station! */
214 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
220 if (wdev
->current_bss
) {
221 const u8
*ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
225 data
->length
= ie
[1];
226 memcpy(ssid
, ie
+ 2, data
->length
);
228 } else if (wdev
->wext
.connect
.ssid
&& wdev
->wext
.connect
.ssid_len
) {
230 data
->length
= wdev
->wext
.connect
.ssid_len
;
231 memcpy(ssid
, wdev
->wext
.connect
.ssid
, data
->length
);
239 int cfg80211_mgd_wext_siwap(struct net_device
*dev
,
240 struct iw_request_info
*info
,
241 struct sockaddr
*ap_addr
, char *extra
)
243 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
244 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
245 u8
*bssid
= ap_addr
->sa_data
;
248 /* call only for station! */
249 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
252 if (ap_addr
->sa_family
!= ARPHRD_ETHER
)
256 if (is_zero_ether_addr(bssid
) || is_broadcast_ether_addr(bssid
))
259 cfg80211_lock_rdev(rdev
);
260 mutex_lock(&rdev
->devlist_mtx
);
263 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
266 if (!bssid
&& !wdev
->wext
.connect
.bssid
)
269 /* fixed already - and no change */
270 if (wdev
->wext
.connect
.bssid
&& bssid
&&
271 compare_ether_addr(bssid
, wdev
->wext
.connect
.bssid
) == 0)
274 err
= __cfg80211_disconnect(rdev
, dev
,
275 WLAN_REASON_DEAUTH_LEAVING
, false);
281 memcpy(wdev
->wext
.bssid
, bssid
, ETH_ALEN
);
282 wdev
->wext
.connect
.bssid
= wdev
->wext
.bssid
;
284 wdev
->wext
.connect
.bssid
= NULL
;
286 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
289 mutex_unlock(&rdev
->devlist_mtx
);
290 cfg80211_unlock_rdev(rdev
);
294 int cfg80211_mgd_wext_giwap(struct net_device
*dev
,
295 struct iw_request_info
*info
,
296 struct sockaddr
*ap_addr
, char *extra
)
298 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
300 /* call only for station! */
301 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
304 ap_addr
->sa_family
= ARPHRD_ETHER
;
307 if (wdev
->current_bss
)
308 memcpy(ap_addr
->sa_data
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
);
309 else if (wdev
->wext
.connect
.bssid
)
310 memcpy(ap_addr
->sa_data
, wdev
->wext
.connect
.bssid
, ETH_ALEN
);
312 memset(ap_addr
->sa_data
, 0, ETH_ALEN
);
318 int cfg80211_wext_siwgenie(struct net_device
*dev
,
319 struct iw_request_info
*info
,
320 struct iw_point
*data
, char *extra
)
322 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
323 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
325 int ie_len
= data
->length
, err
;
327 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
337 if (wdev
->wext
.ie_len
== ie_len
&&
338 memcmp(wdev
->wext
.ie
, ie
, ie_len
) == 0)
342 ie
= kmemdup(extra
, ie_len
, GFP_KERNEL
);
350 kfree(wdev
->wext
.ie
);
352 wdev
->wext
.ie_len
= ie_len
;
354 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
355 err
= __cfg80211_disconnect(rdev
, dev
,
356 WLAN_REASON_DEAUTH_LEAVING
, false);
361 /* userspace better not think we'll reconnect */
367 EXPORT_SYMBOL_GPL(cfg80211_wext_siwgenie
);
369 int cfg80211_wext_siwmlme(struct net_device
*dev
,
370 struct iw_request_info
*info
,
371 struct iw_point
*data
, char *extra
)
373 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
374 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
375 struct cfg80211_registered_device
*rdev
;
381 rdev
= wiphy_to_dev(wdev
->wiphy
);
383 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
386 if (mlme
->addr
.sa_family
!= ARPHRD_ETHER
)
392 case IW_MLME_DISASSOC
:
393 err
= __cfg80211_disconnect(rdev
, dev
, mlme
->reason_code
,
404 EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme
);