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 <linux/slab.h>
11 #include <net/cfg80211.h>
12 #include <net/cfg80211-wext.h>
13 #include "wext-compat.h"
16 int cfg80211_mgd_wext_connect(struct cfg80211_registered_device
*rdev
,
17 struct wireless_dev
*wdev
)
19 struct cfg80211_cached_keys
*ck
= NULL
;
20 const u8
*prev_bssid
= NULL
;
23 ASSERT_RDEV_LOCK(rdev
);
24 ASSERT_WDEV_LOCK(wdev
);
26 if (!netif_running(wdev
->netdev
))
29 wdev
->wext
.connect
.ie
= wdev
->wext
.ie
;
30 wdev
->wext
.connect
.ie_len
= wdev
->wext
.ie_len
;
32 if (wdev
->wext
.keys
) {
33 wdev
->wext
.keys
->def
= wdev
->wext
.default_key
;
34 wdev
->wext
.keys
->defmgmt
= wdev
->wext
.default_mgmt_key
;
35 if (wdev
->wext
.default_key
!= -1)
36 wdev
->wext
.connect
.privacy
= true;
39 if (!wdev
->wext
.connect
.ssid_len
)
42 if (wdev
->wext
.keys
) {
43 ck
= kmemdup(wdev
->wext
.keys
, sizeof(*ck
), GFP_KERNEL
);
46 for (i
= 0; i
< 6; i
++)
47 ck
->params
[i
].key
= ck
->data
[i
];
50 if (wdev
->wext
.prev_bssid_valid
)
51 prev_bssid
= wdev
->wext
.prev_bssid
;
53 err
= __cfg80211_connect(rdev
, wdev
->netdev
,
54 &wdev
->wext
.connect
, ck
, prev_bssid
);
61 int cfg80211_mgd_wext_siwfreq(struct net_device
*dev
,
62 struct iw_request_info
*info
,
63 struct iw_freq
*wextfreq
, char *extra
)
65 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
66 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
67 struct ieee80211_channel
*chan
= NULL
;
70 /* call only for station! */
71 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
74 freq
= cfg80211_wext_freq(wdev
->wiphy
, wextfreq
);
79 chan
= ieee80211_get_channel(wdev
->wiphy
, freq
);
82 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
86 cfg80211_lock_rdev(rdev
);
87 mutex_lock(&rdev
->devlist_mtx
);
90 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
93 if (wdev
->wext
.connect
.channel
== chan
) {
98 /* if SSID set, we'll try right again, avoid event */
99 if (wdev
->wext
.connect
.ssid_len
)
101 err
= __cfg80211_disconnect(rdev
, dev
,
102 WLAN_REASON_DEAUTH_LEAVING
, event
);
108 wdev
->wext
.connect
.channel
= chan
;
110 /* SSID is not set, we just want to switch channel */
111 if (chan
&& !wdev
->wext
.connect
.ssid_len
) {
112 err
= cfg80211_set_freq(rdev
, wdev
, freq
, NL80211_CHAN_NO_HT
);
116 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
119 mutex_unlock(&rdev
->devlist_mtx
);
120 cfg80211_unlock_rdev(rdev
);
124 int cfg80211_mgd_wext_giwfreq(struct net_device
*dev
,
125 struct iw_request_info
*info
,
126 struct iw_freq
*freq
, char *extra
)
128 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
129 struct ieee80211_channel
*chan
= NULL
;
131 /* call only for station! */
132 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
136 if (wdev
->current_bss
)
137 chan
= wdev
->current_bss
->pub
.channel
;
138 else if (wdev
->wext
.connect
.channel
)
139 chan
= wdev
->wext
.connect
.channel
;
143 freq
->m
= chan
->center_freq
;
148 /* no channel if not joining */
152 int cfg80211_mgd_wext_siwessid(struct net_device
*dev
,
153 struct iw_request_info
*info
,
154 struct iw_point
*data
, char *ssid
)
156 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
157 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
158 size_t len
= data
->length
;
161 /* call only for station! */
162 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
168 /* iwconfig uses nul termination in SSID.. */
169 if (len
> 0 && ssid
[len
- 1] == '\0')
172 cfg80211_lock_rdev(rdev
);
173 mutex_lock(&rdev
->devlist_mtx
);
178 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
181 if (wdev
->wext
.connect
.ssid
&& len
&&
182 len
== wdev
->wext
.connect
.ssid_len
&&
183 memcmp(wdev
->wext
.connect
.ssid
, ssid
, len
) == 0)
186 /* if SSID set now, we'll try to connect, avoid event */
189 err
= __cfg80211_disconnect(rdev
, dev
,
190 WLAN_REASON_DEAUTH_LEAVING
, event
);
195 wdev
->wext
.prev_bssid_valid
= false;
196 wdev
->wext
.connect
.ssid
= wdev
->wext
.ssid
;
197 memcpy(wdev
->wext
.ssid
, ssid
, len
);
198 wdev
->wext
.connect
.ssid_len
= len
;
200 wdev
->wext
.connect
.crypto
.control_port
= false;
201 wdev
->wext
.connect
.crypto
.control_port_ethertype
=
202 cpu_to_be16(ETH_P_PAE
);
204 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
207 mutex_unlock(&rdev
->devlist_mtx
);
208 cfg80211_unlock_rdev(rdev
);
212 int cfg80211_mgd_wext_giwessid(struct net_device
*dev
,
213 struct iw_request_info
*info
,
214 struct iw_point
*data
, char *ssid
)
216 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
218 /* call only for station! */
219 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
225 if (wdev
->current_bss
) {
226 const u8
*ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
230 data
->length
= ie
[1];
231 memcpy(ssid
, ie
+ 2, data
->length
);
233 } else if (wdev
->wext
.connect
.ssid
&& wdev
->wext
.connect
.ssid_len
) {
235 data
->length
= wdev
->wext
.connect
.ssid_len
;
236 memcpy(ssid
, wdev
->wext
.connect
.ssid
, data
->length
);
243 int cfg80211_mgd_wext_siwap(struct net_device
*dev
,
244 struct iw_request_info
*info
,
245 struct sockaddr
*ap_addr
, char *extra
)
247 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
248 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
249 u8
*bssid
= ap_addr
->sa_data
;
252 /* call only for station! */
253 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
256 if (ap_addr
->sa_family
!= ARPHRD_ETHER
)
260 if (is_zero_ether_addr(bssid
) || is_broadcast_ether_addr(bssid
))
263 cfg80211_lock_rdev(rdev
);
264 mutex_lock(&rdev
->devlist_mtx
);
267 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
270 if (!bssid
&& !wdev
->wext
.connect
.bssid
)
273 /* fixed already - and no change */
274 if (wdev
->wext
.connect
.bssid
&& bssid
&&
275 compare_ether_addr(bssid
, wdev
->wext
.connect
.bssid
) == 0)
278 err
= __cfg80211_disconnect(rdev
, dev
,
279 WLAN_REASON_DEAUTH_LEAVING
, false);
285 memcpy(wdev
->wext
.bssid
, bssid
, ETH_ALEN
);
286 wdev
->wext
.connect
.bssid
= wdev
->wext
.bssid
;
288 wdev
->wext
.connect
.bssid
= NULL
;
290 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
293 mutex_unlock(&rdev
->devlist_mtx
);
294 cfg80211_unlock_rdev(rdev
);
298 int cfg80211_mgd_wext_giwap(struct net_device
*dev
,
299 struct iw_request_info
*info
,
300 struct sockaddr
*ap_addr
, char *extra
)
302 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
304 /* call only for station! */
305 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
308 ap_addr
->sa_family
= ARPHRD_ETHER
;
311 if (wdev
->current_bss
)
312 memcpy(ap_addr
->sa_data
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
);
314 memset(ap_addr
->sa_data
, 0, ETH_ALEN
);
320 int cfg80211_wext_siwgenie(struct net_device
*dev
,
321 struct iw_request_info
*info
,
322 struct iw_point
*data
, char *extra
)
324 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
325 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
327 int ie_len
= data
->length
, err
;
329 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
339 if (wdev
->wext
.ie_len
== ie_len
&&
340 memcmp(wdev
->wext
.ie
, ie
, ie_len
) == 0)
344 ie
= kmemdup(extra
, ie_len
, GFP_KERNEL
);
352 kfree(wdev
->wext
.ie
);
354 wdev
->wext
.ie_len
= ie_len
;
356 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
357 err
= __cfg80211_disconnect(rdev
, dev
,
358 WLAN_REASON_DEAUTH_LEAVING
, false);
363 /* userspace better not think we'll reconnect */
370 int cfg80211_wext_siwmlme(struct net_device
*dev
,
371 struct iw_request_info
*info
,
372 struct iw_point
*data
, char *extra
)
374 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
375 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
376 struct cfg80211_registered_device
*rdev
;
382 rdev
= wiphy_to_dev(wdev
->wiphy
);
384 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
387 if (mlme
->addr
.sa_family
!= ARPHRD_ETHER
)
393 case IW_MLME_DISASSOC
:
394 err
= __cfg80211_disconnect(rdev
, dev
, mlme
->reason_code
,