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