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 /* 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 wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key;
39 if (wdev->wext.default_key != -1)
40 wdev->wext.connect.privacy = true;
43 if (!wdev->wext.connect.ssid_len)
46 if (wdev->wext.keys) {
47 ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL);
50 for (i = 0; i < 6; i++)
51 ck->params[i].key = ck->data[i];
54 if (wdev->wext.prev_bssid_valid)
55 prev_bssid = wdev->wext.prev_bssid;
57 err = cfg80211_connect(rdev, wdev->netdev,
58 &wdev->wext.connect, ck, prev_bssid);
65 int cfg80211_mgd_wext_siwfreq(struct net_device *dev,
66 struct iw_request_info *info,
67 struct iw_freq *wextfreq, char *extra)
69 struct wireless_dev *wdev = dev->ieee80211_ptr;
70 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
71 struct ieee80211_channel *chan = NULL;
74 /* call only for station! */
75 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
78 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
83 chan = ieee80211_get_channel(wdev->wiphy, freq);
86 if (chan->flags & IEEE80211_CHAN_DISABLED)
95 if (wdev->wext.connect.channel == chan) {
100 /* if SSID set, we'll try right again, avoid event */
101 if (wdev->wext.connect.ssid_len)
103 err = cfg80211_disconnect(rdev, dev,
104 WLAN_REASON_DEAUTH_LEAVING, event);
110 wdev->wext.connect.channel = chan;
113 * SSID is not set, we just want to switch monitor channel,
114 * this is really just backward compatibility, if the SSID
115 * is set then we use the channel to select the BSS to use
116 * to connect to instead. If we were connected on another
117 * channel we disconnected above and reconnect below.
119 if (chan && !wdev->wext.connect.ssid_len) {
120 struct cfg80211_chan_def chandef = {
121 .width = NL80211_CHAN_WIDTH_20_NOHT,
122 .center_freq1 = freq,
125 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
127 err = cfg80211_set_monitor_channel(rdev, &chandef);
133 err = cfg80211_mgd_wext_connect(rdev, wdev);
139 int cfg80211_mgd_wext_giwfreq(struct net_device *dev,
140 struct iw_request_info *info,
141 struct iw_freq *freq, char *extra)
143 struct wireless_dev *wdev = dev->ieee80211_ptr;
144 struct ieee80211_channel *chan = NULL;
146 /* call only for station! */
147 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
151 if (wdev->current_bss)
152 chan = wdev->current_bss->pub.channel;
153 else if (wdev->wext.connect.channel)
154 chan = wdev->wext.connect.channel;
158 freq->m = chan->center_freq;
163 /* no channel if not joining */
167 int cfg80211_mgd_wext_siwessid(struct net_device *dev,
168 struct iw_request_info *info,
169 struct iw_point *data, char *ssid)
171 struct wireless_dev *wdev = dev->ieee80211_ptr;
172 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
173 size_t len = data->length;
176 /* call only for station! */
177 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
183 /* iwconfig uses nul termination in SSID.. */
184 if (len > 0 && ssid[len - 1] == '\0')
194 if (wdev->wext.connect.ssid && len &&
195 len == wdev->wext.connect.ssid_len &&
196 memcmp(wdev->wext.connect.ssid, ssid, len) == 0)
199 /* if SSID set now, we'll try to connect, avoid event */
202 err = cfg80211_disconnect(rdev, dev,
203 WLAN_REASON_DEAUTH_LEAVING, event);
208 wdev->wext.prev_bssid_valid = false;
209 wdev->wext.connect.ssid = wdev->wext.ssid;
210 memcpy(wdev->wext.ssid, ssid, len);
211 wdev->wext.connect.ssid_len = len;
213 wdev->wext.connect.crypto.control_port = false;
214 wdev->wext.connect.crypto.control_port_ethertype =
215 cpu_to_be16(ETH_P_PAE);
217 err = cfg80211_mgd_wext_connect(rdev, wdev);
223 int cfg80211_mgd_wext_giwessid(struct net_device *dev,
224 struct iw_request_info *info,
225 struct iw_point *data, char *ssid)
227 struct wireless_dev *wdev = dev->ieee80211_ptr;
229 /* call only for station! */
230 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
236 if (wdev->current_bss) {
240 ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
244 data->length = ie[1];
245 memcpy(ssid, ie + 2, data->length);
248 } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) {
250 data->length = wdev->wext.connect.ssid_len;
251 memcpy(ssid, wdev->wext.connect.ssid, data->length);
258 int cfg80211_mgd_wext_siwap(struct net_device *dev,
259 struct iw_request_info *info,
260 struct sockaddr *ap_addr, char *extra)
262 struct wireless_dev *wdev = dev->ieee80211_ptr;
263 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
264 u8 *bssid = ap_addr->sa_data;
267 /* call only for station! */
268 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
271 if (ap_addr->sa_family != ARPHRD_ETHER)
275 if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid))
283 if (!bssid && !wdev->wext.connect.bssid)
286 /* fixed already - and no change */
287 if (wdev->wext.connect.bssid && bssid &&
288 ether_addr_equal(bssid, wdev->wext.connect.bssid))
291 err = cfg80211_disconnect(rdev, dev,
292 WLAN_REASON_DEAUTH_LEAVING, false);
298 memcpy(wdev->wext.bssid, bssid, ETH_ALEN);
299 wdev->wext.connect.bssid = wdev->wext.bssid;
301 wdev->wext.connect.bssid = NULL;
303 err = cfg80211_mgd_wext_connect(rdev, wdev);
309 int cfg80211_mgd_wext_giwap(struct net_device *dev,
310 struct iw_request_info *info,
311 struct sockaddr *ap_addr, char *extra)
313 struct wireless_dev *wdev = dev->ieee80211_ptr;
315 /* call only for station! */
316 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
319 ap_addr->sa_family = ARPHRD_ETHER;
322 if (wdev->current_bss)
323 memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN);
325 memset(ap_addr->sa_data, 0, ETH_ALEN);
331 int cfg80211_wext_siwgenie(struct net_device *dev,
332 struct iw_request_info *info,
333 struct iw_point *data, char *extra)
335 struct wireless_dev *wdev = dev->ieee80211_ptr;
336 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
338 int ie_len = data->length, err;
340 if (wdev->iftype != NL80211_IFTYPE_STATION)
350 if (wdev->wext.ie_len == ie_len &&
351 memcmp(wdev->wext.ie, ie, ie_len) == 0)
355 ie = kmemdup(extra, ie_len, GFP_KERNEL);
363 kfree(wdev->wext.ie);
365 wdev->wext.ie_len = ie_len;
368 err = cfg80211_disconnect(rdev, dev,
369 WLAN_REASON_DEAUTH_LEAVING, false);
374 /* userspace better not think we'll reconnect */
381 int cfg80211_wext_siwmlme(struct net_device *dev,
382 struct iw_request_info *info,
383 struct iw_point *data, char *extra)
385 struct wireless_dev *wdev = dev->ieee80211_ptr;
386 struct iw_mlme *mlme = (struct iw_mlme *)extra;
387 struct cfg80211_registered_device *rdev;
393 rdev = wiphy_to_dev(wdev->wiphy);
395 if (wdev->iftype != NL80211_IFTYPE_STATION)
398 if (mlme->addr.sa_family != ARPHRD_ETHER)
404 case IW_MLME_DISASSOC:
405 err = cfg80211_disconnect(rdev, dev, mlme->reason_code, true);