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