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