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