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 if (wdev
->wext
.keys
) {
34 wdev
->wext
.keys
->def
= wdev
->wext
.default_key
;
35 wdev
->wext
.keys
->defmgmt
= wdev
->wext
.default_mgmt_key
;
36 if (wdev
->wext
.default_key
!= -1)
37 wdev
->wext
.connect
.privacy
= true;
40 if (!wdev
->wext
.connect
.ssid_len
)
43 if (wdev
->wext
.keys
) {
44 ck
= kmemdup(wdev
->wext
.keys
, sizeof(*ck
), GFP_KERNEL
);
47 for (i
= 0; i
< 6; i
++)
48 ck
->params
[i
].key
= ck
->data
[i
];
51 if (wdev
->wext
.prev_bssid_valid
)
52 prev_bssid
= wdev
->wext
.prev_bssid
;
54 err
= __cfg80211_connect(rdev
, wdev
->netdev
,
55 &wdev
->wext
.connect
, ck
, prev_bssid
);
62 int cfg80211_mgd_wext_siwfreq(struct net_device
*dev
,
63 struct iw_request_info
*info
,
64 struct iw_freq
*wextfreq
, char *extra
)
66 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
67 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
68 struct ieee80211_channel
*chan
= NULL
;
71 /* call only for station! */
72 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
75 freq
= cfg80211_wext_freq(wdev
->wiphy
, wextfreq
);
80 chan
= ieee80211_get_channel(wdev
->wiphy
, freq
);
83 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
87 cfg80211_lock_rdev(rdev
);
88 mutex_lock(&rdev
->devlist_mtx
);
91 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
94 if (wdev
->wext
.connect
.channel
== chan
) {
99 /* if SSID set, we'll try right again, avoid event */
100 if (wdev
->wext
.connect
.ssid_len
)
102 err
= __cfg80211_disconnect(rdev
, dev
,
103 WLAN_REASON_DEAUTH_LEAVING
, event
);
109 wdev
->wext
.connect
.channel
= chan
;
111 /* SSID is not set, we just want to switch channel */
112 if (chan
&& !wdev
->wext
.connect
.ssid_len
) {
113 err
= cfg80211_set_freq(rdev
, wdev
, freq
, NL80211_CHAN_NO_HT
);
117 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
120 mutex_unlock(&rdev
->devlist_mtx
);
121 cfg80211_unlock_rdev(rdev
);
125 int cfg80211_mgd_wext_giwfreq(struct net_device
*dev
,
126 struct iw_request_info
*info
,
127 struct iw_freq
*freq
, char *extra
)
129 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
130 struct ieee80211_channel
*chan
= NULL
;
132 /* call only for station! */
133 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
137 if (wdev
->current_bss
)
138 chan
= wdev
->current_bss
->pub
.channel
;
139 else if (wdev
->wext
.connect
.channel
)
140 chan
= wdev
->wext
.connect
.channel
;
144 freq
->m
= chan
->center_freq
;
149 /* no channel if not joining */
153 int cfg80211_mgd_wext_siwessid(struct net_device
*dev
,
154 struct iw_request_info
*info
,
155 struct iw_point
*data
, char *ssid
)
157 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
158 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
159 size_t len
= data
->length
;
162 /* call only for station! */
163 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
169 /* iwconfig uses nul termination in SSID.. */
170 if (len
> 0 && ssid
[len
- 1] == '\0')
173 cfg80211_lock_rdev(rdev
);
174 mutex_lock(&rdev
->devlist_mtx
);
179 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
182 if (wdev
->wext
.connect
.ssid
&& len
&&
183 len
== wdev
->wext
.connect
.ssid_len
&&
184 memcmp(wdev
->wext
.connect
.ssid
, ssid
, len
) == 0)
187 /* if SSID set now, we'll try to connect, avoid event */
190 err
= __cfg80211_disconnect(rdev
, dev
,
191 WLAN_REASON_DEAUTH_LEAVING
, event
);
196 wdev
->wext
.prev_bssid_valid
= false;
197 wdev
->wext
.connect
.ssid
= wdev
->wext
.ssid
;
198 memcpy(wdev
->wext
.ssid
, ssid
, len
);
199 wdev
->wext
.connect
.ssid_len
= len
;
201 wdev
->wext
.connect
.crypto
.control_port
= false;
202 wdev
->wext
.connect
.crypto
.control_port_ethertype
=
203 cpu_to_be16(ETH_P_PAE
);
205 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
208 mutex_unlock(&rdev
->devlist_mtx
);
209 cfg80211_unlock_rdev(rdev
);
213 int cfg80211_mgd_wext_giwessid(struct net_device
*dev
,
214 struct iw_request_info
*info
,
215 struct iw_point
*data
, char *ssid
)
217 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
219 /* call only for station! */
220 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
226 if (wdev
->current_bss
) {
227 const u8
*ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
231 data
->length
= ie
[1];
232 memcpy(ssid
, ie
+ 2, data
->length
);
234 } else if (wdev
->wext
.connect
.ssid
&& wdev
->wext
.connect
.ssid_len
) {
236 data
->length
= wdev
->wext
.connect
.ssid_len
;
237 memcpy(ssid
, wdev
->wext
.connect
.ssid
, data
->length
);
244 int cfg80211_mgd_wext_siwap(struct net_device
*dev
,
245 struct iw_request_info
*info
,
246 struct sockaddr
*ap_addr
, char *extra
)
248 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
249 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
250 u8
*bssid
= ap_addr
->sa_data
;
253 /* call only for station! */
254 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
257 if (ap_addr
->sa_family
!= ARPHRD_ETHER
)
261 if (is_zero_ether_addr(bssid
) || is_broadcast_ether_addr(bssid
))
264 cfg80211_lock_rdev(rdev
);
265 mutex_lock(&rdev
->devlist_mtx
);
268 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
271 if (!bssid
&& !wdev
->wext
.connect
.bssid
)
274 /* fixed already - and no change */
275 if (wdev
->wext
.connect
.bssid
&& bssid
&&
276 compare_ether_addr(bssid
, wdev
->wext
.connect
.bssid
) == 0)
279 err
= __cfg80211_disconnect(rdev
, dev
,
280 WLAN_REASON_DEAUTH_LEAVING
, false);
286 memcpy(wdev
->wext
.bssid
, bssid
, ETH_ALEN
);
287 wdev
->wext
.connect
.bssid
= wdev
->wext
.bssid
;
289 wdev
->wext
.connect
.bssid
= NULL
;
291 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
294 mutex_unlock(&rdev
->devlist_mtx
);
295 cfg80211_unlock_rdev(rdev
);
299 int cfg80211_mgd_wext_giwap(struct net_device
*dev
,
300 struct iw_request_info
*info
,
301 struct sockaddr
*ap_addr
, char *extra
)
303 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
305 /* call only for station! */
306 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
309 ap_addr
->sa_family
= ARPHRD_ETHER
;
312 if (wdev
->current_bss
)
313 memcpy(ap_addr
->sa_data
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
);
315 memset(ap_addr
->sa_data
, 0, ETH_ALEN
);
321 int cfg80211_wext_siwgenie(struct net_device
*dev
,
322 struct iw_request_info
*info
,
323 struct iw_point
*data
, char *extra
)
325 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
326 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
328 int ie_len
= data
->length
, err
;
330 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
340 if (wdev
->wext
.ie_len
== ie_len
&&
341 memcmp(wdev
->wext
.ie
, ie
, ie_len
) == 0)
345 ie
= kmemdup(extra
, ie_len
, GFP_KERNEL
);
353 kfree(wdev
->wext
.ie
);
355 wdev
->wext
.ie_len
= ie_len
;
357 if (wdev
->sme_state
!= CFG80211_SME_IDLE
) {
358 err
= __cfg80211_disconnect(rdev
, dev
,
359 WLAN_REASON_DEAUTH_LEAVING
, false);
364 /* userspace better not think we'll reconnect */
371 int cfg80211_wext_siwmlme(struct net_device
*dev
,
372 struct iw_request_info
*info
,
373 struct iw_point
*data
, char *extra
)
375 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
376 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
377 struct cfg80211_registered_device
*rdev
;
383 rdev
= wiphy_to_dev(wdev
->wiphy
);
385 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
388 if (mlme
->addr
.sa_family
!= ARPHRD_ETHER
)
394 case IW_MLME_DISASSOC
:
395 err
= __cfg80211_disconnect(rdev
, dev
, mlme
->reason_code
,