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