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
);
108 wdev
->wext
.connect
.channel
= chan
;
109 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
115 int cfg80211_mgd_wext_giwfreq(struct net_device
*dev
,
116 struct iw_request_info
*info
,
117 struct iw_freq
*freq
, char *extra
)
119 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
120 struct ieee80211_channel
*chan
= NULL
;
122 /* call only for station! */
123 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
127 if (wdev
->current_bss
)
128 chan
= wdev
->current_bss
->pub
.channel
;
129 else if (wdev
->wext
.connect
.channel
)
130 chan
= wdev
->wext
.connect
.channel
;
134 freq
->m
= chan
->center_freq
;
139 /* no channel if not joining */
143 int cfg80211_mgd_wext_siwessid(struct net_device
*dev
,
144 struct iw_request_info
*info
,
145 struct iw_point
*data
, char *ssid
)
147 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
148 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
149 size_t len
= data
->length
;
152 /* call only for station! */
153 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
159 /* iwconfig uses nul termination in SSID.. */
160 if (len
> 0 && ssid
[len
- 1] == '\0')
170 if (wdev
->wext
.connect
.ssid
&& len
&&
171 len
== wdev
->wext
.connect
.ssid_len
&&
172 memcmp(wdev
->wext
.connect
.ssid
, ssid
, len
) == 0)
175 /* if SSID set now, we'll try to connect, avoid event */
178 err
= cfg80211_disconnect(rdev
, dev
,
179 WLAN_REASON_DEAUTH_LEAVING
, event
);
184 wdev
->wext
.prev_bssid_valid
= false;
185 wdev
->wext
.connect
.ssid
= wdev
->wext
.ssid
;
186 memcpy(wdev
->wext
.ssid
, ssid
, len
);
187 wdev
->wext
.connect
.ssid_len
= len
;
189 wdev
->wext
.connect
.crypto
.control_port
= false;
190 wdev
->wext
.connect
.crypto
.control_port_ethertype
=
191 cpu_to_be16(ETH_P_PAE
);
193 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
199 int cfg80211_mgd_wext_giwessid(struct net_device
*dev
,
200 struct iw_request_info
*info
,
201 struct iw_point
*data
, char *ssid
)
203 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
205 /* call only for station! */
206 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
212 if (wdev
->current_bss
) {
216 ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
220 data
->length
= ie
[1];
221 memcpy(ssid
, ie
+ 2, data
->length
);
224 } else if (wdev
->wext
.connect
.ssid
&& wdev
->wext
.connect
.ssid_len
) {
226 data
->length
= wdev
->wext
.connect
.ssid_len
;
227 memcpy(ssid
, wdev
->wext
.connect
.ssid
, data
->length
);
234 int cfg80211_mgd_wext_siwap(struct net_device
*dev
,
235 struct iw_request_info
*info
,
236 struct sockaddr
*ap_addr
, char *extra
)
238 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
239 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
240 u8
*bssid
= ap_addr
->sa_data
;
243 /* call only for station! */
244 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
247 if (ap_addr
->sa_family
!= ARPHRD_ETHER
)
251 if (is_zero_ether_addr(bssid
) || is_broadcast_ether_addr(bssid
))
259 if (!bssid
&& !wdev
->wext
.connect
.bssid
)
262 /* fixed already - and no change */
263 if (wdev
->wext
.connect
.bssid
&& bssid
&&
264 ether_addr_equal(bssid
, wdev
->wext
.connect
.bssid
))
267 err
= cfg80211_disconnect(rdev
, dev
,
268 WLAN_REASON_DEAUTH_LEAVING
, false);
274 memcpy(wdev
->wext
.bssid
, bssid
, ETH_ALEN
);
275 wdev
->wext
.connect
.bssid
= wdev
->wext
.bssid
;
277 wdev
->wext
.connect
.bssid
= NULL
;
279 err
= cfg80211_mgd_wext_connect(rdev
, wdev
);
285 int cfg80211_mgd_wext_giwap(struct net_device
*dev
,
286 struct iw_request_info
*info
,
287 struct sockaddr
*ap_addr
, char *extra
)
289 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
291 /* call only for station! */
292 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
295 ap_addr
->sa_family
= ARPHRD_ETHER
;
298 if (wdev
->current_bss
)
299 memcpy(ap_addr
->sa_data
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
);
301 eth_zero_addr(ap_addr
->sa_data
);
307 int cfg80211_wext_siwgenie(struct net_device
*dev
,
308 struct iw_request_info
*info
,
309 struct iw_point
*data
, char *extra
)
311 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
312 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
314 int ie_len
= data
->length
, err
;
316 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
326 if (wdev
->wext
.ie_len
== ie_len
&&
327 memcmp(wdev
->wext
.ie
, ie
, ie_len
) == 0)
331 ie
= kmemdup(extra
, ie_len
, GFP_KERNEL
);
339 kfree(wdev
->wext
.ie
);
341 wdev
->wext
.ie_len
= ie_len
;
344 err
= cfg80211_disconnect(rdev
, dev
,
345 WLAN_REASON_DEAUTH_LEAVING
, false);
350 /* userspace better not think we'll reconnect */
357 int cfg80211_wext_siwmlme(struct net_device
*dev
,
358 struct iw_request_info
*info
,
359 struct iw_point
*data
, char *extra
)
361 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
362 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
363 struct cfg80211_registered_device
*rdev
;
369 rdev
= wiphy_to_rdev(wdev
->wiphy
);
371 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
)
374 if (mlme
->addr
.sa_family
!= ARPHRD_ETHER
)
380 case IW_MLME_DISASSOC
:
381 err
= cfg80211_disconnect(rdev
, dev
, mlme
->reason_code
, true);