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