Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 2 | /* |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 3 | * SME code for cfg80211 |
| 4 | * both driver SME event handling and the SME implementation |
| 5 | * (for nl80211's connect() and wext) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6 | * |
| 7 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 8 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 9 | * Copyright 2017 Intel Deutschland GmbH |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/etherdevice.h> |
| 13 | #include <linux/if_arp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15 | #include <linux/workqueue.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 16 | #include <linux/wireless.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 18 | #include <net/iw_handler.h> |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 19 | #include <net/cfg80211.h> |
| 20 | #include <net/rtnetlink.h> |
| 21 | #include "nl80211.h" |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 22 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 23 | #include "rdev-ops.h" |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 24 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 25 | /* |
| 26 | * Software SME in cfg80211, using auth/assoc/deauth calls to the |
| 27 | * driver. This is is for implementing nl80211's connect/disconnect |
| 28 | * and wireless extensions (if configured.) |
| 29 | */ |
| 30 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 31 | struct cfg80211_conn { |
| 32 | struct cfg80211_connect_params params; |
| 33 | /* these are sub-states of the _CONNECTING sme_state */ |
| 34 | enum { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 35 | CFG80211_CONN_SCANNING, |
| 36 | CFG80211_CONN_SCAN_AGAIN, |
| 37 | CFG80211_CONN_AUTHENTICATE_NEXT, |
| 38 | CFG80211_CONN_AUTHENTICATING, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 39 | CFG80211_CONN_AUTH_FAILED_TIMEOUT, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 40 | CFG80211_CONN_ASSOCIATE_NEXT, |
| 41 | CFG80211_CONN_ASSOCIATING, |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 42 | CFG80211_CONN_ASSOC_FAILED, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 43 | CFG80211_CONN_ASSOC_FAILED_TIMEOUT, |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 44 | CFG80211_CONN_DEAUTH, |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 45 | CFG80211_CONN_ABANDON, |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 46 | CFG80211_CONN_CONNECTED, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 47 | } state; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 48 | u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN]; |
Johannes Berg | 46b9d18 | 2015-03-31 16:09:13 +0200 | [diff] [blame] | 49 | const u8 *ie; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 50 | size_t ie_len; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 51 | bool auto_auth, prev_bssid_valid; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 54 | static void cfg80211_sme_free(struct wireless_dev *wdev) |
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 | if (!wdev->conn) |
| 57 | return; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 58 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 59 | kfree(wdev->conn->ie); |
| 60 | kfree(wdev->conn); |
| 61 | wdev->conn = NULL; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 64 | static int cfg80211_conn_scan(struct wireless_dev *wdev) |
| 65 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 66 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 67 | struct cfg80211_scan_request *request; |
| 68 | int n_channels, err; |
| 69 | |
| 70 | ASSERT_RTNL(); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 71 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 72 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 73 | if (rdev->scan_req || rdev->scan_msg) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 74 | return -EBUSY; |
| 75 | |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 76 | if (wdev->conn->params.channel) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 77 | n_channels = 1; |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 78 | else |
| 79 | n_channels = ieee80211_get_num_supported_channels(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 80 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 81 | request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) + |
| 82 | sizeof(request->channels[0]) * n_channels, |
| 83 | GFP_KERNEL); |
| 84 | if (!request) |
| 85 | return -ENOMEM; |
| 86 | |
Karl Beldan | 2a84ee8 | 2014-10-07 11:42:18 +0200 | [diff] [blame] | 87 | if (wdev->conn->params.channel) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 88 | enum nl80211_band band = wdev->conn->params.channel->band; |
Karl Beldan | 2a84ee8 | 2014-10-07 11:42:18 +0200 | [diff] [blame] | 89 | struct ieee80211_supported_band *sband = |
| 90 | wdev->wiphy->bands[band]; |
| 91 | |
| 92 | if (!sband) { |
| 93 | kfree(request); |
| 94 | return -EINVAL; |
| 95 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 96 | request->channels[0] = wdev->conn->params.channel; |
Karl Beldan | 2a84ee8 | 2014-10-07 11:42:18 +0200 | [diff] [blame] | 97 | request->rates[band] = (1 << sband->n_bitrates) - 1; |
| 98 | } else { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 99 | int i = 0, j; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 100 | enum nl80211_band band; |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 101 | struct ieee80211_supported_band *bands; |
| 102 | struct ieee80211_channel *channel; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 103 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 104 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 105 | bands = wdev->wiphy->bands[band]; |
| 106 | if (!bands) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 107 | continue; |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 108 | for (j = 0; j < bands->n_channels; j++) { |
| 109 | channel = &bands->channels[j]; |
| 110 | if (channel->flags & IEEE80211_CHAN_DISABLED) |
| 111 | continue; |
| 112 | request->channels[i++] = channel; |
| 113 | } |
| 114 | request->rates[band] = (1 << bands->n_bitrates) - 1; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 115 | } |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 116 | n_channels = i; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 117 | } |
| 118 | request->n_channels = n_channels; |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 119 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 120 | request->n_ssids = 1; |
| 121 | |
| 122 | memcpy(request->ssids[0].ssid, wdev->conn->params.ssid, |
| 123 | wdev->conn->params.ssid_len); |
| 124 | request->ssids[0].ssid_len = wdev->conn->params.ssid_len; |
| 125 | |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 126 | eth_broadcast_addr(request->bssid); |
| 127 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 128 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 129 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 130 | request->scan_start = jiffies; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 131 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 132 | rdev->scan_req = request; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 133 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 134 | err = rdev_scan(rdev, request); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 135 | if (!err) { |
| 136 | wdev->conn->state = CFG80211_CONN_SCANNING; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 137 | nl80211_send_scan_start(rdev, wdev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 138 | dev_hold(wdev->netdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 139 | } else { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 140 | rdev->scan_req = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 141 | kfree(request); |
| 142 | } |
| 143 | return err; |
| 144 | } |
| 145 | |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 146 | static int cfg80211_conn_do_work(struct wireless_dev *wdev, |
| 147 | enum nl80211_timeout_reason *treason) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 148 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 149 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 150 | struct cfg80211_connect_params *params; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 151 | struct cfg80211_assoc_request req = {}; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 152 | int err; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 153 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 154 | ASSERT_WDEV_LOCK(wdev); |
| 155 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 156 | if (!wdev->conn) |
| 157 | return 0; |
| 158 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 159 | params = &wdev->conn->params; |
| 160 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 161 | switch (wdev->conn->state) { |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 162 | case CFG80211_CONN_SCANNING: |
| 163 | /* didn't find it during scan ... */ |
| 164 | return -ENOENT; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 165 | case CFG80211_CONN_SCAN_AGAIN: |
| 166 | return cfg80211_conn_scan(wdev); |
| 167 | case CFG80211_CONN_AUTHENTICATE_NEXT: |
Johannes Berg | 2fd0511 | 2014-04-29 17:52:36 +0200 | [diff] [blame] | 168 | if (WARN_ON(!rdev->ops->auth)) |
| 169 | return -EOPNOTSUPP; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 170 | wdev->conn->state = CFG80211_CONN_AUTHENTICATING; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 171 | return cfg80211_mlme_auth(rdev, wdev->netdev, |
| 172 | params->channel, params->auth_type, |
| 173 | params->bssid, |
| 174 | params->ssid, params->ssid_len, |
| 175 | NULL, 0, |
| 176 | params->key, params->key_len, |
| 177 | params->key_idx, NULL, 0); |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 178 | case CFG80211_CONN_AUTH_FAILED_TIMEOUT: |
| 179 | *treason = NL80211_TIMEOUT_AUTH; |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 180 | return -ENOTCONN; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 181 | case CFG80211_CONN_ASSOCIATE_NEXT: |
Johannes Berg | 2fd0511 | 2014-04-29 17:52:36 +0200 | [diff] [blame] | 182 | if (WARN_ON(!rdev->ops->assoc)) |
| 183 | return -EOPNOTSUPP; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 184 | wdev->conn->state = CFG80211_CONN_ASSOCIATING; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 185 | if (wdev->conn->prev_bssid_valid) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 186 | req.prev_bssid = wdev->conn->prev_bssid; |
| 187 | req.ie = params->ie; |
| 188 | req.ie_len = params->ie_len; |
| 189 | req.use_mfp = params->mfp != NL80211_MFP_NO; |
| 190 | req.crypto = params->crypto; |
| 191 | req.flags = params->flags; |
| 192 | req.ht_capa = params->ht_capa; |
| 193 | req.ht_capa_mask = params->ht_capa_mask; |
| 194 | req.vht_capa = params->vht_capa; |
| 195 | req.vht_capa_mask = params->vht_capa_mask; |
| 196 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 197 | err = cfg80211_mlme_assoc(rdev, wdev->netdev, params->channel, |
| 198 | params->bssid, params->ssid, |
| 199 | params->ssid_len, &req); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 200 | if (err) |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 201 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
| 202 | NULL, 0, |
| 203 | WLAN_REASON_DEAUTH_LEAVING, |
| 204 | false); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 205 | return err; |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 206 | case CFG80211_CONN_ASSOC_FAILED_TIMEOUT: |
| 207 | *treason = NL80211_TIMEOUT_ASSOC; |
| 208 | /* fall through */ |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 209 | case CFG80211_CONN_ASSOC_FAILED: |
| 210 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
| 211 | NULL, 0, |
| 212 | WLAN_REASON_DEAUTH_LEAVING, false); |
| 213 | return -ENOTCONN; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 214 | case CFG80211_CONN_DEAUTH: |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 215 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
| 216 | NULL, 0, |
| 217 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 218 | /* fall through */ |
| 219 | case CFG80211_CONN_ABANDON: |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 220 | /* free directly, disconnected event already sent */ |
| 221 | cfg80211_sme_free(wdev); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 222 | return 0; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 223 | default: |
| 224 | return 0; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | void cfg80211_conn_work(struct work_struct *work) |
| 229 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 230 | struct cfg80211_registered_device *rdev = |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 231 | container_of(work, struct cfg80211_registered_device, conn_work); |
| 232 | struct wireless_dev *wdev; |
Johannes Berg | 7400f42 | 2009-10-31 07:40:37 +0100 | [diff] [blame] | 233 | u8 bssid_buf[ETH_ALEN], *bssid = NULL; |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 234 | enum nl80211_timeout_reason treason; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 235 | |
| 236 | rtnl_lock(); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 237 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 238 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | c815797 | 2013-05-23 18:10:21 +0200 | [diff] [blame] | 239 | if (!wdev->netdev) |
| 240 | continue; |
| 241 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 242 | wdev_lock(wdev); |
| 243 | if (!netif_running(wdev->netdev)) { |
| 244 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 245 | continue; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 246 | } |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 247 | if (!wdev->conn || |
| 248 | wdev->conn->state == CFG80211_CONN_CONNECTED) { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 249 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 250 | continue; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 251 | } |
Johannes Berg | 7400f42 | 2009-10-31 07:40:37 +0100 | [diff] [blame] | 252 | if (wdev->conn->params.bssid) { |
| 253 | memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN); |
| 254 | bssid = bssid_buf; |
| 255 | } |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 256 | treason = NL80211_TIMEOUT_UNSPECIFIED; |
| 257 | if (cfg80211_conn_do_work(wdev, &treason)) { |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 258 | struct cfg80211_connect_resp_params cr; |
| 259 | |
| 260 | memset(&cr, 0, sizeof(cr)); |
| 261 | cr.status = -1; |
| 262 | cr.bssid = bssid; |
| 263 | cr.timeout_reason = treason; |
| 264 | __cfg80211_connect_result(wdev->netdev, &cr, false); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 265 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 266 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 269 | rtnl_unlock(); |
| 270 | } |
| 271 | |
Ben Greear | 0e3a39b | 2013-06-19 14:06:27 -0700 | [diff] [blame] | 272 | /* Returned bss is reference counted and must be cleaned up appropriately. */ |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 273 | static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 274 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 275 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 276 | struct cfg80211_bss *bss; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 277 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 278 | ASSERT_WDEV_LOCK(wdev); |
| 279 | |
Jouni Malinen | ed9d010 | 2011-05-16 19:40:15 +0300 | [diff] [blame] | 280 | bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel, |
| 281 | wdev->conn->params.bssid, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 282 | wdev->conn->params.ssid, |
| 283 | wdev->conn->params.ssid_len, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 284 | wdev->conn_bss_type, |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 285 | IEEE80211_PRIVACY(wdev->conn->params.privacy)); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 286 | if (!bss) |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 287 | return NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 288 | |
| 289 | memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN); |
| 290 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 291 | wdev->conn->params.channel = bss->channel; |
| 292 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 293 | schedule_work(&rdev->conn_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 294 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 295 | return bss; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 296 | } |
| 297 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 298 | static void __cfg80211_sme_scan_done(struct net_device *dev) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 299 | { |
| 300 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 301 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 302 | struct cfg80211_bss *bss; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 303 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 304 | ASSERT_WDEV_LOCK(wdev); |
| 305 | |
Zhu Yi | d4b1a68 | 2009-07-16 17:34:14 +0800 | [diff] [blame] | 306 | if (!wdev->conn) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 307 | return; |
| 308 | |
| 309 | if (wdev->conn->state != CFG80211_CONN_SCANNING && |
| 310 | wdev->conn->state != CFG80211_CONN_SCAN_AGAIN) |
| 311 | return; |
| 312 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 313 | bss = cfg80211_get_conn_bss(wdev); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 314 | if (bss) |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 315 | cfg80211_put_bss(&rdev->wiphy, bss); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 316 | else |
| 317 | schedule_work(&rdev->conn_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 318 | } |
| 319 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 320 | void cfg80211_sme_scan_done(struct net_device *dev) |
| 321 | { |
| 322 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 323 | |
| 324 | wdev_lock(wdev); |
| 325 | __cfg80211_sme_scan_done(dev); |
| 326 | wdev_unlock(wdev); |
| 327 | } |
| 328 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 329 | 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] | 330 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 331 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 332 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 333 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 334 | u16 status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 335 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 336 | ASSERT_WDEV_LOCK(wdev); |
| 337 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 338 | if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 339 | return; |
| 340 | |
| 341 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG && |
| 342 | wdev->conn->auto_auth && |
| 343 | wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) { |
| 344 | /* select automatically between only open, shared, leap */ |
| 345 | switch (wdev->conn->params.auth_type) { |
| 346 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 347 | if (wdev->connect_keys) |
| 348 | wdev->conn->params.auth_type = |
| 349 | NL80211_AUTHTYPE_SHARED_KEY; |
| 350 | else |
| 351 | wdev->conn->params.auth_type = |
| 352 | NL80211_AUTHTYPE_NETWORK_EAP; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 353 | break; |
| 354 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 355 | wdev->conn->params.auth_type = |
| 356 | NL80211_AUTHTYPE_NETWORK_EAP; |
| 357 | break; |
| 358 | default: |
| 359 | /* huh? */ |
| 360 | wdev->conn->params.auth_type = |
| 361 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 362 | break; |
| 363 | } |
| 364 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 365 | schedule_work(&rdev->conn_work); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 366 | } else if (status_code != WLAN_STATUS_SUCCESS) { |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 367 | struct cfg80211_connect_resp_params cr; |
| 368 | |
| 369 | memset(&cr, 0, sizeof(cr)); |
| 370 | cr.status = status_code; |
| 371 | cr.bssid = mgmt->bssid; |
| 372 | cr.timeout_reason = NL80211_TIMEOUT_UNSPECIFIED; |
| 373 | __cfg80211_connect_result(wdev->netdev, &cr, false); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 374 | } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 375 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 376 | schedule_work(&rdev->conn_work); |
| 377 | } |
| 378 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 379 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 380 | bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status) |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 381 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 382 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 383 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 384 | if (!wdev->conn) |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 385 | return false; |
| 386 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 387 | if (status == WLAN_STATUS_SUCCESS) { |
| 388 | wdev->conn->state = CFG80211_CONN_CONNECTED; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 389 | return false; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | if (wdev->conn->prev_bssid_valid) { |
| 393 | /* |
| 394 | * Some stupid APs don't accept reassoc, so we |
| 395 | * need to fall back to trying regular assoc; |
| 396 | * return true so no event is sent to userspace. |
| 397 | */ |
| 398 | wdev->conn->prev_bssid_valid = false; |
| 399 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 400 | schedule_work(&rdev->conn_work); |
| 401 | return true; |
| 402 | } |
| 403 | |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 404 | wdev->conn->state = CFG80211_CONN_ASSOC_FAILED; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 405 | schedule_work(&rdev->conn_work); |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | void cfg80211_sme_deauth(struct wireless_dev *wdev) |
| 410 | { |
| 411 | cfg80211_sme_free(wdev); |
| 412 | } |
| 413 | |
| 414 | void cfg80211_sme_auth_timeout(struct wireless_dev *wdev) |
| 415 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 416 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 417 | |
| 418 | if (!wdev->conn) |
| 419 | return; |
| 420 | |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 421 | wdev->conn->state = CFG80211_CONN_AUTH_FAILED_TIMEOUT; |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 422 | schedule_work(&rdev->conn_work); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | void cfg80211_sme_disassoc(struct wireless_dev *wdev) |
| 426 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 427 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 428 | |
| 429 | if (!wdev->conn) |
| 430 | return; |
| 431 | |
| 432 | wdev->conn->state = CFG80211_CONN_DEAUTH; |
| 433 | schedule_work(&rdev->conn_work); |
| 434 | } |
| 435 | |
| 436 | void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev) |
| 437 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 438 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 439 | |
| 440 | if (!wdev->conn) |
| 441 | return; |
| 442 | |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 443 | wdev->conn->state = CFG80211_CONN_ASSOC_FAILED_TIMEOUT; |
Johannes Berg | 923a0e7 | 2013-06-28 11:38:54 +0200 | [diff] [blame] | 444 | schedule_work(&rdev->conn_work); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 445 | } |
| 446 | |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 447 | void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev) |
| 448 | { |
| 449 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 450 | |
| 451 | if (!wdev->conn) |
| 452 | return; |
| 453 | |
| 454 | wdev->conn->state = CFG80211_CONN_ABANDON; |
| 455 | schedule_work(&rdev->conn_work); |
| 456 | } |
| 457 | |
Johannes Berg | 46b9d18 | 2015-03-31 16:09:13 +0200 | [diff] [blame] | 458 | static int cfg80211_sme_get_conn_ies(struct wireless_dev *wdev, |
| 459 | const u8 *ies, size_t ies_len, |
| 460 | const u8 **out_ies, size_t *out_ies_len) |
| 461 | { |
| 462 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 463 | u8 *buf; |
| 464 | size_t offs; |
| 465 | |
| 466 | if (!rdev->wiphy.extended_capabilities_len || |
| 467 | (ies && cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, ies, ies_len))) { |
| 468 | *out_ies = kmemdup(ies, ies_len, GFP_KERNEL); |
| 469 | if (!*out_ies) |
| 470 | return -ENOMEM; |
| 471 | *out_ies_len = ies_len; |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | buf = kmalloc(ies_len + rdev->wiphy.extended_capabilities_len + 2, |
| 476 | GFP_KERNEL); |
| 477 | if (!buf) |
| 478 | return -ENOMEM; |
| 479 | |
| 480 | if (ies_len) { |
| 481 | static const u8 before_extcapa[] = { |
| 482 | /* not listing IEs expected to be created by driver */ |
| 483 | WLAN_EID_RSN, |
| 484 | WLAN_EID_QOS_CAPA, |
| 485 | WLAN_EID_RRM_ENABLED_CAPABILITIES, |
| 486 | WLAN_EID_MOBILITY_DOMAIN, |
| 487 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 488 | WLAN_EID_BSS_COEX_2040, |
| 489 | }; |
| 490 | |
| 491 | offs = ieee80211_ie_split(ies, ies_len, before_extcapa, |
| 492 | ARRAY_SIZE(before_extcapa), 0); |
| 493 | memcpy(buf, ies, offs); |
| 494 | /* leave a whole for extended capabilities IE */ |
| 495 | memcpy(buf + offs + rdev->wiphy.extended_capabilities_len + 2, |
| 496 | ies + offs, ies_len - offs); |
| 497 | } else { |
| 498 | offs = 0; |
| 499 | } |
| 500 | |
| 501 | /* place extended capabilities IE (with only driver capabilities) */ |
| 502 | buf[offs] = WLAN_EID_EXT_CAPABILITY; |
| 503 | buf[offs + 1] = rdev->wiphy.extended_capabilities_len; |
| 504 | memcpy(buf + offs + 2, |
| 505 | rdev->wiphy.extended_capabilities, |
| 506 | rdev->wiphy.extended_capabilities_len); |
| 507 | |
| 508 | *out_ies = buf; |
| 509 | *out_ies_len = ies_len + rdev->wiphy.extended_capabilities_len + 2; |
| 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 514 | static int cfg80211_sme_connect(struct wireless_dev *wdev, |
| 515 | struct cfg80211_connect_params *connect, |
| 516 | const u8 *prev_bssid) |
| 517 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 518 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 519 | struct cfg80211_bss *bss; |
| 520 | int err; |
| 521 | |
| 522 | if (!rdev->ops->auth || !rdev->ops->assoc) |
| 523 | return -EOPNOTSUPP; |
| 524 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 525 | if (wdev->current_bss) { |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 526 | cfg80211_unhold_bss(wdev->current_bss); |
| 527 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
| 528 | wdev->current_bss = NULL; |
| 529 | |
| 530 | cfg80211_sme_free(wdev); |
| 531 | } |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 532 | |
| 533 | if (WARN_ON(wdev->conn)) |
| 534 | return -EINPROGRESS; |
| 535 | |
| 536 | wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL); |
| 537 | if (!wdev->conn) |
| 538 | return -ENOMEM; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 539 | |
| 540 | /* |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 541 | * Copy all parameters, and treat explicitly IEs, BSSID, SSID. |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 542 | */ |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 543 | memcpy(&wdev->conn->params, connect, sizeof(*connect)); |
| 544 | if (connect->bssid) { |
| 545 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 546 | memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN); |
| 547 | } |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 548 | |
Johannes Berg | 46b9d18 | 2015-03-31 16:09:13 +0200 | [diff] [blame] | 549 | if (cfg80211_sme_get_conn_ies(wdev, connect->ie, connect->ie_len, |
| 550 | &wdev->conn->ie, |
| 551 | &wdev->conn->params.ie_len)) { |
| 552 | kfree(wdev->conn); |
| 553 | wdev->conn = NULL; |
| 554 | return -ENOMEM; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 555 | } |
Johannes Berg | 46b9d18 | 2015-03-31 16:09:13 +0200 | [diff] [blame] | 556 | wdev->conn->params.ie = wdev->conn->ie; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 557 | |
| 558 | if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) { |
| 559 | wdev->conn->auto_auth = true; |
| 560 | /* start with open system ... should mostly work */ |
| 561 | wdev->conn->params.auth_type = |
| 562 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 563 | } else { |
| 564 | wdev->conn->auto_auth = false; |
| 565 | } |
| 566 | |
| 567 | wdev->conn->params.ssid = wdev->ssid; |
Zhao, Gang | babd3a2 | 2014-03-19 23:02:21 +0800 | [diff] [blame] | 568 | wdev->conn->params.ssid_len = wdev->ssid_len; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 569 | |
| 570 | /* see if we have the bss already */ |
| 571 | bss = cfg80211_get_conn_bss(wdev); |
| 572 | |
| 573 | if (prev_bssid) { |
| 574 | memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN); |
| 575 | wdev->conn->prev_bssid_valid = true; |
| 576 | } |
| 577 | |
| 578 | /* we're good if we have a matching bss struct */ |
| 579 | if (bss) { |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 580 | enum nl80211_timeout_reason treason; |
| 581 | |
| 582 | err = cfg80211_conn_do_work(wdev, &treason); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 583 | cfg80211_put_bss(wdev->wiphy, bss); |
| 584 | } else { |
| 585 | /* otherwise we'll need to scan for the AP first */ |
| 586 | err = cfg80211_conn_scan(wdev); |
| 587 | |
| 588 | /* |
| 589 | * If we can't scan right now, then we need to scan again |
| 590 | * after the current scan finished, since the parameters |
| 591 | * changed (unless we find a good AP anyway). |
| 592 | */ |
| 593 | if (err == -EBUSY) { |
| 594 | err = 0; |
| 595 | wdev->conn->state = CFG80211_CONN_SCAN_AGAIN; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | if (err) |
| 600 | cfg80211_sme_free(wdev); |
| 601 | |
| 602 | return err; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 603 | } |
| 604 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 605 | static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason) |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 606 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 607 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 608 | int err; |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 609 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 610 | if (!wdev->conn) |
| 611 | return 0; |
| 612 | |
| 613 | if (!rdev->ops->deauth) |
| 614 | return -EOPNOTSUPP; |
| 615 | |
| 616 | if (wdev->conn->state == CFG80211_CONN_SCANNING || |
| 617 | wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) { |
| 618 | err = 0; |
| 619 | goto out; |
| 620 | } |
| 621 | |
| 622 | /* wdev->conn->params.bssid must be set if > SCANNING */ |
| 623 | err = cfg80211_mlme_deauth(rdev, wdev->netdev, |
| 624 | wdev->conn->params.bssid, |
| 625 | NULL, 0, reason, false); |
| 626 | out: |
| 627 | cfg80211_sme_free(wdev); |
| 628 | return err; |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 629 | } |
| 630 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 631 | /* |
| 632 | * code shared for in-device and software SME |
| 633 | */ |
| 634 | |
| 635 | static bool cfg80211_is_all_idle(void) |
| 636 | { |
| 637 | struct cfg80211_registered_device *rdev; |
| 638 | struct wireless_dev *wdev; |
| 639 | bool is_all_idle = true; |
| 640 | |
| 641 | /* |
| 642 | * All devices must be idle as otherwise if you are actively |
| 643 | * scanning some new beacon hints could be learned and would |
| 644 | * count as new regulatory hints. |
Sriram R | 113f3aa | 2018-10-19 14:42:59 +0530 | [diff] [blame] | 645 | * Also if there is any other active beaconing interface we |
| 646 | * need not issue a disconnect hint and reset any info such |
| 647 | * as chan dfs state, etc. |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 648 | */ |
| 649 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 650 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 651 | wdev_lock(wdev); |
Sriram R | 113f3aa | 2018-10-19 14:42:59 +0530 | [diff] [blame] | 652 | if (wdev->conn || wdev->current_bss || |
| 653 | cfg80211_beaconing_iface_active(wdev)) |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 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 | |
Johannes Berg | e005bd7d | 2019-02-01 11:09:54 +0100 | [diff] [blame] | 670 | DECLARE_WORK(cfg80211_disconnect_work, disconnect_work); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 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 + |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 810 | params->fils.kek_len + params->fils.pmk_len + |
| 811 | (params->fils.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 | } |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [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; |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 844 | } |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 845 | if (params->fils.pmk_len) { |
| 846 | ev->cr.fils.pmk = next; |
| 847 | ev->cr.fils.pmk_len = params->fils.pmk_len; |
| 848 | memcpy((void *)ev->cr.fils.pmk, params->fils.pmk, |
| 849 | params->fils.pmk_len); |
| 850 | next += params->fils.pmk_len; |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 851 | } |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 852 | if (params->fils.pmkid) { |
| 853 | ev->cr.fils.pmkid = next; |
| 854 | memcpy((void *)ev->cr.fils.pmkid, params->fils.pmkid, |
| 855 | WLAN_PMKID_LEN); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 856 | next += WLAN_PMKID_LEN; |
| 857 | } |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 858 | ev->cr.fils.update_erp_next_seq_num = params->fils.update_erp_next_seq_num; |
| 859 | if (params->fils.update_erp_next_seq_num) |
| 860 | 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] | 861 | if (params->bss) |
| 862 | cfg80211_hold_bss(bss_from_pub(params->bss)); |
| 863 | ev->cr.bss = params->bss; |
| 864 | ev->cr.status = params->status; |
| 865 | ev->cr.timeout_reason = params->timeout_reason; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 866 | |
| 867 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 868 | list_add_tail(&ev->list, &wdev->event_list); |
| 869 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 870 | queue_work(cfg80211_wq, &rdev->event_work); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 871 | } |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 872 | EXPORT_SYMBOL(cfg80211_connect_done); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 873 | |
Ben Greear | 0e3a39b | 2013-06-19 14:06:27 -0700 | [diff] [blame] | 874 | /* Consumes bss object one way or another */ |
Jouni Malinen | ed9d010 | 2011-05-16 19:40:15 +0300 | [diff] [blame] | 875 | void __cfg80211_roamed(struct wireless_dev *wdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 876 | struct cfg80211_roam_info *info) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 877 | { |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 878 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 879 | union iwreq_data wrqu; |
| 880 | #endif |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 881 | ASSERT_WDEV_LOCK(wdev); |
| 882 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 883 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
| 884 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 885 | goto out; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 886 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 887 | if (WARN_ON(!wdev->current_bss)) |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 888 | goto out; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 889 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 890 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 891 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 892 | wdev->current_bss = NULL; |
| 893 | |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 894 | if (WARN_ON(!info->bss)) |
| 895 | return; |
| 896 | |
| 897 | cfg80211_hold_bss(bss_from_pub(info->bss)); |
| 898 | wdev->current_bss = bss_from_pub(info->bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 899 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 900 | nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy), |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 901 | wdev->netdev, info, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 902 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 903 | #ifdef CONFIG_CFG80211_WEXT |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 904 | if (info->req_ie) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 905 | memset(&wrqu, 0, sizeof(wrqu)); |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 906 | wrqu.data.length = info->req_ie_len; |
Zhu Yi | 3409ff7 | 2009-07-20 11:47:44 +0800 | [diff] [blame] | 907 | wireless_send_event(wdev->netdev, IWEVASSOCREQIE, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 908 | &wrqu, info->req_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 909 | } |
| 910 | |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 911 | if (info->resp_ie) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 912 | memset(&wrqu, 0, sizeof(wrqu)); |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 913 | wrqu.data.length = info->resp_ie_len; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 914 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 915 | &wrqu, info->resp_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | memset(&wrqu, 0, sizeof(wrqu)); |
| 919 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 920 | memcpy(wrqu.ap_addr.sa_data, info->bss->bssid, ETH_ALEN); |
| 921 | memcpy(wdev->wext.prev_bssid, info->bss->bssid, ETH_ALEN); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 922 | wdev->wext.prev_bssid_valid = true; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 923 | wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 924 | #endif |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 925 | |
| 926 | return; |
| 927 | out: |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 928 | cfg80211_put_bss(wdev->wiphy, info->bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 929 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 930 | |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 931 | /* Consumes info->bss object one way or another */ |
| 932 | void cfg80211_roamed(struct net_device *dev, struct cfg80211_roam_info *info, |
| 933 | gfp_t gfp) |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 934 | { |
| 935 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 936 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 937 | struct cfg80211_event *ev; |
| 938 | unsigned long flags; |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 939 | u8 *next; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 940 | |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 941 | if (!info->bss) { |
| 942 | info->bss = cfg80211_get_bss(wdev->wiphy, info->channel, |
| 943 | info->bssid, wdev->ssid, |
| 944 | wdev->ssid_len, |
| 945 | wdev->conn_bss_type, |
| 946 | IEEE80211_PRIVACY_ANY); |
| 947 | } |
| 948 | |
| 949 | if (WARN_ON(!info->bss)) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 950 | return; |
| 951 | |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 952 | ev = kzalloc(sizeof(*ev) + info->req_ie_len + info->resp_ie_len + |
| 953 | info->fils.kek_len + info->fils.pmk_len + |
| 954 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 955 | if (!ev) { |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 956 | cfg80211_put_bss(wdev->wiphy, info->bss); |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 957 | return; |
| 958 | } |
| 959 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 960 | ev->type = EVENT_ROAMED; |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 961 | next = ((u8 *)ev) + sizeof(*ev); |
| 962 | if (info->req_ie_len) { |
| 963 | ev->rm.req_ie = next; |
| 964 | ev->rm.req_ie_len = info->req_ie_len; |
| 965 | memcpy((void *)ev->rm.req_ie, info->req_ie, info->req_ie_len); |
| 966 | next += info->req_ie_len; |
| 967 | } |
| 968 | if (info->resp_ie_len) { |
| 969 | ev->rm.resp_ie = next; |
| 970 | ev->rm.resp_ie_len = info->resp_ie_len; |
| 971 | memcpy((void *)ev->rm.resp_ie, info->resp_ie, |
| 972 | info->resp_ie_len); |
| 973 | next += info->resp_ie_len; |
| 974 | } |
| 975 | if (info->fils.kek_len) { |
| 976 | ev->rm.fils.kek = next; |
| 977 | ev->rm.fils.kek_len = info->fils.kek_len; |
| 978 | memcpy((void *)ev->rm.fils.kek, info->fils.kek, |
| 979 | info->fils.kek_len); |
| 980 | next += info->fils.kek_len; |
| 981 | } |
| 982 | if (info->fils.pmk_len) { |
| 983 | ev->rm.fils.pmk = next; |
| 984 | ev->rm.fils.pmk_len = info->fils.pmk_len; |
| 985 | memcpy((void *)ev->rm.fils.pmk, info->fils.pmk, |
| 986 | info->fils.pmk_len); |
| 987 | next += info->fils.pmk_len; |
| 988 | } |
| 989 | if (info->fils.pmkid) { |
| 990 | ev->rm.fils.pmkid = next; |
| 991 | memcpy((void *)ev->rm.fils.pmkid, info->fils.pmkid, |
| 992 | WLAN_PMKID_LEN); |
| 993 | next += WLAN_PMKID_LEN; |
| 994 | } |
| 995 | ev->rm.fils.update_erp_next_seq_num = info->fils.update_erp_next_seq_num; |
| 996 | if (info->fils.update_erp_next_seq_num) |
| 997 | ev->rm.fils.erp_next_seq_num = info->fils.erp_next_seq_num; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 998 | ev->rm.bss = info->bss; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 999 | |
| 1000 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 1001 | list_add_tail(&ev->list, &wdev->event_list); |
| 1002 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 1003 | queue_work(cfg80211_wq, &rdev->event_work); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1004 | } |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 1005 | EXPORT_SYMBOL(cfg80211_roamed); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1006 | |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 1007 | void __cfg80211_port_authorized(struct wireless_dev *wdev, const u8 *bssid) |
| 1008 | { |
| 1009 | ASSERT_WDEV_LOCK(wdev); |
| 1010 | |
| 1011 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 1012 | return; |
| 1013 | |
| 1014 | if (WARN_ON(!wdev->current_bss) || |
| 1015 | WARN_ON(!ether_addr_equal(wdev->current_bss->pub.bssid, bssid))) |
| 1016 | return; |
| 1017 | |
| 1018 | nl80211_send_port_authorized(wiphy_to_rdev(wdev->wiphy), wdev->netdev, |
| 1019 | bssid); |
| 1020 | } |
| 1021 | |
| 1022 | void cfg80211_port_authorized(struct net_device *dev, const u8 *bssid, |
| 1023 | gfp_t gfp) |
| 1024 | { |
| 1025 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1026 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 1027 | struct cfg80211_event *ev; |
| 1028 | unsigned long flags; |
| 1029 | |
| 1030 | if (WARN_ON(!bssid)) |
| 1031 | return; |
| 1032 | |
| 1033 | ev = kzalloc(sizeof(*ev), gfp); |
| 1034 | if (!ev) |
| 1035 | return; |
| 1036 | |
| 1037 | ev->type = EVENT_PORT_AUTHORIZED; |
| 1038 | memcpy(ev->pa.bssid, bssid, ETH_ALEN); |
| 1039 | |
| 1040 | /* |
| 1041 | * Use the wdev event list so that if there are pending |
| 1042 | * connected/roamed events, they will be reported first. |
| 1043 | */ |
| 1044 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 1045 | list_add_tail(&ev->list, &wdev->event_list); |
| 1046 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 1047 | queue_work(cfg80211_wq, &rdev->event_work); |
| 1048 | } |
| 1049 | EXPORT_SYMBOL(cfg80211_port_authorized); |
| 1050 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1051 | void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1052 | size_t ie_len, u16 reason, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1053 | { |
| 1054 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1055 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1056 | int i; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1057 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1058 | union iwreq_data wrqu; |
| 1059 | #endif |
| 1060 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1061 | ASSERT_WDEV_LOCK(wdev); |
| 1062 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1063 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
| 1064 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1065 | return; |
| 1066 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1067 | if (wdev->current_bss) { |
| 1068 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 1069 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | wdev->current_bss = NULL; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 1073 | wdev->ssid_len = 0; |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 1074 | wdev->conn_owner_nlportid = 0; |
Avraham Stern | 3027a8e | 2018-02-19 14:48:38 +0200 | [diff] [blame] | 1075 | kzfree(wdev->connect_keys); |
| 1076 | wdev->connect_keys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1077 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1078 | nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap); |
| 1079 | |
Arend van Spriel | b860715 | 2016-02-15 14:35:53 +0100 | [diff] [blame] | 1080 | /* stop critical protocol if supported */ |
| 1081 | if (rdev->ops->crit_proto_stop && rdev->crit_proto_nlportid) { |
| 1082 | rdev->crit_proto_nlportid = 0; |
| 1083 | rdev_crit_proto_stop(rdev, wdev); |
| 1084 | } |
| 1085 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1086 | /* |
| 1087 | * Delete all the keys ... pairwise keys can't really |
| 1088 | * exist any more anyway, but default keys might. |
| 1089 | */ |
| 1090 | if (rdev->ops->del_key) |
| 1091 | for (i = 0; i < 6; i++) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1092 | rdev_del_key(rdev, dev, i, false, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1093 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 1094 | rdev_set_qos_map(rdev, dev, NULL); |
| 1095 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1096 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1097 | memset(&wrqu, 0, sizeof(wrqu)); |
| 1098 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1099 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
Abhijeet Kolekar | 5f61203 | 2010-01-13 13:23:14 -0800 | [diff] [blame] | 1100 | wdev->wext.connect.ssid_len = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1101 | #endif |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 1102 | |
| 1103 | schedule_work(&cfg80211_disconnect_work); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | void cfg80211_disconnected(struct net_device *dev, u16 reason, |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 1107 | const u8 *ie, size_t ie_len, |
| 1108 | bool locally_generated, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1109 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1110 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1111 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1112 | struct cfg80211_event *ev; |
| 1113 | unsigned long flags; |
| 1114 | |
| 1115 | ev = kzalloc(sizeof(*ev) + ie_len, gfp); |
| 1116 | if (!ev) |
| 1117 | return; |
| 1118 | |
| 1119 | ev->type = EVENT_DISCONNECTED; |
| 1120 | ev->dc.ie = ((u8 *)ev) + sizeof(*ev); |
| 1121 | ev->dc.ie_len = ie_len; |
| 1122 | memcpy((void *)ev->dc.ie, ie, ie_len); |
| 1123 | ev->dc.reason = reason; |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 1124 | ev->dc.locally_generated = locally_generated; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1125 | |
| 1126 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 1127 | list_add_tail(&ev->list, &wdev->event_list); |
| 1128 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 1129 | queue_work(cfg80211_wq, &rdev->event_work); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1130 | } |
| 1131 | EXPORT_SYMBOL(cfg80211_disconnected); |
| 1132 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1133 | /* |
| 1134 | * API calls for nl80211/wext compatibility code |
| 1135 | */ |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 1136 | int cfg80211_connect(struct cfg80211_registered_device *rdev, |
| 1137 | struct net_device *dev, |
| 1138 | struct cfg80211_connect_params *connect, |
| 1139 | struct cfg80211_cached_keys *connkeys, |
| 1140 | const u8 *prev_bssid) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1141 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1142 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1143 | int err; |
| 1144 | |
| 1145 | ASSERT_WDEV_LOCK(wdev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1146 | |
Johannes Berg | 51e1335 | 2017-10-17 21:56:20 +0200 | [diff] [blame] | 1147 | /* |
| 1148 | * If we have an ssid_len, we're trying to connect or are |
| 1149 | * already connected, so reject a new SSID unless it's the |
| 1150 | * same (which is the case for re-association.) |
| 1151 | */ |
| 1152 | if (wdev->ssid_len && |
| 1153 | (wdev->ssid_len != connect->ssid_len || |
| 1154 | memcmp(wdev->ssid, connect->ssid, wdev->ssid_len))) |
| 1155 | return -EALREADY; |
| 1156 | |
| 1157 | /* |
| 1158 | * If connected, reject (re-)association unless prev_bssid |
| 1159 | * matches the current BSSID. |
| 1160 | */ |
| 1161 | if (wdev->current_bss) { |
| 1162 | if (!prev_bssid) |
| 1163 | return -EALREADY; |
| 1164 | if (!ether_addr_equal(prev_bssid, wdev->current_bss->pub.bssid)) |
| 1165 | return -ENOTCONN; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1166 | } |
| 1167 | |
Johannes Berg | 51e1335 | 2017-10-17 21:56:20 +0200 | [diff] [blame] | 1168 | /* |
| 1169 | * Reject if we're in the process of connecting with WEP, |
| 1170 | * this case isn't very interesting and trying to handle |
| 1171 | * it would make the code much more complex. |
| 1172 | */ |
| 1173 | if (wdev->connect_keys) |
| 1174 | return -EINPROGRESS; |
| 1175 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1176 | cfg80211_oper_and_ht_capa(&connect->ht_capa_mask, |
| 1177 | rdev->wiphy.ht_capa_mod_mask); |
Sergey Matyukevich | 81c5dce | 2018-10-19 15:40:13 +0000 | [diff] [blame] | 1178 | cfg80211_oper_and_vht_capa(&connect->vht_capa_mask, |
| 1179 | rdev->wiphy.vht_capa_mod_mask); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1180 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1181 | if (connkeys && connkeys->def >= 0) { |
| 1182 | int idx; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 1183 | u32 cipher; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1184 | |
| 1185 | idx = connkeys->def; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 1186 | cipher = connkeys->params[idx].cipher; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1187 | /* 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] | 1188 | if (cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 1189 | cipher == WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1190 | connect->key_idx = idx; |
| 1191 | connect->key = connkeys->params[idx].key; |
| 1192 | connect->key_len = connkeys->params[idx].key_len; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 1193 | |
| 1194 | /* |
| 1195 | * If ciphers are not set (e.g. when going through |
| 1196 | * iwconfig), we have to set them appropriately here. |
| 1197 | */ |
| 1198 | if (connect->crypto.cipher_group == 0) |
| 1199 | connect->crypto.cipher_group = cipher; |
| 1200 | |
| 1201 | if (connect->crypto.n_ciphers_pairwise == 0) { |
| 1202 | connect->crypto.n_ciphers_pairwise = 1; |
| 1203 | connect->crypto.ciphers_pairwise[0] = cipher; |
| 1204 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1205 | } |
David Spinadel | b867622 | 2016-09-22 23:16:50 +0300 | [diff] [blame] | 1206 | |
| 1207 | connect->crypto.wep_keys = connkeys->params; |
| 1208 | connect->crypto.wep_tx_key = connkeys->def; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1209 | } else { |
| 1210 | if (WARN_ON(connkeys)) |
| 1211 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1212 | } |
| 1213 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1214 | wdev->connect_keys = connkeys; |
| 1215 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); |
| 1216 | wdev->ssid_len = connect->ssid_len; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1217 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 1218 | wdev->conn_bss_type = connect->pbss ? IEEE80211_BSS_TYPE_PBSS : |
| 1219 | IEEE80211_BSS_TYPE_ESS; |
| 1220 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1221 | if (!rdev->ops->connect) |
| 1222 | err = cfg80211_sme_connect(wdev, connect, prev_bssid); |
| 1223 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1224 | err = rdev_connect(rdev, dev, connect); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1225 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1226 | if (err) { |
| 1227 | wdev->connect_keys = NULL; |
Johannes Berg | 51e1335 | 2017-10-17 21:56:20 +0200 | [diff] [blame] | 1228 | /* |
| 1229 | * This could be reassoc getting refused, don't clear |
| 1230 | * ssid_len in that case. |
| 1231 | */ |
| 1232 | if (!wdev->current_bss) |
| 1233 | wdev->ssid_len = 0; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1234 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1235 | } |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1236 | |
| 1237 | return 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1238 | } |
| 1239 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 1240 | int cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
| 1241 | struct net_device *dev, u16 reason, bool wextev) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1242 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1243 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | dee8a97 | 2013-08-13 09:23:57 +0200 | [diff] [blame] | 1244 | int err = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1245 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1246 | ASSERT_WDEV_LOCK(wdev); |
| 1247 | |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 1248 | kzfree(wdev->connect_keys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1249 | wdev->connect_keys = NULL; |
| 1250 | |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 1251 | wdev->conn_owner_nlportid = 0; |
| 1252 | |
Johannes Berg | dee8a97 | 2013-08-13 09:23:57 +0200 | [diff] [blame] | 1253 | if (wdev->conn) |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1254 | err = cfg80211_sme_disconnect(wdev, reason); |
Johannes Berg | dee8a97 | 2013-08-13 09:23:57 +0200 | [diff] [blame] | 1255 | else if (!rdev->ops->disconnect) |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1256 | cfg80211_mlme_down(rdev, dev); |
Ilan Peer | 0711d63 | 2016-10-18 23:12:13 +0300 | [diff] [blame] | 1257 | else if (wdev->ssid_len) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1258 | err = rdev_disconnect(rdev, dev, reason); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1259 | |
Johannes Berg | 51e1335 | 2017-10-17 21:56:20 +0200 | [diff] [blame] | 1260 | /* |
| 1261 | * Clear ssid_len unless we actually were fully connected, |
| 1262 | * in which case cfg80211_disconnected() will take care of |
| 1263 | * this later. |
| 1264 | */ |
| 1265 | if (!wdev->current_bss) |
| 1266 | wdev->ssid_len = 0; |
| 1267 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1268 | return err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 1269 | } |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 1270 | |
| 1271 | /* |
| 1272 | * Used to clean up after the connection / connection attempt owner socket |
| 1273 | * disconnects |
| 1274 | */ |
| 1275 | void cfg80211_autodisconnect_wk(struct work_struct *work) |
| 1276 | { |
| 1277 | struct wireless_dev *wdev = |
| 1278 | container_of(work, struct wireless_dev, disconnect_wk); |
| 1279 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 1280 | |
| 1281 | wdev_lock(wdev); |
| 1282 | |
| 1283 | if (wdev->conn_owner_nlportid) { |
Denis Kenzior | 37b1c00 | 2018-03-26 12:52:44 -0500 | [diff] [blame] | 1284 | switch (wdev->iftype) { |
| 1285 | case NL80211_IFTYPE_ADHOC: |
| 1286 | cfg80211_leave_ibss(rdev, wdev->netdev, false); |
| 1287 | break; |
| 1288 | case NL80211_IFTYPE_AP: |
| 1289 | case NL80211_IFTYPE_P2P_GO: |
| 1290 | cfg80211_stop_ap(rdev, wdev->netdev, false); |
| 1291 | break; |
| 1292 | case NL80211_IFTYPE_MESH_POINT: |
| 1293 | cfg80211_leave_mesh(rdev, wdev->netdev); |
| 1294 | break; |
| 1295 | case NL80211_IFTYPE_STATION: |
| 1296 | case NL80211_IFTYPE_P2P_CLIENT: |
| 1297 | /* |
| 1298 | * Use disconnect_bssid if still connecting and |
| 1299 | * ops->disconnect not implemented. Otherwise we can |
| 1300 | * use cfg80211_disconnect. |
| 1301 | */ |
| 1302 | if (rdev->ops->disconnect || wdev->current_bss) |
| 1303 | cfg80211_disconnect(rdev, wdev->netdev, |
| 1304 | WLAN_REASON_DEAUTH_LEAVING, |
| 1305 | true); |
| 1306 | else |
| 1307 | cfg80211_mlme_deauth(rdev, wdev->netdev, |
| 1308 | wdev->disconnect_bssid, |
| 1309 | NULL, 0, |
| 1310 | WLAN_REASON_DEAUTH_LEAVING, |
| 1311 | false); |
| 1312 | break; |
| 1313 | default: |
| 1314 | break; |
| 1315 | } |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | wdev_unlock(wdev); |
| 1319 | } |