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