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