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
;
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 if (wdev
->wext
.default_key
!= -1)
39 wdev
->wext
.connect
.privacy
= true;
42 if (!wdev
->wext
.connect
.ssid_len
)
45 if (wdev
->wext
.keys
&& wdev
->wext
.keys
->def
!= -1) {
46 ck
= kmemdup(wdev
->wext
.keys
, sizeof(*ck
), GFP_KERNEL
);
49 for (i
= 0; i
< CFG80211_MAX_WEP_KEYS
; i
++)
50 ck
->params
[i
].key
= ck
->data
[i
];
53 if (wdev
->wext
.prev_bssid_valid
)
54 prev_bssid
= wdev
->wext
.prev_bssid
;
56 err
= cfg80211_connect(rdev
, wdev
->netdev
,
57 &wdev
->wext
.connect
, ck
, prev_bssid
);
64 int cfg80211_mgd_wext_siwfreq(struct net_device
*dev
,
65 struct iw_request_info
*info
,
66 struct iw_freq
*wextfreq
, char *extra
)
68 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
69 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
70 struct ieee80211_channel
*chan
= NULL
;
73 /* call only for station! */
74 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
77 freq
= cfg80211_wext_freq(wextfreq
);
82 chan
= ieee80211_get_channel(wdev
->wiphy
, freq
);
85 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
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
;
112 * SSID is not set, we just want to switch monitor channel,
113 * this is really just backward compatibility, if the SSID
114 * is set then we use the channel to select the BSS to use
115 * to connect to instead. If we were connected on another
116 * channel we disconnected above and reconnect below.
118 if (chan
&& !wdev
->wext
.connect
.ssid_len
) {
119 struct cfg80211_chan_def chandef
= {
120 .width
= NL80211_CHAN_WIDTH_20_NOHT
,
121 .center_freq1
= freq
,
124 chandef
.chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
126 err
= cfg80211_set_monitor_channel(rdev
, &chandef
);
132 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
138 int cfg80211_mgd_wext_giwfreq(struct net_device
*dev
,
139 struct iw_request_info
*info
,
140 struct iw_freq
*freq
, char *extra
)
142 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
143 struct ieee80211_channel
*chan
= NULL
;
145 /* call only for station! */
146 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
150 if (wdev
->current_bss
)
151 chan
= wdev
->current_bss
->pub
.channel
;
152 else if (wdev
->wext
.connect
.channel
)
153 chan
= wdev
->wext
.connect
.channel
;
157 freq
->m
= chan
->center_freq
;
162 /* no channel if not joining */
166 int cfg80211_mgd_wext_siwessid(struct net_device
*dev
,
167 struct iw_request_info
*info
,
168 struct iw_point
*data
, char *ssid
)
170 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
171 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
172 size_t len
= data
->length
;
175 /* call only for station! */
176 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
182 /* iwconfig uses nul termination in SSID.. */
183 if (len
> 0 && ssid
[len
- 1] == '\0')
193 if (wdev
->wext
.connect
.ssid
&& len
&&
194 len
== wdev
->wext
.connect
.ssid_len
&&
195 memcmp(wdev
->wext
.connect
.ssid
, ssid
, len
) == 0)
198 /* if SSID set now, we'll try to connect, avoid event */
201 err
= cfg80211_disconnect(rdev
, dev
,
202 WLAN_REASON_DEAUTH_LEAVING
, event
);
207 wdev
->wext
.prev_bssid_valid
= false;
208 wdev
->wext
.connect
.ssid
= wdev
->wext
.ssid
;
209 memcpy(wdev
->wext
.ssid
, ssid
, len
);
210 wdev
->wext
.connect
.ssid_len
= len
;
212 wdev
->wext
.connect
.crypto
.control_port
= false;
213 wdev
->wext
.connect
.crypto
.control_port_ethertype
=
214 cpu_to_be16(ETH_P_PAE
);
216 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
222 int cfg80211_mgd_wext_giwessid(struct net_device
*dev
,
223 struct iw_request_info
*info
,
224 struct iw_point
*data
, char *ssid
)
226 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
228 /* call only for station! */
229 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
235 if (wdev
->current_bss
) {
239 ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
243 data
->length
= ie
[1];
244 memcpy(ssid
, ie
+ 2, data
->length
);
247 } else if (wdev
->wext
.connect
.ssid
&& wdev
->wext
.connect
.ssid_len
) {
249 data
->length
= wdev
->wext
.connect
.ssid_len
;
250 memcpy(ssid
, wdev
->wext
.connect
.ssid
, data
->length
);
257 int cfg80211_mgd_wext_siwap(struct net_device
*dev
,
258 struct iw_request_info
*info
,
259 struct sockaddr
*ap_addr
, char *extra
)
261 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
262 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
263 u8
*bssid
= ap_addr
->sa_data
;
266 /* call only for station! */
267 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
270 if (ap_addr
->sa_family
!= ARPHRD_ETHER
)
274 if (is_zero_ether_addr(bssid
) || is_broadcast_ether_addr(bssid
))
282 if (!bssid
&& !wdev
->wext
.connect
.bssid
)
285 /* fixed already - and no change */
286 if (wdev
->wext
.connect
.bssid
&& bssid
&&
287 ether_addr_equal(bssid
, wdev
->wext
.connect
.bssid
))
290 err
= cfg80211_disconnect(rdev
, dev
,
291 WLAN_REASON_DEAUTH_LEAVING
, false);
297 memcpy(wdev
->wext
.bssid
, bssid
, ETH_ALEN
);
298 wdev
->wext
.connect
.bssid
= wdev
->wext
.bssid
;
300 wdev
->wext
.connect
.bssid
= NULL
;
302 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
308 int cfg80211_mgd_wext_giwap(struct net_device
*dev
,
309 struct iw_request_info
*info
,
310 struct sockaddr
*ap_addr
, char *extra
)
312 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
314 /* call only for station! */
315 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
318 ap_addr
->sa_family
= ARPHRD_ETHER
;
321 if (wdev
->current_bss
)
322 memcpy(ap_addr
->sa_data
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
);
324 eth_zero_addr(ap_addr
->sa_data
);
330 int cfg80211_wext_siwgenie(struct net_device
*dev
,
331 struct iw_request_info
*info
,
332 struct iw_point
*data
, char *extra
)
334 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
335 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
337 int ie_len
= data
->length
, err
;
339 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
349 if (wdev
->wext
.ie_len
== ie_len
&&
350 memcmp(wdev
->wext
.ie
, ie
, ie_len
) == 0)
354 ie
= kmemdup(extra
, ie_len
, GFP_KERNEL
);
362 kfree(wdev
->wext
.ie
);
364 wdev
->wext
.ie_len
= ie_len
;
367 err
= cfg80211_disconnect(rdev
, dev
,
368 WLAN_REASON_DEAUTH_LEAVING
, false);
373 /* userspace better not think we'll reconnect */
380 int cfg80211_wext_siwmlme(struct net_device
*dev
,
381 struct iw_request_info
*info
,
382 struct iw_point
*data
, char *extra
)
384 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
385 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
386 struct cfg80211_registered_device
*rdev
;
392 rdev
= wiphy_to_rdev(wdev
->wiphy
);
394 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
397 if (mlme
->addr
.sa_family
!= ARPHRD_ETHER
)
403 case IW_MLME_DISASSOC
:
404 err
= cfg80211_disconnect(rdev
, dev
, mlme
->reason_code
, true);