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