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