Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1 | /* |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 2 | * SME code for cfg80211 |
| 3 | * both driver SME event handling and the SME implementation |
| 4 | * (for nl80211's connect() and wext) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5 | * |
| 6 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 7 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/etherdevice.h> |
| 11 | #include <linux/if_arp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13 | #include <linux/workqueue.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 14 | #include <linux/wireless.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 15 | #include <linux/export.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 16 | #include <net/iw_handler.h> |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 17 | #include <net/cfg80211.h> |
| 18 | #include <net/rtnetlink.h> |
| 19 | #include "nl80211.h" |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 20 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 21 | #include "rdev-ops.h" |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 22 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 23 | /* |
| 24 | * Software SME in cfg80211, using auth/assoc/deauth calls to the |
| 25 | * driver. This is is for implementing nl80211's connect/disconnect |
| 26 | * and wireless extensions (if configured.) |
| 27 | */ |
| 28 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 29 | struct cfg80211_conn { |
| 30 | struct cfg80211_connect_params params; |
| 31 | /* these are sub-states of the _CONNECTING sme_state */ |
| 32 | enum { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 33 | CFG80211_CONN_SCANNING, |
| 34 | CFG80211_CONN_SCAN_AGAIN, |
| 35 | CFG80211_CONN_AUTHENTICATE_NEXT, |
| 36 | CFG80211_CONN_AUTHENTICATING, |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 37 | CFG80211_CONN_AUTH_FAILED, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 38 | CFG80211_CONN_ASSOCIATE_NEXT, |
| 39 | CFG80211_CONN_ASSOCIATING, |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 40 | CFG80211_CONN_ASSOC_FAILED, |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 41 | CFG80211_CONN_DEAUTH, |
Johannes Berg | 1976c76 | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 42 | CFG80211_CONN_ABANDON, |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 43 | CFG80211_CONN_CONNECTED, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 44 | } state; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 45 | u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN]; |
Johannes Berg | 46b9d18 | 2015-03-31 16:09:13 +0200 | [diff] [blame] | 46 | const u8 *ie; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 47 | size_t ie_len; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 48 | bool auto_auth, prev_bssid_valid; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 51 | static void cfg80211_sme_free(struct wireless_dev *wdev) |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 52 | { |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 53 | if (!wdev->conn) |
| 54 | return; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 55 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 56 | kfree(wdev->conn->ie); |
| 57 | kfree(wdev->conn); |
| 58 | wdev->conn = NULL; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 61 | static int cfg80211_conn_scan(struct wireless_dev *wdev) |
| 62 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 63 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 64 | struct cfg80211_scan_request *request; |
| 65 | int n_channels, err; |
| 66 | |
| 67 | ASSERT_RTNL(); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 68 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 69 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 70 | if (rdev->scan_req || rdev->scan_msg) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 71 | return -EBUSY; |
| 72 | |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 73 | if (wdev->conn->params.channel) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 74 | n_channels = 1; |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 75 | else |
| 76 | n_channels = ieee80211_get_num_supported_channels(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 77 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 78 | request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) + |
| 79 | sizeof(request->channels[0]) * n_channels, |
| 80 | GFP_KERNEL); |
| 81 | if (!request) |
| 82 | return -ENOMEM; |
| 83 | |
Karl Beldan | 2a84ee8 | 2014-10-07 11:42:18 +0200 | [diff] [blame] | 84 | if (wdev->conn->params.channel) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 85 | enum nl80211_band band = wdev->conn->params.channel->band; |
Karl Beldan | 2a84ee8 | 2014-10-07 11:42:18 +0200 | [diff] [blame] | 86 | struct ieee80211_supported_band *sband = |
| 87 | wdev->wiphy->bands[band]; |
| 88 | |
| 89 | if (!sband) { |
| 90 | kfree(request); |
| 91 | return -EINVAL; |
| 92 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 93 | request->channels[0] = wdev->conn->params.channel; |
Karl Beldan | 2a84ee8 | 2014-10-07 11:42:18 +0200 | [diff] [blame] | 94 | request->rates[band] = (1 << sband->n_bitrates) - 1; |
| 95 | } else { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 96 | int i = 0, j; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 97 | enum nl80211_band band; |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 98 | struct ieee80211_supported_band *bands; |
| 99 | struct ieee80211_channel *channel; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 100 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 101 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 102 | bands = wdev->wiphy->bands[band]; |
| 103 | if (!bands) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 104 | continue; |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 105 | for (j = 0; j < bands->n_channels; j++) { |
| 106 | channel = &bands->channels[j]; |
| 107 | if (channel->flags & IEEE80211_CHAN_DISABLED) |
| 108 | continue; |
| 109 | request->channels[i++] = channel; |
| 110 | } |
| 111 | request->rates[band] = (1 << bands->n_bitrates) - 1; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 112 | } |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 113 | n_channels = i; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 114 | } |
| 115 | request->n_channels = n_channels; |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 116 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 117 | request->n_ssids = 1; |
| 118 | |
| 119 | memcpy(request->ssids[0].ssid, wdev->conn->params.ssid, |
| 120 | wdev->conn->params.ssid_len); |
| 121 | request->ssids[0].ssid_len = wdev->conn->params.ssid_len; |
| 122 | |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 123 | eth_broadcast_addr(request->bssid); |
| 124 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 125 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 126 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 127 | request->scan_start = jiffies; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 128 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 129 | rdev->scan_req = request; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 130 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 131 | err = rdev_scan(rdev, request); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 132 | if (!err) { |
| 133 | wdev->conn->state = CFG80211_CONN_SCANNING; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 134 | nl80211_send_scan_start(rdev, wdev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 135 | dev_hold(wdev->netdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 136 | } else { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 137 | rdev->scan_req = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 138 | kfree(request); |
| 139 | } |
| 140 | return err; |
| 141 | } |
| 142 | |
| 143 | static int cfg80211_conn_do_work(struct wireless_dev *wdev) |
| 144 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 145 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 146 | struct cfg80211_connect_params *params; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 147 | struct cfg80211_assoc_request req = {}; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 148 | int err; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 149 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 150 | ASSERT_WDEV_LOCK(wdev); |
| 151 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 152 | if (!wdev->conn) |
| 153 | return 0; |
| 154 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 155 | params = &wdev->conn->params; |
| 156 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 157 | switch (wdev->conn->state) { |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 158 | case CFG80211_CONN_SCANNING: |
| 159 | /* didn't find it during scan ... */ |
| 160 | return -ENOENT; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 161 | case CFG80211_CONN_SCAN_AGAIN: |
| 162 | return cfg80211_conn_scan(wdev); |
| 163 | case CFG80211_CONN_AUTHENTICATE_NEXT: |
Johannes Berg | 2fd0511 | 2014-04-29 17:52:36 +0200 | [diff] [blame] | 164 | if (WARN_ON(!rdev->ops->auth)) |
| 165 | return -EOPNOTSUPP; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 166 | wdev->conn->state = CFG80211_CONN_AUTHENTICATING; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 167 | return cfg80211_mlme_auth(rdev, wdev->netdev, |
| 168 | params->channel, params->auth_type, |
| 169 | params->bssid, |
| 170 | params->ssid, params->ssid_len, |
| 171 | NULL, 0, |
| 172 | params->key, params->key_len, |
| 173 | params->key_idx, NULL, 0); |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 174 | case CFG80211_CONN_AUTH_FAILED: |
| 175 | return -ENOTCONN; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 176 | case CFG80211_CONN_ASSOCIATE_NEXT: |
Johannes Berg | 2fd0511 | 2014-04-29 17:52:36 +0200 | [diff] [blame] | 177 | if (WARN_ON(!rdev->ops->assoc)) |
| 178 | return -EOPNOTSUPP; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 179 | wdev->conn->state = CFG80211_CONN_ASSOCIATING; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 180 | if (wdev->conn->prev_bssid_valid) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 181 | req.prev_bssid = wdev->conn->prev_bssid; |
| 182 | req.ie = params->ie; |
| 183 | req.ie_len = params->ie_len; |
| 184 | req.use_mfp = params->mfp != NL80211_MFP_NO; |
| 185 | req.crypto = params->crypto; |
| 186 | req.flags = params->flags; |
| 187 | req.ht_capa = params->ht_capa; |
| 188 | req.ht_capa_mask = params->ht_capa_mask; |
| 189 | req.vht_capa = params->vht_capa; |
| 190 | req.vht_capa_mask = params->vht_capa_mask; |
| 191 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 192 | err = cfg80211_mlme_assoc(rdev, wdev->netdev, params->channel, |
| 193 | params->bssid, params->ssid, |
| 194 | params->ssid_len, &req); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 195 | if (err) |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 196 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
| 197 | NULL, 0, |
| 198 | WLAN_REASON_DEAUTH_LEAVING, |
| 199 | false); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 200 | return err; |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 201 | case CFG80211_CONN_ASSOC_FAILED: |
| 202 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
| 203 | NULL, 0, |
| 204 | WLAN_REASON_DEAUTH_LEAVING, false); |
| 205 | return -ENOTCONN; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 206 | case CFG80211_CONN_DEAUTH: |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 207 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
| 208 | NULL, 0, |
| 209 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | 1976c76 | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 210 | /* fall through */ |
| 211 | case CFG80211_CONN_ABANDON: |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 212 | /* free directly, disconnected event already sent */ |
| 213 | cfg80211_sme_free(wdev); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 214 | return 0; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 215 | default: |
| 216 | return 0; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | void cfg80211_conn_work(struct work_struct *work) |
| 221 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 222 | struct cfg80211_registered_device *rdev = |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 223 | container_of(work, struct cfg80211_registered_device, conn_work); |
| 224 | struct wireless_dev *wdev; |
Johannes Berg | 7400f42 | 2009-10-31 07:40:37 +0100 | [diff] [blame] | 225 | u8 bssid_buf[ETH_ALEN], *bssid = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 226 | |
| 227 | rtnl_lock(); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 228 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 229 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | c815797 | 2013-05-23 18:10:21 +0200 | [diff] [blame] | 230 | if (!wdev->netdev) |
| 231 | continue; |
| 232 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 233 | wdev_lock(wdev); |
| 234 | if (!netif_running(wdev->netdev)) { |
| 235 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 236 | continue; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 237 | } |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 238 | if (!wdev->conn || |
| 239 | wdev->conn->state == CFG80211_CONN_CONNECTED) { |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 240 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 241 | continue; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 242 | } |
Johannes Berg | 7400f42 | 2009-10-31 07:40:37 +0100 | [diff] [blame] | 243 | if (wdev->conn->params.bssid) { |
| 244 | memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN); |
| 245 | bssid = bssid_buf; |
| 246 | } |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 247 | if (cfg80211_conn_do_work(wdev)) { |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 248 | __cfg80211_connect_result( |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 249 | wdev->netdev, bssid, |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 250 | NULL, 0, NULL, 0, -1, false, NULL); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 251 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 252 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 255 | rtnl_unlock(); |
| 256 | } |
| 257 | |
Ben Greear | 0e3a39b | 2013-06-19 14:06:27 -0700 | [diff] [blame] | 258 | /* Returned bss is reference counted and must be cleaned up appropriately. */ |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 259 | static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 260 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 261 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 262 | struct cfg80211_bss *bss; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 263 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 264 | ASSERT_WDEV_LOCK(wdev); |
| 265 | |
Jouni Malinen | ed9d010 | 2011-05-16 19:40:15 +0300 | [diff] [blame] | 266 | bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel, |
| 267 | wdev->conn->params.bssid, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 268 | wdev->conn->params.ssid, |
| 269 | wdev->conn->params.ssid_len, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 270 | wdev->conn_bss_type, |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 271 | IEEE80211_PRIVACY(wdev->conn->params.privacy)); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 272 | if (!bss) |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 273 | return NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 274 | |
| 275 | memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN); |
| 276 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 277 | wdev->conn->params.channel = bss->channel; |
| 278 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 279 | schedule_work(&rdev->conn_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 280 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 281 | return bss; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 282 | } |
| 283 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 284 | static void __cfg80211_sme_scan_done(struct net_device *dev) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 285 | { |
| 286 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 287 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 288 | struct cfg80211_bss *bss; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 289 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 290 | ASSERT_WDEV_LOCK(wdev); |
| 291 | |
Zhu Yi | d4b1a68 | 2009-07-16 17:34:14 +0800 | [diff] [blame] | 292 | if (!wdev->conn) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 293 | return; |
| 294 | |
| 295 | if (wdev->conn->state != CFG80211_CONN_SCANNING && |
| 296 | wdev->conn->state != CFG80211_CONN_SCAN_AGAIN) |
| 297 | return; |
| 298 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 299 | bss = cfg80211_get_conn_bss(wdev); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 300 | if (bss) |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 301 | cfg80211_put_bss(&rdev->wiphy, bss); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 302 | else |
| 303 | schedule_work(&rdev->conn_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 304 | } |
| 305 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 306 | void cfg80211_sme_scan_done(struct net_device *dev) |
| 307 | { |
| 308 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 309 | |
| 310 | wdev_lock(wdev); |
| 311 | __cfg80211_sme_scan_done(dev); |
| 312 | wdev_unlock(wdev); |
| 313 | } |
| 314 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 315 | void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 316 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 317 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 318 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 319 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 320 | u16 status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 321 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 322 | ASSERT_WDEV_LOCK(wdev); |
| 323 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 324 | if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 325 | return; |
| 326 | |
| 327 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG && |
| 328 | wdev->conn->auto_auth && |
| 329 | wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) { |
| 330 | /* select automatically between only open, shared, leap */ |
| 331 | switch (wdev->conn->params.auth_type) { |
| 332 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 333 | if (wdev->connect_keys) |
| 334 | wdev->conn->params.auth_type = |
| 335 | NL80211_AUTHTYPE_SHARED_KEY; |
| 336 | else |
| 337 | wdev->conn->params.auth_type = |
| 338 | NL80211_AUTHTYPE_NETWORK_EAP; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 339 | break; |
| 340 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 341 | wdev->conn->params.auth_type = |
| 342 | NL80211_AUTHTYPE_NETWORK_EAP; |
| 343 | break; |
| 344 | default: |
| 345 | /* huh? */ |
| 346 | wdev->conn->params.auth_type = |
| 347 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 348 | break; |
| 349 | } |
| 350 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 351 | schedule_work(&rdev->conn_work); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 352 | } else if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 353 | __cfg80211_connect_result(wdev->netdev, mgmt->bssid, |
| 354 | NULL, 0, NULL, 0, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 355 | status_code, false, NULL); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 356 | } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 357 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 358 | schedule_work(&rdev->conn_work); |
| 359 | } |
| 360 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 361 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 362 | bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status) |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 363 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 364 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 365 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 366 | if (!wdev->conn) |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 367 | return false; |
| 368 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 369 | if (status == WLAN_STATUS_SUCCESS) { |
| 370 | wdev->conn->state = CFG80211_CONN_CONNECTED; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 371 | return false; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | if (wdev->conn->prev_bssid_valid) { |
| 375 | /* |
| 376 | * Some stupid APs don't accept reassoc, so we |
| 377 | * need to fall back to trying regular assoc; |
| 378 | * return true so no event is sent to userspace. |
| 379 | */ |
| 380 | wdev->conn->prev_bssid_valid = false; |
| 381 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 382 | schedule_work(&rdev->conn_work); |
| 383 | return true; |
| 384 | } |
| 385 | |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 386 | wdev->conn->state = CFG80211_CONN_ASSOC_FAILED; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 387 | schedule_work(&rdev->conn_work); |
| 388 | return false; |
| 389 | } |
| 390 | |
| 391 | void cfg80211_sme_deauth(struct wireless_dev *wdev) |
| 392 | { |
| 393 | cfg80211_sme_free(wdev); |
| 394 | } |
| 395 | |
| 396 | void cfg80211_sme_auth_timeout(struct wireless_dev *wdev) |
| 397 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 398 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 399 | |
| 400 | if (!wdev->conn) |
| 401 | return; |
| 402 | |
| 403 | wdev->conn->state = CFG80211_CONN_AUTH_FAILED; |
| 404 | schedule_work(&rdev->conn_work); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void cfg80211_sme_disassoc(struct wireless_dev *wdev) |
| 408 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 409 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 410 | |
| 411 | if (!wdev->conn) |
| 412 | return; |
| 413 | |
| 414 | wdev->conn->state = CFG80211_CONN_DEAUTH; |
| 415 | schedule_work(&rdev->conn_work); |
| 416 | } |
| 417 | |
| 418 | void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev) |
| 419 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 420 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 421 | |
| 422 | if (!wdev->conn) |
| 423 | return; |
| 424 | |
| 425 | wdev->conn->state = CFG80211_CONN_ASSOC_FAILED; |
| 426 | schedule_work(&rdev->conn_work); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 427 | } |
| 428 | |
Johannes Berg | 1976c76 | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 429 | void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev) |
| 430 | { |
| 431 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 432 | |
| 433 | if (!wdev->conn) |
| 434 | return; |
| 435 | |
| 436 | wdev->conn->state = CFG80211_CONN_ABANDON; |
| 437 | schedule_work(&rdev->conn_work); |
| 438 | } |
| 439 | |
Johannes Berg | 46b9d18 | 2015-03-31 16:09:13 +0200 | [diff] [blame] | 440 | static int cfg80211_sme_get_conn_ies(struct wireless_dev *wdev, |
| 441 | const u8 *ies, size_t ies_len, |
| 442 | const u8 **out_ies, size_t *out_ies_len) |
| 443 | { |
| 444 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 445 | u8 *buf; |
| 446 | size_t offs; |
| 447 | |
| 448 | if (!rdev->wiphy.extended_capabilities_len || |
| 449 | (ies && cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, ies, ies_len))) { |
| 450 | *out_ies = kmemdup(ies, ies_len, GFP_KERNEL); |
| 451 | if (!*out_ies) |
| 452 | return -ENOMEM; |
| 453 | *out_ies_len = ies_len; |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | buf = kmalloc(ies_len + rdev->wiphy.extended_capabilities_len + 2, |
| 458 | GFP_KERNEL); |
| 459 | if (!buf) |
| 460 | return -ENOMEM; |
| 461 | |
| 462 | if (ies_len) { |
| 463 | static const u8 before_extcapa[] = { |
| 464 | /* not listing IEs expected to be created by driver */ |
| 465 | WLAN_EID_RSN, |
| 466 | WLAN_EID_QOS_CAPA, |
| 467 | WLAN_EID_RRM_ENABLED_CAPABILITIES, |
| 468 | WLAN_EID_MOBILITY_DOMAIN, |
| 469 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 470 | WLAN_EID_BSS_COEX_2040, |
| 471 | }; |
| 472 | |
| 473 | offs = ieee80211_ie_split(ies, ies_len, before_extcapa, |
| 474 | ARRAY_SIZE(before_extcapa), 0); |
| 475 | memcpy(buf, ies, offs); |
| 476 | /* leave a whole for extended capabilities IE */ |
| 477 | memcpy(buf + offs + rdev->wiphy.extended_capabilities_len + 2, |
| 478 | ies + offs, ies_len - offs); |
| 479 | } else { |
| 480 | offs = 0; |
| 481 | } |
| 482 | |
| 483 | /* place extended capabilities IE (with only driver capabilities) */ |
| 484 | buf[offs] = WLAN_EID_EXT_CAPABILITY; |
| 485 | buf[offs + 1] = rdev->wiphy.extended_capabilities_len; |
| 486 | memcpy(buf + offs + 2, |
| 487 | rdev->wiphy.extended_capabilities, |
| 488 | rdev->wiphy.extended_capabilities_len); |
| 489 | |
| 490 | *out_ies = buf; |
| 491 | *out_ies_len = ies_len + rdev->wiphy.extended_capabilities_len + 2; |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 496 | static int cfg80211_sme_connect(struct wireless_dev *wdev, |
| 497 | struct cfg80211_connect_params *connect, |
| 498 | const u8 *prev_bssid) |
| 499 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 500 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 501 | struct cfg80211_bss *bss; |
| 502 | int err; |
| 503 | |
| 504 | if (!rdev->ops->auth || !rdev->ops->assoc) |
| 505 | return -EOPNOTSUPP; |
| 506 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 507 | if (wdev->current_bss) { |
| 508 | if (!prev_bssid) |
| 509 | return -EALREADY; |
| 510 | if (prev_bssid && |
| 511 | !ether_addr_equal(prev_bssid, wdev->current_bss->pub.bssid)) |
| 512 | return -ENOTCONN; |
| 513 | cfg80211_unhold_bss(wdev->current_bss); |
| 514 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
| 515 | wdev->current_bss = NULL; |
| 516 | |
| 517 | cfg80211_sme_free(wdev); |
| 518 | } |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 519 | |
| 520 | if (WARN_ON(wdev->conn)) |
| 521 | return -EINPROGRESS; |
| 522 | |
| 523 | wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL); |
| 524 | if (!wdev->conn) |
| 525 | return -ENOMEM; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 526 | |
| 527 | /* |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 528 | * Copy all parameters, and treat explicitly IEs, BSSID, SSID. |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 529 | */ |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 530 | memcpy(&wdev->conn->params, connect, sizeof(*connect)); |
| 531 | if (connect->bssid) { |
| 532 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 533 | memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN); |
| 534 | } |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 535 | |
Johannes Berg | 46b9d18 | 2015-03-31 16:09:13 +0200 | [diff] [blame] | 536 | if (cfg80211_sme_get_conn_ies(wdev, connect->ie, connect->ie_len, |
| 537 | &wdev->conn->ie, |
| 538 | &wdev->conn->params.ie_len)) { |
| 539 | kfree(wdev->conn); |
| 540 | wdev->conn = NULL; |
| 541 | return -ENOMEM; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 542 | } |
Johannes Berg | 46b9d18 | 2015-03-31 16:09:13 +0200 | [diff] [blame] | 543 | wdev->conn->params.ie = wdev->conn->ie; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 544 | |
| 545 | if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) { |
| 546 | wdev->conn->auto_auth = true; |
| 547 | /* start with open system ... should mostly work */ |
| 548 | wdev->conn->params.auth_type = |
| 549 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 550 | } else { |
| 551 | wdev->conn->auto_auth = false; |
| 552 | } |
| 553 | |
| 554 | wdev->conn->params.ssid = wdev->ssid; |
Zhao, Gang | babd3a2 | 2014-03-19 23:02:21 +0800 | [diff] [blame] | 555 | wdev->conn->params.ssid_len = wdev->ssid_len; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 556 | |
| 557 | /* see if we have the bss already */ |
| 558 | bss = cfg80211_get_conn_bss(wdev); |
| 559 | |
| 560 | if (prev_bssid) { |
| 561 | memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN); |
| 562 | wdev->conn->prev_bssid_valid = true; |
| 563 | } |
| 564 | |
| 565 | /* we're good if we have a matching bss struct */ |
| 566 | if (bss) { |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 567 | err = cfg80211_conn_do_work(wdev); |
| 568 | cfg80211_put_bss(wdev->wiphy, bss); |
| 569 | } else { |
| 570 | /* otherwise we'll need to scan for the AP first */ |
| 571 | err = cfg80211_conn_scan(wdev); |
| 572 | |
| 573 | /* |
| 574 | * If we can't scan right now, then we need to scan again |
| 575 | * after the current scan finished, since the parameters |
| 576 | * changed (unless we find a good AP anyway). |
| 577 | */ |
| 578 | if (err == -EBUSY) { |
| 579 | err = 0; |
| 580 | wdev->conn->state = CFG80211_CONN_SCAN_AGAIN; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | if (err) |
| 585 | cfg80211_sme_free(wdev); |
| 586 | |
| 587 | return err; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 588 | } |
| 589 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 590 | static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason) |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 591 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 592 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 593 | int err; |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 594 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 595 | if (!wdev->conn) |
| 596 | return 0; |
| 597 | |
| 598 | if (!rdev->ops->deauth) |
| 599 | return -EOPNOTSUPP; |
| 600 | |
| 601 | if (wdev->conn->state == CFG80211_CONN_SCANNING || |
| 602 | wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) { |
| 603 | err = 0; |
| 604 | goto out; |
| 605 | } |
| 606 | |
| 607 | /* wdev->conn->params.bssid must be set if > SCANNING */ |
| 608 | err = cfg80211_mlme_deauth(rdev, wdev->netdev, |
| 609 | wdev->conn->params.bssid, |
| 610 | NULL, 0, reason, false); |
| 611 | out: |
| 612 | cfg80211_sme_free(wdev); |
| 613 | return err; |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 614 | } |
| 615 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 616 | /* |
| 617 | * code shared for in-device and software SME |
| 618 | */ |
| 619 | |
| 620 | static bool cfg80211_is_all_idle(void) |
| 621 | { |
| 622 | struct cfg80211_registered_device *rdev; |
| 623 | struct wireless_dev *wdev; |
| 624 | bool is_all_idle = true; |
| 625 | |
| 626 | /* |
| 627 | * All devices must be idle as otherwise if you are actively |
| 628 | * scanning some new beacon hints could be learned and would |
| 629 | * count as new regulatory hints. |
| 630 | */ |
| 631 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 632 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 633 | wdev_lock(wdev); |
| 634 | if (wdev->conn || wdev->current_bss) |
| 635 | is_all_idle = false; |
| 636 | wdev_unlock(wdev); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | return is_all_idle; |
| 641 | } |
| 642 | |
| 643 | static void disconnect_work(struct work_struct *work) |
| 644 | { |
| 645 | rtnl_lock(); |
| 646 | if (cfg80211_is_all_idle()) |
| 647 | regulatory_hint_disconnect(); |
| 648 | rtnl_unlock(); |
| 649 | } |
| 650 | |
| 651 | static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work); |
| 652 | |
| 653 | |
| 654 | /* |
| 655 | * API calls for drivers implementing connect/disconnect and |
| 656 | * SME event handling |
| 657 | */ |
| 658 | |
Ben Greear | 6f39090 | 2013-06-19 14:06:25 -0700 | [diff] [blame] | 659 | /* This method must consume bss one way or another */ |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 660 | void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 661 | const u8 *req_ie, size_t req_ie_len, |
| 662 | const u8 *resp_ie, size_t resp_ie_len, |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 663 | int status, bool wextev, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 664 | struct cfg80211_bss *bss) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 665 | { |
| 666 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 667 | const u8 *country_ie; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 668 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 669 | union iwreq_data wrqu; |
| 670 | #endif |
| 671 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 672 | ASSERT_WDEV_LOCK(wdev); |
| 673 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 674 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
Ben Greear | 6f39090 | 2013-06-19 14:06:25 -0700 | [diff] [blame] | 675 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) { |
| 676 | cfg80211_put_bss(wdev->wiphy, bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 677 | return; |
Ben Greear | 6f39090 | 2013-06-19 14:06:25 -0700 | [diff] [blame] | 678 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 679 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 680 | nl80211_send_connect_result(wiphy_to_rdev(wdev->wiphy), dev, |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 681 | bssid, req_ie, req_ie_len, |
Johannes Berg | ea416a7 | 2009-08-17 12:22:14 +0200 | [diff] [blame] | 682 | resp_ie, resp_ie_len, |
| 683 | status, GFP_KERNEL); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 684 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 685 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 686 | if (wextev) { |
| 687 | if (req_ie && status == WLAN_STATUS_SUCCESS) { |
| 688 | memset(&wrqu, 0, sizeof(wrqu)); |
| 689 | wrqu.data.length = req_ie_len; |
Zhu Yi | 3409ff7 | 2009-07-20 11:47:44 +0800 | [diff] [blame] | 690 | wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | if (resp_ie && status == WLAN_STATUS_SUCCESS) { |
| 694 | memset(&wrqu, 0, sizeof(wrqu)); |
| 695 | wrqu.data.length = resp_ie_len; |
| 696 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie); |
| 697 | } |
| 698 | |
| 699 | memset(&wrqu, 0, sizeof(wrqu)); |
| 700 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 701 | if (bssid && status == WLAN_STATUS_SUCCESS) { |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 702 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 703 | memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN); |
| 704 | wdev->wext.prev_bssid_valid = true; |
| 705 | } |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 706 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 707 | } |
| 708 | #endif |
| 709 | |
Ujjal Roy | 4c4d684 | 2013-12-04 17:27:34 +0530 | [diff] [blame] | 710 | if (!bss && (status == WLAN_STATUS_SUCCESS)) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 711 | WARN_ON_ONCE(!wiphy_to_rdev(wdev->wiphy)->ops->connect); |
Ujjal Roy | 4c4d684 | 2013-12-04 17:27:34 +0530 | [diff] [blame] | 712 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
| 713 | wdev->ssid, wdev->ssid_len, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 714 | wdev->conn_bss_type, |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 715 | IEEE80211_PRIVACY_ANY); |
Ujjal Roy | 4c4d684 | 2013-12-04 17:27:34 +0530 | [diff] [blame] | 716 | if (bss) |
| 717 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 718 | } |
| 719 | |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 720 | if (wdev->current_bss) { |
| 721 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 722 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 723 | wdev->current_bss = NULL; |
| 724 | } |
| 725 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 726 | if (status != WLAN_STATUS_SUCCESS) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 727 | kzfree(wdev->connect_keys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 728 | wdev->connect_keys = NULL; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 729 | wdev->ssid_len = 0; |
Johannes Berg | f1940c5 | 2013-06-19 13:21:15 +0200 | [diff] [blame] | 730 | if (bss) { |
| 731 | cfg80211_unhold_bss(bss_from_pub(bss)); |
| 732 | cfg80211_put_bss(wdev->wiphy, bss); |
| 733 | } |
Eliad Peller | c1fbb25 | 2014-04-30 15:58:13 +0300 | [diff] [blame] | 734 | cfg80211_sme_free(wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 735 | return; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 736 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 737 | |
Ujjal Roy | 4c4d684 | 2013-12-04 17:27:34 +0530 | [diff] [blame] | 738 | if (WARN_ON(!bss)) |
| 739 | return; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 740 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 741 | wdev->current_bss = bss_from_pub(bss); |
| 742 | |
David Spinadel | b867622 | 2016-09-22 23:16:50 +0300 | [diff] [blame] | 743 | if (!(wdev->wiphy->flags & WIPHY_FLAG_HAS_STATIC_WEP)) |
| 744 | cfg80211_upload_connect_keys(wdev); |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 745 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 746 | rcu_read_lock(); |
| 747 | country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY); |
| 748 | if (!country_ie) { |
| 749 | rcu_read_unlock(); |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | country_ie = kmemdup(country_ie, 2 + country_ie[1], GFP_ATOMIC); |
| 754 | rcu_read_unlock(); |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 755 | |
| 756 | if (!country_ie) |
| 757 | return; |
| 758 | |
| 759 | /* |
| 760 | * ieee80211_bss_get_ie() ensures we can access: |
| 761 | * - country_ie + 2, the start of the country ie data, and |
| 762 | * - and country_ie[1] which is the IE length |
| 763 | */ |
Luis R. Rodriguez | 789fd03 | 2013-10-04 18:07:24 -0700 | [diff] [blame] | 764 | regulatory_hint_country_ie(wdev->wiphy, bss->channel->band, |
| 765 | country_ie + 2, country_ie[1]); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 766 | kfree(country_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 767 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 768 | |
Kanchanapally, Vidyullatha | e705498 | 2016-04-11 15:16:01 +0530 | [diff] [blame] | 769 | /* Consumes bss object one way or another */ |
| 770 | void cfg80211_connect_bss(struct net_device *dev, const u8 *bssid, |
| 771 | struct cfg80211_bss *bss, const u8 *req_ie, |
| 772 | size_t req_ie_len, const u8 *resp_ie, |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 773 | size_t resp_ie_len, int status, gfp_t gfp) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 774 | { |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 775 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 776 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 777 | struct cfg80211_event *ev; |
| 778 | unsigned long flags; |
| 779 | |
Kanchanapally, Vidyullatha | e705498 | 2016-04-11 15:16:01 +0530 | [diff] [blame] | 780 | if (bss) { |
| 781 | /* Make sure the bss entry provided by the driver is valid. */ |
| 782 | struct cfg80211_internal_bss *ibss = bss_from_pub(bss); |
| 783 | |
| 784 | if (WARN_ON(list_empty(&ibss->list))) { |
| 785 | cfg80211_put_bss(wdev->wiphy, bss); |
| 786 | return; |
| 787 | } |
| 788 | } |
| 789 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 790 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
Kanchanapally, Vidyullatha | e705498 | 2016-04-11 15:16:01 +0530 | [diff] [blame] | 791 | if (!ev) { |
| 792 | cfg80211_put_bss(wdev->wiphy, bss); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 793 | return; |
Kanchanapally, Vidyullatha | e705498 | 2016-04-11 15:16:01 +0530 | [diff] [blame] | 794 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 795 | |
| 796 | ev->type = EVENT_CONNECT_RESULT; |
Zhu Yi | 16a832e | 2009-08-19 16:08:22 +0800 | [diff] [blame] | 797 | if (bssid) |
| 798 | memcpy(ev->cr.bssid, bssid, ETH_ALEN); |
Nishant Sarmukadam | 7834704b | 2010-04-14 22:03:02 -0700 | [diff] [blame] | 799 | if (req_ie_len) { |
| 800 | ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 801 | ev->cr.req_ie_len = req_ie_len; |
| 802 | memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len); |
| 803 | } |
| 804 | if (resp_ie_len) { |
| 805 | ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 806 | ev->cr.resp_ie_len = resp_ie_len; |
| 807 | memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len); |
| 808 | } |
Kanchanapally, Vidyullatha | e705498 | 2016-04-11 15:16:01 +0530 | [diff] [blame] | 809 | if (bss) |
| 810 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 811 | ev->cr.bss = bss; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 812 | ev->cr.status = status; |
| 813 | |
| 814 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 815 | list_add_tail(&ev->list, &wdev->event_list); |
| 816 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 817 | queue_work(cfg80211_wq, &rdev->event_work); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 818 | } |
Kanchanapally, Vidyullatha | e705498 | 2016-04-11 15:16:01 +0530 | [diff] [blame] | 819 | EXPORT_SYMBOL(cfg80211_connect_bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 820 | |
Ben Greear | 0e3a39b | 2013-06-19 14:06:27 -0700 | [diff] [blame] | 821 | /* Consumes bss object one way or another */ |
Jouni Malinen | ed9d010 | 2011-05-16 19:40:15 +0300 | [diff] [blame] | 822 | void __cfg80211_roamed(struct wireless_dev *wdev, |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 823 | struct cfg80211_bss *bss, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 824 | const u8 *req_ie, size_t req_ie_len, |
| 825 | const u8 *resp_ie, size_t resp_ie_len) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 826 | { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 827 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 828 | union iwreq_data wrqu; |
| 829 | #endif |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 830 | ASSERT_WDEV_LOCK(wdev); |
| 831 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 832 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
| 833 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 834 | goto out; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 835 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 836 | if (WARN_ON(!wdev->current_bss)) |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 837 | goto out; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 838 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 839 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 840 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 841 | wdev->current_bss = NULL; |
| 842 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 843 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 844 | wdev->current_bss = bss_from_pub(bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 845 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 846 | nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy), |
| 847 | wdev->netdev, bss->bssid, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 848 | req_ie, req_ie_len, resp_ie, resp_ie_len, |
| 849 | GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 850 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 851 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 852 | if (req_ie) { |
| 853 | memset(&wrqu, 0, sizeof(wrqu)); |
| 854 | wrqu.data.length = req_ie_len; |
Zhu Yi | 3409ff7 | 2009-07-20 11:47:44 +0800 | [diff] [blame] | 855 | wireless_send_event(wdev->netdev, IWEVASSOCREQIE, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 856 | &wrqu, req_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | if (resp_ie) { |
| 860 | memset(&wrqu, 0, sizeof(wrqu)); |
| 861 | wrqu.data.length = resp_ie_len; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 862 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, |
| 863 | &wrqu, resp_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | memset(&wrqu, 0, sizeof(wrqu)); |
| 867 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 868 | memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN); |
| 869 | memcpy(wdev->wext.prev_bssid, bss->bssid, ETH_ALEN); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 870 | wdev->wext.prev_bssid_valid = true; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 871 | wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 872 | #endif |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 873 | |
| 874 | return; |
| 875 | out: |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 876 | cfg80211_put_bss(wdev->wiphy, bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 877 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 878 | |
Jouni Malinen | ed9d010 | 2011-05-16 19:40:15 +0300 | [diff] [blame] | 879 | void cfg80211_roamed(struct net_device *dev, |
| 880 | struct ieee80211_channel *channel, |
| 881 | const u8 *bssid, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 882 | const u8 *req_ie, size_t req_ie_len, |
| 883 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 884 | { |
| 885 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 886 | struct cfg80211_bss *bss; |
| 887 | |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 888 | bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid, |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 889 | wdev->ssid_len, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 890 | wdev->conn_bss_type, IEEE80211_PRIVACY_ANY); |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 891 | if (WARN_ON(!bss)) |
| 892 | return; |
| 893 | |
| 894 | cfg80211_roamed_bss(dev, bss, req_ie, req_ie_len, resp_ie, |
| 895 | resp_ie_len, gfp); |
| 896 | } |
| 897 | EXPORT_SYMBOL(cfg80211_roamed); |
| 898 | |
Ben Greear | 0e3a39b | 2013-06-19 14:06:27 -0700 | [diff] [blame] | 899 | /* Consumes bss object one way or another */ |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 900 | void cfg80211_roamed_bss(struct net_device *dev, |
| 901 | struct cfg80211_bss *bss, const u8 *req_ie, |
| 902 | size_t req_ie_len, const u8 *resp_ie, |
| 903 | size_t resp_ie_len, gfp_t gfp) |
| 904 | { |
| 905 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 906 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 907 | struct cfg80211_event *ev; |
| 908 | unsigned long flags; |
| 909 | |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 910 | if (WARN_ON(!bss)) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 911 | return; |
| 912 | |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 913 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 914 | if (!ev) { |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 915 | cfg80211_put_bss(wdev->wiphy, bss); |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 916 | return; |
| 917 | } |
| 918 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 919 | ev->type = EVENT_ROAMED; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 920 | ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 921 | ev->rm.req_ie_len = req_ie_len; |
| 922 | memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len); |
| 923 | ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 924 | ev->rm.resp_ie_len = resp_ie_len; |
| 925 | memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len); |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 926 | ev->rm.bss = bss; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 927 | |
| 928 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 929 | list_add_tail(&ev->list, &wdev->event_list); |
| 930 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 931 | queue_work(cfg80211_wq, &rdev->event_work); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 932 | } |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 933 | EXPORT_SYMBOL(cfg80211_roamed_bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 934 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 935 | void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 936 | size_t ie_len, u16 reason, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 937 | { |
| 938 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 939 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 940 | int i; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 941 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 942 | union iwreq_data wrqu; |
| 943 | #endif |
| 944 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 945 | ASSERT_WDEV_LOCK(wdev); |
| 946 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 947 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
| 948 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 949 | return; |
| 950 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 951 | if (wdev->current_bss) { |
| 952 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 953 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | wdev->current_bss = NULL; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 957 | wdev->ssid_len = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 958 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 959 | nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap); |
| 960 | |
Arend van Spriel | b860715 | 2016-02-15 14:35:53 +0100 | [diff] [blame] | 961 | /* stop critical protocol if supported */ |
| 962 | if (rdev->ops->crit_proto_stop && rdev->crit_proto_nlportid) { |
| 963 | rdev->crit_proto_nlportid = 0; |
| 964 | rdev_crit_proto_stop(rdev, wdev); |
| 965 | } |
| 966 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 967 | /* |
| 968 | * Delete all the keys ... pairwise keys can't really |
| 969 | * exist any more anyway, but default keys might. |
| 970 | */ |
| 971 | if (rdev->ops->del_key) |
| 972 | for (i = 0; i < 6; i++) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 973 | rdev_del_key(rdev, dev, i, false, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 974 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 975 | rdev_set_qos_map(rdev, dev, NULL); |
| 976 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 977 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 978 | memset(&wrqu, 0, sizeof(wrqu)); |
| 979 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 980 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
Abhijeet Kolekar | 5f61203 | 2010-01-13 13:23:14 -0800 | [diff] [blame] | 981 | wdev->wext.connect.ssid_len = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 982 | #endif |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 983 | |
| 984 | schedule_work(&cfg80211_disconnect_work); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | void cfg80211_disconnected(struct net_device *dev, u16 reason, |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 988 | const u8 *ie, size_t ie_len, |
| 989 | bool locally_generated, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 990 | { |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 991 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 992 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 993 | struct cfg80211_event *ev; |
| 994 | unsigned long flags; |
| 995 | |
| 996 | ev = kzalloc(sizeof(*ev) + ie_len, gfp); |
| 997 | if (!ev) |
| 998 | return; |
| 999 | |
| 1000 | ev->type = EVENT_DISCONNECTED; |
| 1001 | ev->dc.ie = ((u8 *)ev) + sizeof(*ev); |
| 1002 | ev->dc.ie_len = ie_len; |
| 1003 | memcpy((void *)ev->dc.ie, ie, ie_len); |
| 1004 | ev->dc.reason = reason; |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 1005 | ev->dc.locally_generated = locally_generated; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1006 | |
| 1007 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 1008 | list_add_tail(&ev->list, &wdev->event_list); |
| 1009 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 1010 | queue_work(cfg80211_wq, &rdev->event_work); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1011 | } |
| 1012 | EXPORT_SYMBOL(cfg80211_disconnected); |
| 1013 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1014 | /* |
| 1015 | * API calls for nl80211/wext compatibility code |
| 1016 | */ |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 1017 | int cfg80211_connect(struct cfg80211_registered_device *rdev, |
| 1018 | struct net_device *dev, |
| 1019 | struct cfg80211_connect_params *connect, |
| 1020 | struct cfg80211_cached_keys *connkeys, |
| 1021 | const u8 *prev_bssid) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1022 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1023 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1024 | int err; |
| 1025 | |
| 1026 | ASSERT_WDEV_LOCK(wdev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1027 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1028 | if (WARN_ON(wdev->connect_keys)) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 1029 | kzfree(wdev->connect_keys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1030 | wdev->connect_keys = NULL; |
| 1031 | } |
| 1032 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1033 | cfg80211_oper_and_ht_capa(&connect->ht_capa_mask, |
| 1034 | rdev->wiphy.ht_capa_mod_mask); |
| 1035 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1036 | if (connkeys && connkeys->def >= 0) { |
| 1037 | int idx; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 1038 | u32 cipher; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1039 | |
| 1040 | idx = connkeys->def; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 1041 | cipher = connkeys->params[idx].cipher; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1042 | /* If given a WEP key we may need it for shared key auth */ |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 1043 | if (cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 1044 | cipher == WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1045 | connect->key_idx = idx; |
| 1046 | connect->key = connkeys->params[idx].key; |
| 1047 | connect->key_len = connkeys->params[idx].key_len; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 1048 | |
| 1049 | /* |
| 1050 | * If ciphers are not set (e.g. when going through |
| 1051 | * iwconfig), we have to set them appropriately here. |
| 1052 | */ |
| 1053 | if (connect->crypto.cipher_group == 0) |
| 1054 | connect->crypto.cipher_group = cipher; |
| 1055 | |
| 1056 | if (connect->crypto.n_ciphers_pairwise == 0) { |
| 1057 | connect->crypto.n_ciphers_pairwise = 1; |
| 1058 | connect->crypto.ciphers_pairwise[0] = cipher; |
| 1059 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1060 | } |
David Spinadel | b867622 | 2016-09-22 23:16:50 +0300 | [diff] [blame] | 1061 | |
| 1062 | connect->crypto.wep_keys = connkeys->params; |
| 1063 | connect->crypto.wep_tx_key = connkeys->def; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1064 | } else { |
| 1065 | if (WARN_ON(connkeys)) |
| 1066 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1067 | } |
| 1068 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1069 | wdev->connect_keys = connkeys; |
| 1070 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); |
| 1071 | wdev->ssid_len = connect->ssid_len; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1072 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 1073 | wdev->conn_bss_type = connect->pbss ? IEEE80211_BSS_TYPE_PBSS : |
| 1074 | IEEE80211_BSS_TYPE_ESS; |
| 1075 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1076 | if (!rdev->ops->connect) |
| 1077 | err = cfg80211_sme_connect(wdev, connect, prev_bssid); |
| 1078 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1079 | err = rdev_connect(rdev, dev, connect); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1080 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1081 | if (err) { |
| 1082 | wdev->connect_keys = NULL; |
| 1083 | wdev->ssid_len = 0; |
| 1084 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1085 | } |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1086 | |
| 1087 | return 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1088 | } |
| 1089 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 1090 | int cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
| 1091 | struct net_device *dev, u16 reason, bool wextev) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1092 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1093 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | dee8a97 | 2013-08-13 09:23:57 +0200 | [diff] [blame] | 1094 | int err = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1095 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1096 | ASSERT_WDEV_LOCK(wdev); |
| 1097 | |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 1098 | kzfree(wdev->connect_keys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1099 | wdev->connect_keys = NULL; |
| 1100 | |
Johannes Berg | dee8a97 | 2013-08-13 09:23:57 +0200 | [diff] [blame] | 1101 | if (wdev->conn) |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1102 | err = cfg80211_sme_disconnect(wdev, reason); |
Johannes Berg | dee8a97 | 2013-08-13 09:23:57 +0200 | [diff] [blame] | 1103 | else if (!rdev->ops->disconnect) |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1104 | cfg80211_mlme_down(rdev, dev); |
Johannes Berg | dee8a97 | 2013-08-13 09:23:57 +0200 | [diff] [blame] | 1105 | else if (wdev->current_bss) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1106 | err = rdev_disconnect(rdev, dev, reason); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1107 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1108 | return err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 1109 | } |