Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * SME code for cfg80211's connect emulation. |
| 3 | * |
| 4 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 5 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/etherdevice.h> |
| 9 | #include <linux/if_arp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11 | #include <linux/workqueue.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 12 | #include <linux/wireless.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 13 | #include <linux/export.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 14 | #include <net/iw_handler.h> |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15 | #include <net/cfg80211.h> |
| 16 | #include <net/rtnetlink.h> |
| 17 | #include "nl80211.h" |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 18 | #include "reg.h" |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 19 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 20 | struct cfg80211_conn { |
| 21 | struct cfg80211_connect_params params; |
| 22 | /* these are sub-states of the _CONNECTING sme_state */ |
| 23 | enum { |
| 24 | CFG80211_CONN_IDLE, |
| 25 | CFG80211_CONN_SCANNING, |
| 26 | CFG80211_CONN_SCAN_AGAIN, |
| 27 | CFG80211_CONN_AUTHENTICATE_NEXT, |
| 28 | CFG80211_CONN_AUTHENTICATING, |
| 29 | CFG80211_CONN_ASSOCIATE_NEXT, |
| 30 | CFG80211_CONN_ASSOCIATING, |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 31 | CFG80211_CONN_DEAUTH_ASSOC_FAIL, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 32 | } state; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 33 | u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN]; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 34 | u8 *ie; |
| 35 | size_t ie_len; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 36 | bool auto_auth, prev_bssid_valid; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 37 | }; |
| 38 | |
John W. Linville | 20925fe | 2010-07-20 12:32:52 -0400 | [diff] [blame] | 39 | static bool cfg80211_is_all_idle(void) |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 40 | { |
| 41 | struct cfg80211_registered_device *rdev; |
| 42 | struct wireless_dev *wdev; |
| 43 | bool is_all_idle = true; |
| 44 | |
| 45 | mutex_lock(&cfg80211_mutex); |
| 46 | |
| 47 | /* |
| 48 | * All devices must be idle as otherwise if you are actively |
| 49 | * scanning some new beacon hints could be learned and would |
| 50 | * count as new regulatory hints. |
| 51 | */ |
| 52 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 53 | cfg80211_lock_rdev(rdev); |
| 54 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
| 55 | wdev_lock(wdev); |
| 56 | if (wdev->sme_state != CFG80211_SME_IDLE) |
| 57 | is_all_idle = false; |
| 58 | wdev_unlock(wdev); |
| 59 | } |
| 60 | cfg80211_unlock_rdev(rdev); |
| 61 | } |
| 62 | |
| 63 | mutex_unlock(&cfg80211_mutex); |
| 64 | |
| 65 | return is_all_idle; |
| 66 | } |
| 67 | |
| 68 | static void disconnect_work(struct work_struct *work) |
| 69 | { |
| 70 | if (!cfg80211_is_all_idle()) |
| 71 | return; |
| 72 | |
| 73 | regulatory_hint_disconnect(); |
| 74 | } |
| 75 | |
| 76 | static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 77 | |
| 78 | static int cfg80211_conn_scan(struct wireless_dev *wdev) |
| 79 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 80 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 81 | struct cfg80211_scan_request *request; |
| 82 | int n_channels, err; |
| 83 | |
| 84 | ASSERT_RTNL(); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 85 | ASSERT_RDEV_LOCK(rdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 86 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 87 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 88 | if (rdev->scan_req) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 89 | return -EBUSY; |
| 90 | |
| 91 | if (wdev->conn->params.channel) { |
| 92 | n_channels = 1; |
| 93 | } else { |
| 94 | enum ieee80211_band band; |
| 95 | n_channels = 0; |
| 96 | |
| 97 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 98 | if (!wdev->wiphy->bands[band]) |
| 99 | continue; |
| 100 | n_channels += wdev->wiphy->bands[band]->n_channels; |
| 101 | } |
| 102 | } |
| 103 | request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) + |
| 104 | sizeof(request->channels[0]) * n_channels, |
| 105 | GFP_KERNEL); |
| 106 | if (!request) |
| 107 | return -ENOMEM; |
| 108 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 109 | if (wdev->conn->params.channel) |
| 110 | request->channels[0] = wdev->conn->params.channel; |
| 111 | else { |
| 112 | int i = 0, j; |
| 113 | enum ieee80211_band band; |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 114 | struct ieee80211_supported_band *bands; |
| 115 | struct ieee80211_channel *channel; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 116 | |
| 117 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 118 | bands = wdev->wiphy->bands[band]; |
| 119 | if (!bands) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 120 | continue; |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 121 | for (j = 0; j < bands->n_channels; j++) { |
| 122 | channel = &bands->channels[j]; |
| 123 | if (channel->flags & IEEE80211_CHAN_DISABLED) |
| 124 | continue; |
| 125 | request->channels[i++] = channel; |
| 126 | } |
| 127 | request->rates[band] = (1 << bands->n_bitrates) - 1; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 128 | } |
Rajkumar Manoharan | e308150 | 2011-09-15 17:40:50 +0530 | [diff] [blame] | 129 | n_channels = i; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 130 | } |
| 131 | request->n_channels = n_channels; |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 132 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 133 | request->n_ssids = 1; |
| 134 | |
| 135 | memcpy(request->ssids[0].ssid, wdev->conn->params.ssid, |
| 136 | wdev->conn->params.ssid_len); |
| 137 | request->ssids[0].ssid_len = wdev->conn->params.ssid_len; |
| 138 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 139 | request->dev = wdev->netdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 140 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 141 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 142 | rdev->scan_req = request; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 143 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 144 | err = rdev->ops->scan(wdev->wiphy, wdev->netdev, request); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 145 | if (!err) { |
| 146 | wdev->conn->state = CFG80211_CONN_SCANNING; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 147 | nl80211_send_scan_start(rdev, wdev->netdev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 148 | dev_hold(wdev->netdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 149 | } else { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 150 | rdev->scan_req = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 151 | kfree(request); |
| 152 | } |
| 153 | return err; |
| 154 | } |
| 155 | |
| 156 | static int cfg80211_conn_do_work(struct wireless_dev *wdev) |
| 157 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 158 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 159 | struct cfg80211_connect_params *params; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 160 | const u8 *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 161 | int err; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 162 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 163 | ASSERT_WDEV_LOCK(wdev); |
| 164 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 165 | if (!wdev->conn) |
| 166 | return 0; |
| 167 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 168 | params = &wdev->conn->params; |
| 169 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 170 | switch (wdev->conn->state) { |
| 171 | case CFG80211_CONN_SCAN_AGAIN: |
| 172 | return cfg80211_conn_scan(wdev); |
| 173 | case CFG80211_CONN_AUTHENTICATE_NEXT: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 174 | BUG_ON(!rdev->ops->auth); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 175 | wdev->conn->state = CFG80211_CONN_AUTHENTICATING; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 176 | return __cfg80211_mlme_auth(rdev, wdev->netdev, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 177 | params->channel, params->auth_type, |
| 178 | params->bssid, |
| 179 | params->ssid, params->ssid_len, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 180 | NULL, 0, |
| 181 | params->key, params->key_len, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 182 | params->key_idx); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 183 | case CFG80211_CONN_ASSOCIATE_NEXT: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 184 | BUG_ON(!rdev->ops->assoc); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 185 | wdev->conn->state = CFG80211_CONN_ASSOCIATING; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 186 | if (wdev->conn->prev_bssid_valid) |
| 187 | prev_bssid = wdev->conn->prev_bssid; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 188 | err = __cfg80211_mlme_assoc(rdev, wdev->netdev, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 189 | params->channel, params->bssid, |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 190 | prev_bssid, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 191 | params->ssid, params->ssid_len, |
| 192 | params->ie, params->ie_len, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 193 | false, ¶ms->crypto, |
| 194 | params->flags, ¶ms->ht_capa, |
| 195 | ¶ms->ht_capa_mask); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 196 | if (err) |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 197 | __cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 198 | NULL, 0, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 199 | WLAN_REASON_DEAUTH_LEAVING, |
| 200 | false); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 201 | return err; |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 202 | case CFG80211_CONN_DEAUTH_ASSOC_FAIL: |
| 203 | __cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
| 204 | NULL, 0, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 205 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 206 | /* return an error so that we call __cfg80211_connect_result() */ |
| 207 | return -EINVAL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 208 | default: |
| 209 | return 0; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | void cfg80211_conn_work(struct work_struct *work) |
| 214 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 215 | struct cfg80211_registered_device *rdev = |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 216 | container_of(work, struct cfg80211_registered_device, conn_work); |
| 217 | struct wireless_dev *wdev; |
Johannes Berg | 7400f42 | 2009-10-31 07:40:37 +0100 | [diff] [blame] | 218 | u8 bssid_buf[ETH_ALEN], *bssid = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 219 | |
| 220 | rtnl_lock(); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 221 | cfg80211_lock_rdev(rdev); |
| 222 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 223 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 224 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 225 | wdev_lock(wdev); |
| 226 | if (!netif_running(wdev->netdev)) { |
| 227 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 228 | continue; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 229 | } |
| 230 | if (wdev->sme_state != CFG80211_SME_CONNECTING) { |
| 231 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 232 | continue; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 233 | } |
Johannes Berg | 7400f42 | 2009-10-31 07:40:37 +0100 | [diff] [blame] | 234 | if (wdev->conn->params.bssid) { |
| 235 | memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN); |
| 236 | bssid = bssid_buf; |
| 237 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 238 | if (cfg80211_conn_do_work(wdev)) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 239 | __cfg80211_connect_result( |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 240 | wdev->netdev, bssid, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 241 | NULL, 0, NULL, 0, |
| 242 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 243 | false, NULL); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 244 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 245 | } |
| 246 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 247 | mutex_unlock(&rdev->devlist_mtx); |
| 248 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 249 | rtnl_unlock(); |
| 250 | } |
| 251 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 252 | static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 253 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 254 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 255 | struct cfg80211_bss *bss; |
| 256 | u16 capa = WLAN_CAPABILITY_ESS; |
| 257 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 258 | ASSERT_WDEV_LOCK(wdev); |
| 259 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 260 | if (wdev->conn->params.privacy) |
| 261 | capa |= WLAN_CAPABILITY_PRIVACY; |
| 262 | |
Jouni Malinen | ed9d010 | 2011-05-16 19:40:15 +0300 | [diff] [blame] | 263 | bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel, |
| 264 | wdev->conn->params.bssid, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 265 | wdev->conn->params.ssid, |
| 266 | wdev->conn->params.ssid_len, |
| 267 | WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY, |
| 268 | capa); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 269 | if (!bss) |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 270 | return NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 271 | |
| 272 | memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN); |
| 273 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 274 | wdev->conn->params.channel = bss->channel; |
| 275 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 276 | schedule_work(&rdev->conn_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 277 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 278 | return bss; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 281 | static void __cfg80211_sme_scan_done(struct net_device *dev) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 282 | { |
| 283 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 284 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 285 | struct cfg80211_bss *bss; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 286 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 287 | ASSERT_WDEV_LOCK(wdev); |
| 288 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 289 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
| 290 | return; |
| 291 | |
Zhu Yi | d4b1a68 | 2009-07-16 17:34:14 +0800 | [diff] [blame] | 292 | if (!wdev->conn) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 293 | return; |
| 294 | |
| 295 | if (wdev->conn->state != CFG80211_CONN_SCANNING && |
| 296 | wdev->conn->state != CFG80211_CONN_SCAN_AGAIN) |
| 297 | return; |
| 298 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 299 | bss = cfg80211_get_conn_bss(wdev); |
| 300 | if (bss) { |
| 301 | cfg80211_put_bss(bss); |
| 302 | } else { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 303 | /* not found */ |
| 304 | if (wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 305 | schedule_work(&rdev->conn_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 306 | else |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 307 | __cfg80211_connect_result( |
| 308 | wdev->netdev, |
| 309 | wdev->conn->params.bssid, |
| 310 | NULL, 0, NULL, 0, |
| 311 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 312 | false, NULL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 316 | void cfg80211_sme_scan_done(struct net_device *dev) |
| 317 | { |
| 318 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 319 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 320 | mutex_lock(&wiphy_to_dev(wdev->wiphy)->devlist_mtx); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 321 | wdev_lock(wdev); |
| 322 | __cfg80211_sme_scan_done(dev); |
| 323 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 324 | mutex_unlock(&wiphy_to_dev(wdev->wiphy)->devlist_mtx); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | void cfg80211_sme_rx_auth(struct net_device *dev, |
| 328 | const u8 *buf, size_t len) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 329 | { |
| 330 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 331 | struct wiphy *wiphy = wdev->wiphy; |
| 332 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 333 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 334 | u16 status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 335 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 336 | ASSERT_WDEV_LOCK(wdev); |
| 337 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 338 | /* should only RX auth frames when connecting */ |
| 339 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
| 340 | return; |
| 341 | |
| 342 | if (WARN_ON(!wdev->conn)) |
| 343 | return; |
| 344 | |
| 345 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG && |
| 346 | wdev->conn->auto_auth && |
| 347 | wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) { |
| 348 | /* select automatically between only open, shared, leap */ |
| 349 | switch (wdev->conn->params.auth_type) { |
| 350 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 351 | if (wdev->connect_keys) |
| 352 | wdev->conn->params.auth_type = |
| 353 | NL80211_AUTHTYPE_SHARED_KEY; |
| 354 | else |
| 355 | wdev->conn->params.auth_type = |
| 356 | NL80211_AUTHTYPE_NETWORK_EAP; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 357 | break; |
| 358 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 359 | wdev->conn->params.auth_type = |
| 360 | NL80211_AUTHTYPE_NETWORK_EAP; |
| 361 | break; |
| 362 | default: |
| 363 | /* huh? */ |
| 364 | wdev->conn->params.auth_type = |
| 365 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 366 | break; |
| 367 | } |
| 368 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 369 | schedule_work(&rdev->conn_work); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 370 | } else if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | 4bde0f7 | 2009-07-07 23:46:51 +0200 | [diff] [blame] | 371 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 372 | status_code, false, NULL); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 373 | } else if (wdev->sme_state == CFG80211_SME_CONNECTING && |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 374 | wdev->conn->state == CFG80211_CONN_AUTHENTICATING) { |
| 375 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 376 | schedule_work(&rdev->conn_work); |
| 377 | } |
| 378 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 379 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 380 | bool cfg80211_sme_failed_reassoc(struct wireless_dev *wdev) |
| 381 | { |
| 382 | struct wiphy *wiphy = wdev->wiphy; |
| 383 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 384 | |
| 385 | if (WARN_ON(!wdev->conn)) |
| 386 | return false; |
| 387 | |
| 388 | if (!wdev->conn->prev_bssid_valid) |
| 389 | return false; |
| 390 | |
| 391 | /* |
| 392 | * Some stupid APs don't accept reassoc, so we |
| 393 | * need to fall back to trying regular assoc. |
| 394 | */ |
| 395 | wdev->conn->prev_bssid_valid = false; |
| 396 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 397 | schedule_work(&rdev->conn_work); |
| 398 | |
| 399 | return true; |
| 400 | } |
| 401 | |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 402 | void cfg80211_sme_failed_assoc(struct wireless_dev *wdev) |
| 403 | { |
| 404 | struct wiphy *wiphy = wdev->wiphy; |
| 405 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 406 | |
| 407 | wdev->conn->state = CFG80211_CONN_DEAUTH_ASSOC_FAIL; |
| 408 | schedule_work(&rdev->conn_work); |
| 409 | } |
| 410 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 411 | void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 412 | const u8 *req_ie, size_t req_ie_len, |
| 413 | const u8 *resp_ie, size_t resp_ie_len, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 414 | u16 status, bool wextev, |
| 415 | struct cfg80211_bss *bss) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 416 | { |
| 417 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 418 | u8 *country_ie; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 419 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 420 | union iwreq_data wrqu; |
| 421 | #endif |
| 422 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 423 | ASSERT_WDEV_LOCK(wdev); |
| 424 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 425 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
| 426 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 427 | return; |
| 428 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 429 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
Johannes Berg | ea416a7 | 2009-08-17 12:22:14 +0200 | [diff] [blame] | 430 | return; |
| 431 | |
| 432 | nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev, |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 433 | bssid, req_ie, req_ie_len, |
Johannes Berg | ea416a7 | 2009-08-17 12:22:14 +0200 | [diff] [blame] | 434 | resp_ie, resp_ie_len, |
| 435 | status, GFP_KERNEL); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 436 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 437 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 438 | if (wextev) { |
| 439 | if (req_ie && status == WLAN_STATUS_SUCCESS) { |
| 440 | memset(&wrqu, 0, sizeof(wrqu)); |
| 441 | wrqu.data.length = req_ie_len; |
Zhu Yi | 3409ff7 | 2009-07-20 11:47:44 +0800 | [diff] [blame] | 442 | wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | if (resp_ie && status == WLAN_STATUS_SUCCESS) { |
| 446 | memset(&wrqu, 0, sizeof(wrqu)); |
| 447 | wrqu.data.length = resp_ie_len; |
| 448 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie); |
| 449 | } |
| 450 | |
| 451 | memset(&wrqu, 0, sizeof(wrqu)); |
| 452 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 453 | if (bssid && status == WLAN_STATUS_SUCCESS) { |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 454 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 455 | memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN); |
| 456 | wdev->wext.prev_bssid_valid = true; |
| 457 | } |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 458 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 459 | } |
| 460 | #endif |
| 461 | |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 462 | if (wdev->current_bss) { |
| 463 | cfg80211_unhold_bss(wdev->current_bss); |
| 464 | cfg80211_put_bss(&wdev->current_bss->pub); |
| 465 | wdev->current_bss = NULL; |
| 466 | } |
| 467 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 468 | if (wdev->conn) |
| 469 | wdev->conn->state = CFG80211_CONN_IDLE; |
| 470 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 471 | if (status != WLAN_STATUS_SUCCESS) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 472 | wdev->sme_state = CFG80211_SME_IDLE; |
David Kilroy | 415ad1ef | 2009-08-19 00:43:31 +0100 | [diff] [blame] | 473 | if (wdev->conn) |
| 474 | kfree(wdev->conn->ie); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 475 | kfree(wdev->conn); |
| 476 | wdev->conn = NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 477 | kfree(wdev->connect_keys); |
| 478 | wdev->connect_keys = NULL; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 479 | wdev->ssid_len = 0; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 480 | cfg80211_put_bss(bss); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 481 | return; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 482 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 483 | |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 484 | if (!bss) |
Jouni Malinen | ed9d010 | 2011-05-16 19:40:15 +0300 | [diff] [blame] | 485 | bss = cfg80211_get_bss(wdev->wiphy, |
| 486 | wdev->conn ? wdev->conn->params.channel : |
| 487 | NULL, |
| 488 | bssid, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 489 | wdev->ssid, wdev->ssid_len, |
| 490 | WLAN_CAPABILITY_ESS, |
| 491 | WLAN_CAPABILITY_ESS); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 492 | |
| 493 | if (WARN_ON(!bss)) |
| 494 | return; |
| 495 | |
| 496 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 497 | wdev->current_bss = bss_from_pub(bss); |
| 498 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 499 | wdev->sme_state = CFG80211_SME_CONNECTED; |
| 500 | cfg80211_upload_connect_keys(wdev); |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 501 | |
| 502 | country_ie = (u8 *) ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY); |
| 503 | |
| 504 | if (!country_ie) |
| 505 | return; |
| 506 | |
| 507 | /* |
| 508 | * ieee80211_bss_get_ie() ensures we can access: |
| 509 | * - country_ie + 2, the start of the country ie data, and |
| 510 | * - and country_ie[1] which is the IE length |
| 511 | */ |
| 512 | regulatory_hint_11d(wdev->wiphy, |
Luis R. Rodriguez | 84920e3 | 2010-01-14 20:08:20 -0500 | [diff] [blame] | 513 | bss->channel->band, |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 514 | country_ie + 2, |
| 515 | country_ie[1]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 516 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 517 | |
| 518 | void cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 519 | const u8 *req_ie, size_t req_ie_len, |
| 520 | const u8 *resp_ie, size_t resp_ie_len, |
| 521 | u16 status, gfp_t gfp) |
| 522 | { |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 523 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 524 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 525 | struct cfg80211_event *ev; |
| 526 | unsigned long flags; |
| 527 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 528 | CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTING); |
| 529 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 530 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 531 | if (!ev) |
| 532 | return; |
| 533 | |
| 534 | ev->type = EVENT_CONNECT_RESULT; |
Zhu Yi | 16a832e | 2009-08-19 16:08:22 +0800 | [diff] [blame] | 535 | if (bssid) |
| 536 | memcpy(ev->cr.bssid, bssid, ETH_ALEN); |
Nishant Sarmukadam | 7834704b | 2010-04-14 22:03:02 -0700 | [diff] [blame] | 537 | if (req_ie_len) { |
| 538 | ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 539 | ev->cr.req_ie_len = req_ie_len; |
| 540 | memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len); |
| 541 | } |
| 542 | if (resp_ie_len) { |
| 543 | ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 544 | ev->cr.resp_ie_len = resp_ie_len; |
| 545 | memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len); |
| 546 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 547 | ev->cr.status = status; |
| 548 | |
| 549 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 550 | list_add_tail(&ev->list, &wdev->event_list); |
| 551 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 552 | queue_work(cfg80211_wq, &rdev->event_work); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 553 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 554 | EXPORT_SYMBOL(cfg80211_connect_result); |
| 555 | |
Jouni Malinen | ed9d010 | 2011-05-16 19:40:15 +0300 | [diff] [blame] | 556 | void __cfg80211_roamed(struct wireless_dev *wdev, |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 557 | struct cfg80211_bss *bss, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 558 | const u8 *req_ie, size_t req_ie_len, |
| 559 | const u8 *resp_ie, size_t resp_ie_len) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 560 | { |
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 |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 564 | ASSERT_WDEV_LOCK(wdev); |
| 565 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 566 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
| 567 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 568 | goto out; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 569 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 570 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 571 | goto out; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 572 | |
| 573 | /* internal error -- how did we get to CONNECTED w/o BSS? */ |
| 574 | if (WARN_ON(!wdev->current_bss)) { |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 575 | goto out; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 579 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 580 | wdev->current_bss = NULL; |
| 581 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 582 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 583 | wdev->current_bss = bss_from_pub(bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 584 | |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 585 | nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), wdev->netdev, bss->bssid, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 586 | req_ie, req_ie_len, resp_ie, resp_ie_len, |
| 587 | GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 588 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 589 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 590 | if (req_ie) { |
| 591 | memset(&wrqu, 0, sizeof(wrqu)); |
| 592 | wrqu.data.length = req_ie_len; |
Zhu Yi | 3409ff7 | 2009-07-20 11:47:44 +0800 | [diff] [blame] | 593 | wireless_send_event(wdev->netdev, IWEVASSOCREQIE, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 594 | &wrqu, req_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | if (resp_ie) { |
| 598 | memset(&wrqu, 0, sizeof(wrqu)); |
| 599 | wrqu.data.length = resp_ie_len; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 600 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, |
| 601 | &wrqu, resp_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | memset(&wrqu, 0, sizeof(wrqu)); |
| 605 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 606 | memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN); |
| 607 | memcpy(wdev->wext.prev_bssid, bss->bssid, ETH_ALEN); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 608 | wdev->wext.prev_bssid_valid = true; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 609 | wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 610 | #endif |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 611 | |
| 612 | return; |
| 613 | out: |
| 614 | cfg80211_put_bss(bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 615 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 616 | |
Jouni Malinen | ed9d010 | 2011-05-16 19:40:15 +0300 | [diff] [blame] | 617 | void cfg80211_roamed(struct net_device *dev, |
| 618 | struct ieee80211_channel *channel, |
| 619 | const u8 *bssid, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 620 | const u8 *req_ie, size_t req_ie_len, |
| 621 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 622 | { |
| 623 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 624 | struct cfg80211_bss *bss; |
| 625 | |
| 626 | CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED); |
| 627 | |
| 628 | bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid, |
| 629 | wdev->ssid_len, WLAN_CAPABILITY_ESS, |
| 630 | WLAN_CAPABILITY_ESS); |
| 631 | if (WARN_ON(!bss)) |
| 632 | return; |
| 633 | |
| 634 | cfg80211_roamed_bss(dev, bss, req_ie, req_ie_len, resp_ie, |
| 635 | resp_ie_len, gfp); |
| 636 | } |
| 637 | EXPORT_SYMBOL(cfg80211_roamed); |
| 638 | |
| 639 | void cfg80211_roamed_bss(struct net_device *dev, |
| 640 | struct cfg80211_bss *bss, const u8 *req_ie, |
| 641 | size_t req_ie_len, const u8 *resp_ie, |
| 642 | size_t resp_ie_len, gfp_t gfp) |
| 643 | { |
| 644 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 645 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 646 | struct cfg80211_event *ev; |
| 647 | unsigned long flags; |
| 648 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 649 | CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED); |
| 650 | |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 651 | if (WARN_ON(!bss)) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 652 | return; |
| 653 | |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 654 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 655 | if (!ev) { |
| 656 | cfg80211_put_bss(bss); |
| 657 | return; |
| 658 | } |
| 659 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 660 | ev->type = EVENT_ROAMED; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 661 | ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 662 | ev->rm.req_ie_len = req_ie_len; |
| 663 | memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len); |
| 664 | ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 665 | ev->rm.resp_ie_len = resp_ie_len; |
| 666 | memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len); |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 667 | ev->rm.bss = bss; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 668 | |
| 669 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 670 | list_add_tail(&ev->list, &wdev->event_list); |
| 671 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 672 | queue_work(cfg80211_wq, &rdev->event_work); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 673 | } |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 674 | EXPORT_SYMBOL(cfg80211_roamed_bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 675 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 676 | void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 677 | size_t ie_len, u16 reason, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 678 | { |
| 679 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 680 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 681 | int i; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 682 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 683 | union iwreq_data wrqu; |
| 684 | #endif |
| 685 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 686 | ASSERT_WDEV_LOCK(wdev); |
| 687 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 688 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
| 689 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 690 | return; |
| 691 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 692 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 693 | return; |
| 694 | |
| 695 | if (wdev->current_bss) { |
| 696 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 697 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | wdev->current_bss = NULL; |
| 701 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 702 | wdev->ssid_len = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 703 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 704 | if (wdev->conn) { |
| 705 | kfree(wdev->conn->ie); |
| 706 | wdev->conn->ie = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 707 | kfree(wdev->conn); |
| 708 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 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 | 667503dd | 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 | 667503dd | 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 | 667503dd | 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 | 667503dd | 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 | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 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 | 667503dd | 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 | 667503dd | 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 | 667503dd | 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 | 667503dd | 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 | 667503dd | 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 | 6829c87 | 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 | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 931 | ASSERT_WDEV_LOCK(wdev); |
| 932 | |
Johannes Berg | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 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 | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 957 | return 0; |
| 958 | } |
| 959 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 960 | /* wdev->conn->params.bssid must be set if > SCANNING */ |
Johannes Berg | 667503dd | 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 | 6829c87 | 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 | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 972 | if (wdev->sme_state == CFG80211_SME_CONNECTED) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 973 | __cfg80211_disconnected(dev, NULL, 0, 0, false); |
Johannes Berg | 6829c87 | 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 | 667503dd | 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 | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 995 | void cfg80211_sme_disassoc(struct net_device *dev, |
| 996 | struct cfg80211_internal_bss *bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 997 | { |
| 998 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 999 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 1000 | u8 bssid[ETH_ALEN]; |
| 1001 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1002 | ASSERT_WDEV_LOCK(wdev); |
| 1003 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 1004 | if (!wdev->conn) |
| 1005 | return; |
| 1006 | |
| 1007 | if (wdev->conn->state == CFG80211_CONN_IDLE) |
| 1008 | return; |
| 1009 | |
| 1010 | /* |
| 1011 | * Ok, so the association was made by this SME -- we don't |
| 1012 | * want it any more so deauthenticate too. |
| 1013 | */ |
| 1014 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 1015 | memcpy(bssid, bss->pub.bssid, ETH_ALEN); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 1016 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 1017 | __cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0, |
| 1018 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 1019 | } |