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