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 "wext-compat.h"
15 int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
16 struct wireless_dev *wdev)
18 struct cfg80211_cached_keys *ck = NULL;
19 const u8 *prev_bssid = NULL;
22 ASSERT_RDEV_LOCK(rdev);
23 ASSERT_WDEV_LOCK(wdev);
25 if (!netif_running(wdev->netdev))
28 wdev->wext.connect.ie = wdev->wext.ie;
29 wdev->wext.connect.ie_len = wdev->wext.ie_len;
31 if (wdev->wext.keys) {
32 wdev->wext.keys->def = wdev->wext.default_key;
33 wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key;
34 if (wdev->wext.default_key != -1)
35 wdev->wext.connect.privacy = true;
38 if (!wdev->wext.connect.ssid_len)
41 if (wdev->wext.keys) {
42 ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL);
45 for (i = 0; i < 6; i++)
46 ck->params[i].key = ck->data[i];
49 if (wdev->wext.prev_bssid_valid)
50 prev_bssid = wdev->wext.prev_bssid;
52 err = __cfg80211_connect(rdev, wdev->netdev,
53 &wdev->wext.connect, ck, prev_bssid);
60 int cfg80211_mgd_wext_siwfreq(struct net_device *dev,
61 struct iw_request_info *info,
62 struct iw_freq *wextfreq, char *extra)
64 struct wireless_dev *wdev = dev->ieee80211_ptr;
65 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
66 struct ieee80211_channel *chan = NULL;
69 /* call only for station! */
70 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
73 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
78 chan = ieee80211_get_channel(wdev->wiphy, freq);
81 if (chan->flags & IEEE80211_CHAN_DISABLED)
85 cfg80211_lock_rdev(rdev);
86 mutex_lock(&rdev->devlist_mtx);
89 if (wdev->sme_state != CFG80211_SME_IDLE) {
92 if (wdev->wext.connect.channel == chan) {
97 /* if SSID set, we'll try right again, avoid event */
98 if (wdev->wext.connect.ssid_len)
100 err = __cfg80211_disconnect(rdev, dev,
101 WLAN_REASON_DEAUTH_LEAVING, event);
107 wdev->wext.connect.channel = chan;
109 /* SSID is not set, we just want to switch channel */
110 if (chan && !wdev->wext.connect.ssid_len) {
111 err = cfg80211_set_freq(rdev, wdev, freq, NL80211_CHAN_NO_HT);
115 err = cfg80211_mgd_wext_connect(rdev, wdev);
118 mutex_unlock(&rdev->devlist_mtx);
119 cfg80211_unlock_rdev(rdev);
123 int cfg80211_mgd_wext_giwfreq(struct net_device *dev,
124 struct iw_request_info *info,
125 struct iw_freq *freq, char *extra)
127 struct wireless_dev *wdev = dev->ieee80211_ptr;
128 struct ieee80211_channel *chan = NULL;
130 /* call only for station! */
131 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
135 if (wdev->current_bss)
136 chan = wdev->current_bss->pub.channel;
137 else if (wdev->wext.connect.channel)
138 chan = wdev->wext.connect.channel;
142 freq->m = chan->center_freq;
147 /* no channel if not joining */
151 int cfg80211_mgd_wext_siwessid(struct net_device *dev,
152 struct iw_request_info *info,
153 struct iw_point *data, char *ssid)
155 struct wireless_dev *wdev = dev->ieee80211_ptr;
156 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
157 size_t len = data->length;
160 /* call only for station! */
161 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
167 /* iwconfig uses nul termination in SSID.. */
168 if (len > 0 && ssid[len - 1] == '\0')
171 cfg80211_lock_rdev(rdev);
172 mutex_lock(&rdev->devlist_mtx);
177 if (wdev->sme_state != CFG80211_SME_IDLE) {
180 if (wdev->wext.connect.ssid && len &&
181 len == wdev->wext.connect.ssid_len &&
182 memcmp(wdev->wext.connect.ssid, ssid, len) == 0)
185 /* if SSID set now, we'll try to connect, avoid event */
188 err = __cfg80211_disconnect(rdev, dev,
189 WLAN_REASON_DEAUTH_LEAVING, event);
194 wdev->wext.prev_bssid_valid = false;
195 wdev->wext.connect.ssid = wdev->wext.ssid;
196 memcpy(wdev->wext.ssid, ssid, len);
197 wdev->wext.connect.ssid_len = len;
199 wdev->wext.connect.crypto.control_port = false;
200 wdev->wext.connect.crypto.control_port_ethertype =
201 cpu_to_be16(ETH_P_PAE);
203 err = cfg80211_mgd_wext_connect(rdev, wdev);
206 mutex_unlock(&rdev->devlist_mtx);
207 cfg80211_unlock_rdev(rdev);
211 int cfg80211_mgd_wext_giwessid(struct net_device *dev,
212 struct iw_request_info *info,
213 struct iw_point *data, char *ssid)
215 struct wireless_dev *wdev = dev->ieee80211_ptr;
217 /* call only for station! */
218 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
224 if (wdev->current_bss) {
225 const u8 *ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
229 data->length = ie[1];
230 memcpy(ssid, ie + 2, data->length);
232 } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) {
234 data->length = wdev->wext.connect.ssid_len;
235 memcpy(ssid, wdev->wext.connect.ssid, data->length);
242 int cfg80211_mgd_wext_siwap(struct net_device *dev,
243 struct iw_request_info *info,
244 struct sockaddr *ap_addr, char *extra)
246 struct wireless_dev *wdev = dev->ieee80211_ptr;
247 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
248 u8 *bssid = ap_addr->sa_data;
251 /* call only for station! */
252 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
255 if (ap_addr->sa_family != ARPHRD_ETHER)
259 if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid))
262 cfg80211_lock_rdev(rdev);
263 mutex_lock(&rdev->devlist_mtx);
266 if (wdev->sme_state != CFG80211_SME_IDLE) {
269 if (!bssid && !wdev->wext.connect.bssid)
272 /* fixed already - and no change */
273 if (wdev->wext.connect.bssid && bssid &&
274 compare_ether_addr(bssid, wdev->wext.connect.bssid) == 0)
277 err = __cfg80211_disconnect(rdev, dev,
278 WLAN_REASON_DEAUTH_LEAVING, false);
284 memcpy(wdev->wext.bssid, bssid, ETH_ALEN);
285 wdev->wext.connect.bssid = wdev->wext.bssid;
287 wdev->wext.connect.bssid = NULL;
289 err = cfg80211_mgd_wext_connect(rdev, wdev);
292 mutex_unlock(&rdev->devlist_mtx);
293 cfg80211_unlock_rdev(rdev);
297 int cfg80211_mgd_wext_giwap(struct net_device *dev,
298 struct iw_request_info *info,
299 struct sockaddr *ap_addr, char *extra)
301 struct wireless_dev *wdev = dev->ieee80211_ptr;
303 /* call only for station! */
304 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
307 ap_addr->sa_family = ARPHRD_ETHER;
310 if (wdev->current_bss)
311 memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN);
313 memset(ap_addr->sa_data, 0, ETH_ALEN);
319 int cfg80211_wext_siwgenie(struct net_device *dev,
320 struct iw_request_info *info,
321 struct iw_point *data, char *extra)
323 struct wireless_dev *wdev = dev->ieee80211_ptr;
324 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
326 int ie_len = data->length, err;
328 if (wdev->iftype != NL80211_IFTYPE_STATION)
338 if (wdev->wext.ie_len == ie_len &&
339 memcmp(wdev->wext.ie, ie, ie_len) == 0)
343 ie = kmemdup(extra, ie_len, GFP_KERNEL);
351 kfree(wdev->wext.ie);
353 wdev->wext.ie_len = ie_len;
355 if (wdev->sme_state != CFG80211_SME_IDLE) {
356 err = __cfg80211_disconnect(rdev, dev,
357 WLAN_REASON_DEAUTH_LEAVING, false);
362 /* userspace better not think we'll reconnect */
368 EXPORT_SYMBOL_GPL(cfg80211_wext_siwgenie);
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,
405 EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme);