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> |
| 10 | #include <linux/workqueue.h> |
| 11 | #include <net/cfg80211.h> |
| 12 | #include <net/rtnetlink.h> |
| 13 | #include "nl80211.h" |
| 14 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 15 | struct cfg80211_conn { |
| 16 | struct cfg80211_connect_params params; |
| 17 | /* these are sub-states of the _CONNECTING sme_state */ |
| 18 | enum { |
| 19 | CFG80211_CONN_IDLE, |
| 20 | CFG80211_CONN_SCANNING, |
| 21 | CFG80211_CONN_SCAN_AGAIN, |
| 22 | CFG80211_CONN_AUTHENTICATE_NEXT, |
| 23 | CFG80211_CONN_AUTHENTICATING, |
| 24 | CFG80211_CONN_ASSOCIATE_NEXT, |
| 25 | CFG80211_CONN_ASSOCIATING, |
| 26 | } state; |
| 27 | u8 bssid[ETH_ALEN]; |
| 28 | u8 *ie; |
| 29 | size_t ie_len; |
| 30 | bool auto_auth; |
| 31 | }; |
| 32 | |
| 33 | |
| 34 | static int cfg80211_conn_scan(struct wireless_dev *wdev) |
| 35 | { |
| 36 | struct cfg80211_registered_device *drv = wiphy_to_dev(wdev->wiphy); |
| 37 | struct cfg80211_scan_request *request; |
| 38 | int n_channels, err; |
| 39 | |
| 40 | ASSERT_RTNL(); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 41 | ASSERT_RDEV_LOCK(drv); |
| 42 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 43 | |
| 44 | if (drv->scan_req) |
| 45 | return -EBUSY; |
| 46 | |
| 47 | if (wdev->conn->params.channel) { |
| 48 | n_channels = 1; |
| 49 | } else { |
| 50 | enum ieee80211_band band; |
| 51 | n_channels = 0; |
| 52 | |
| 53 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 54 | if (!wdev->wiphy->bands[band]) |
| 55 | continue; |
| 56 | n_channels += wdev->wiphy->bands[band]->n_channels; |
| 57 | } |
| 58 | } |
| 59 | request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) + |
| 60 | sizeof(request->channels[0]) * n_channels, |
| 61 | GFP_KERNEL); |
| 62 | if (!request) |
| 63 | return -ENOMEM; |
| 64 | |
| 65 | request->channels = (void *)((char *)request + sizeof(*request)); |
| 66 | if (wdev->conn->params.channel) |
| 67 | request->channels[0] = wdev->conn->params.channel; |
| 68 | else { |
| 69 | int i = 0, j; |
| 70 | enum ieee80211_band band; |
| 71 | |
| 72 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 73 | if (!wdev->wiphy->bands[band]) |
| 74 | continue; |
| 75 | for (j = 0; j < wdev->wiphy->bands[band]->n_channels; |
| 76 | i++, j++) |
| 77 | request->channels[i] = |
| 78 | &wdev->wiphy->bands[band]->channels[j]; |
| 79 | } |
| 80 | } |
| 81 | request->n_channels = n_channels; |
| 82 | request->ssids = (void *)(request->channels + n_channels); |
| 83 | request->n_ssids = 1; |
| 84 | |
| 85 | memcpy(request->ssids[0].ssid, wdev->conn->params.ssid, |
| 86 | wdev->conn->params.ssid_len); |
| 87 | request->ssids[0].ssid_len = wdev->conn->params.ssid_len; |
| 88 | |
| 89 | request->ifidx = wdev->netdev->ifindex; |
| 90 | request->wiphy = &drv->wiphy; |
| 91 | |
| 92 | drv->scan_req = request; |
| 93 | |
| 94 | err = drv->ops->scan(wdev->wiphy, wdev->netdev, request); |
| 95 | if (!err) { |
| 96 | wdev->conn->state = CFG80211_CONN_SCANNING; |
| 97 | nl80211_send_scan_start(drv, wdev->netdev); |
| 98 | } else { |
| 99 | drv->scan_req = NULL; |
| 100 | kfree(request); |
| 101 | } |
| 102 | return err; |
| 103 | } |
| 104 | |
| 105 | static int cfg80211_conn_do_work(struct wireless_dev *wdev) |
| 106 | { |
| 107 | struct cfg80211_registered_device *drv = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 108 | struct cfg80211_connect_params *params; |
| 109 | int err; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 110 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 111 | ASSERT_WDEV_LOCK(wdev); |
| 112 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 113 | if (!wdev->conn) |
| 114 | return 0; |
| 115 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 116 | params = &wdev->conn->params; |
| 117 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 118 | switch (wdev->conn->state) { |
| 119 | case CFG80211_CONN_SCAN_AGAIN: |
| 120 | return cfg80211_conn_scan(wdev); |
| 121 | case CFG80211_CONN_AUTHENTICATE_NEXT: |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 122 | BUG_ON(!drv->ops->auth); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 123 | wdev->conn->state = CFG80211_CONN_AUTHENTICATING; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 124 | return __cfg80211_mlme_auth(drv, wdev->netdev, |
| 125 | params->channel, params->auth_type, |
| 126 | params->bssid, |
| 127 | params->ssid, params->ssid_len, |
| 128 | NULL, 0); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 129 | case CFG80211_CONN_ASSOCIATE_NEXT: |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 130 | BUG_ON(!drv->ops->assoc); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 131 | wdev->conn->state = CFG80211_CONN_ASSOCIATING; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 132 | /* |
| 133 | * We could, later, implement roaming here and then actually |
| 134 | * set prev_bssid to non-NULL. But then we need to be aware |
| 135 | * that some APs don't like that -- so we'd need to retry |
| 136 | * the association. |
| 137 | */ |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 138 | err = __cfg80211_mlme_assoc(drv, wdev->netdev, |
| 139 | params->channel, params->bssid, |
| 140 | NULL, |
| 141 | params->ssid, params->ssid_len, |
| 142 | params->ie, params->ie_len, |
| 143 | false, ¶ms->crypto); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 144 | if (err) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 145 | __cfg80211_mlme_deauth(drv, wdev->netdev, params->bssid, |
| 146 | NULL, 0, |
| 147 | WLAN_REASON_DEAUTH_LEAVING); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 148 | return err; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 149 | default: |
| 150 | return 0; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | void cfg80211_conn_work(struct work_struct *work) |
| 155 | { |
| 156 | struct cfg80211_registered_device *drv = |
| 157 | container_of(work, struct cfg80211_registered_device, conn_work); |
| 158 | struct wireless_dev *wdev; |
| 159 | |
| 160 | rtnl_lock(); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 161 | cfg80211_lock_rdev(drv); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 162 | mutex_lock(&drv->devlist_mtx); |
| 163 | |
| 164 | list_for_each_entry(wdev, &drv->netdev_list, list) { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 165 | wdev_lock(wdev); |
| 166 | if (!netif_running(wdev->netdev)) { |
| 167 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 168 | continue; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 169 | } |
| 170 | if (wdev->sme_state != CFG80211_SME_CONNECTING) { |
| 171 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 172 | continue; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 173 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 174 | if (cfg80211_conn_do_work(wdev)) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 175 | __cfg80211_connect_result( |
| 176 | wdev->netdev, |
| 177 | wdev->conn->params.bssid, |
| 178 | NULL, 0, NULL, 0, |
| 179 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 180 | false); |
| 181 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | mutex_unlock(&drv->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 185 | cfg80211_unlock_rdev(drv); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 186 | rtnl_unlock(); |
| 187 | } |
| 188 | |
| 189 | static bool cfg80211_get_conn_bss(struct wireless_dev *wdev) |
| 190 | { |
| 191 | struct cfg80211_registered_device *drv = wiphy_to_dev(wdev->wiphy); |
| 192 | struct cfg80211_bss *bss; |
| 193 | u16 capa = WLAN_CAPABILITY_ESS; |
| 194 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 195 | ASSERT_WDEV_LOCK(wdev); |
| 196 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 197 | if (wdev->conn->params.privacy) |
| 198 | capa |= WLAN_CAPABILITY_PRIVACY; |
| 199 | |
| 200 | bss = cfg80211_get_bss(wdev->wiphy, NULL, wdev->conn->params.bssid, |
| 201 | wdev->conn->params.ssid, |
| 202 | wdev->conn->params.ssid_len, |
| 203 | WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY, |
| 204 | capa); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 205 | if (!bss) |
| 206 | return false; |
| 207 | |
| 208 | memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN); |
| 209 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 210 | wdev->conn->params.channel = bss->channel; |
| 211 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 212 | schedule_work(&drv->conn_work); |
| 213 | |
| 214 | cfg80211_put_bss(bss); |
| 215 | return true; |
| 216 | } |
| 217 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 218 | static void __cfg80211_sme_scan_done(struct net_device *dev) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 219 | { |
| 220 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 221 | struct cfg80211_registered_device *drv = wiphy_to_dev(wdev->wiphy); |
| 222 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 223 | ASSERT_WDEV_LOCK(wdev); |
| 224 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 225 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
| 226 | return; |
| 227 | |
| 228 | if (WARN_ON(!wdev->conn)) |
| 229 | return; |
| 230 | |
| 231 | if (wdev->conn->state != CFG80211_CONN_SCANNING && |
| 232 | wdev->conn->state != CFG80211_CONN_SCAN_AGAIN) |
| 233 | return; |
| 234 | |
| 235 | if (!cfg80211_get_conn_bss(wdev)) { |
| 236 | /* not found */ |
| 237 | if (wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) |
| 238 | schedule_work(&drv->conn_work); |
| 239 | else |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 240 | __cfg80211_connect_result( |
| 241 | wdev->netdev, |
| 242 | wdev->conn->params.bssid, |
| 243 | NULL, 0, NULL, 0, |
| 244 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 245 | false); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 249 | void cfg80211_sme_scan_done(struct net_device *dev) |
| 250 | { |
| 251 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 252 | |
| 253 | wdev_lock(wdev); |
| 254 | __cfg80211_sme_scan_done(dev); |
| 255 | wdev_unlock(wdev); |
| 256 | } |
| 257 | |
| 258 | void cfg80211_sme_rx_auth(struct net_device *dev, |
| 259 | const u8 *buf, size_t len) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 260 | { |
| 261 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 262 | struct wiphy *wiphy = wdev->wiphy; |
| 263 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 264 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 265 | u16 status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 266 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 267 | ASSERT_WDEV_LOCK(wdev); |
| 268 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 269 | /* should only RX auth frames when connecting */ |
| 270 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
| 271 | return; |
| 272 | |
| 273 | if (WARN_ON(!wdev->conn)) |
| 274 | return; |
| 275 | |
| 276 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG && |
| 277 | wdev->conn->auto_auth && |
| 278 | wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) { |
| 279 | /* select automatically between only open, shared, leap */ |
| 280 | switch (wdev->conn->params.auth_type) { |
| 281 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 282 | wdev->conn->params.auth_type = |
| 283 | NL80211_AUTHTYPE_SHARED_KEY; |
| 284 | break; |
| 285 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 286 | wdev->conn->params.auth_type = |
| 287 | NL80211_AUTHTYPE_NETWORK_EAP; |
| 288 | break; |
| 289 | default: |
| 290 | /* huh? */ |
| 291 | wdev->conn->params.auth_type = |
| 292 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 293 | break; |
| 294 | } |
| 295 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 296 | schedule_work(&rdev->conn_work); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 297 | } else if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 298 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 299 | kfree(wdev->conn); |
| 300 | wdev->conn = NULL; |
| 301 | } else if (wdev->sme_state == CFG80211_SME_CONNECTING && |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 302 | wdev->conn->state == CFG80211_CONN_AUTHENTICATING) { |
| 303 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 304 | schedule_work(&rdev->conn_work); |
| 305 | } |
| 306 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 307 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 308 | void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 309 | const u8 *req_ie, size_t req_ie_len, |
| 310 | const u8 *resp_ie, size_t resp_ie_len, |
| 311 | u16 status, bool wextev) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 312 | { |
| 313 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 314 | struct cfg80211_bss *bss; |
| 315 | #ifdef CONFIG_WIRELESS_EXT |
| 316 | union iwreq_data wrqu; |
| 317 | #endif |
| 318 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 319 | ASSERT_WDEV_LOCK(wdev); |
| 320 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 321 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 322 | return; |
| 323 | |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 324 | if (wdev->sme_state == CFG80211_SME_CONNECTED) |
| 325 | nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), dev, |
| 326 | bssid, req_ie, req_ie_len, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 327 | resp_ie, resp_ie_len, GFP_KERNEL); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 328 | else |
| 329 | nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev, |
| 330 | bssid, req_ie, req_ie_len, |
| 331 | resp_ie, resp_ie_len, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 332 | status, GFP_KERNEL); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 333 | |
| 334 | #ifdef CONFIG_WIRELESS_EXT |
| 335 | if (wextev) { |
| 336 | if (req_ie && status == WLAN_STATUS_SUCCESS) { |
| 337 | memset(&wrqu, 0, sizeof(wrqu)); |
| 338 | wrqu.data.length = req_ie_len; |
| 339 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, req_ie); |
| 340 | } |
| 341 | |
| 342 | if (resp_ie && status == WLAN_STATUS_SUCCESS) { |
| 343 | memset(&wrqu, 0, sizeof(wrqu)); |
| 344 | wrqu.data.length = resp_ie_len; |
| 345 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie); |
| 346 | } |
| 347 | |
| 348 | memset(&wrqu, 0, sizeof(wrqu)); |
| 349 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 350 | if (bssid && status == WLAN_STATUS_SUCCESS) |
| 351 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
| 352 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 353 | } |
| 354 | #endif |
| 355 | |
| 356 | if (status == WLAN_STATUS_SUCCESS && |
| 357 | wdev->sme_state == CFG80211_SME_IDLE) { |
| 358 | wdev->sme_state = CFG80211_SME_CONNECTED; |
| 359 | return; |
| 360 | } |
| 361 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 362 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 363 | return; |
| 364 | |
| 365 | if (wdev->current_bss) { |
| 366 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 367 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 368 | wdev->current_bss = NULL; |
| 369 | } |
| 370 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 371 | if (wdev->conn) |
| 372 | wdev->conn->state = CFG80211_CONN_IDLE; |
| 373 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 374 | if (status == WLAN_STATUS_SUCCESS) { |
| 375 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
| 376 | wdev->ssid, wdev->ssid_len, |
| 377 | WLAN_CAPABILITY_ESS, |
| 378 | WLAN_CAPABILITY_ESS); |
| 379 | |
| 380 | if (WARN_ON(!bss)) |
| 381 | return; |
| 382 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 383 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 384 | wdev->current_bss = bss_from_pub(bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 385 | |
| 386 | wdev->sme_state = CFG80211_SME_CONNECTED; |
| 387 | } else { |
| 388 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 389 | kfree(wdev->conn); |
| 390 | wdev->conn = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 391 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 392 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 393 | |
| 394 | void cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 395 | const u8 *req_ie, size_t req_ie_len, |
| 396 | const u8 *resp_ie, size_t resp_ie_len, |
| 397 | u16 status, gfp_t gfp) |
| 398 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 399 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 400 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 401 | struct cfg80211_event *ev; |
| 402 | unsigned long flags; |
| 403 | |
| 404 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 405 | if (!ev) |
| 406 | return; |
| 407 | |
| 408 | ev->type = EVENT_CONNECT_RESULT; |
| 409 | memcpy(ev->cr.bssid, bssid, ETH_ALEN); |
| 410 | ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 411 | ev->cr.req_ie_len = req_ie_len; |
| 412 | memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len); |
| 413 | ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 414 | ev->cr.resp_ie_len = resp_ie_len; |
| 415 | memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len); |
| 416 | ev->cr.status = status; |
| 417 | |
| 418 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 419 | list_add_tail(&ev->list, &wdev->event_list); |
| 420 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 421 | schedule_work(&rdev->event_work); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 422 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 423 | EXPORT_SYMBOL(cfg80211_connect_result); |
| 424 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 425 | void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid, |
| 426 | const u8 *req_ie, size_t req_ie_len, |
| 427 | const u8 *resp_ie, size_t resp_ie_len) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 428 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 429 | struct cfg80211_bss *bss; |
| 430 | #ifdef CONFIG_WIRELESS_EXT |
| 431 | union iwreq_data wrqu; |
| 432 | #endif |
| 433 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 434 | ASSERT_WDEV_LOCK(wdev); |
| 435 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 436 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 437 | return; |
| 438 | |
| 439 | if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED)) |
| 440 | return; |
| 441 | |
| 442 | /* internal error -- how did we get to CONNECTED w/o BSS? */ |
| 443 | if (WARN_ON(!wdev->current_bss)) { |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 448 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 449 | wdev->current_bss = NULL; |
| 450 | |
| 451 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
| 452 | wdev->ssid, wdev->ssid_len, |
| 453 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
| 454 | |
| 455 | if (WARN_ON(!bss)) |
| 456 | return; |
| 457 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 458 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 459 | wdev->current_bss = bss_from_pub(bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 460 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 461 | nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), wdev->netdev, bssid, |
| 462 | req_ie, req_ie_len, resp_ie, resp_ie_len, |
| 463 | GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 464 | |
| 465 | #ifdef CONFIG_WIRELESS_EXT |
| 466 | if (req_ie) { |
| 467 | memset(&wrqu, 0, sizeof(wrqu)); |
| 468 | wrqu.data.length = req_ie_len; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 469 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, |
| 470 | &wrqu, req_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | if (resp_ie) { |
| 474 | memset(&wrqu, 0, sizeof(wrqu)); |
| 475 | wrqu.data.length = resp_ie_len; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 476 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, |
| 477 | &wrqu, resp_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | memset(&wrqu, 0, sizeof(wrqu)); |
| 481 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 482 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 483 | wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 484 | #endif |
| 485 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 486 | |
| 487 | void cfg80211_roamed(struct net_device *dev, const u8 *bssid, |
| 488 | const u8 *req_ie, size_t req_ie_len, |
| 489 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 490 | { |
| 491 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 492 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 493 | struct cfg80211_event *ev; |
| 494 | unsigned long flags; |
| 495 | |
| 496 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 497 | if (!ev) |
| 498 | return; |
| 499 | |
| 500 | ev->type = EVENT_ROAMED; |
| 501 | memcpy(ev->rm.bssid, bssid, ETH_ALEN); |
| 502 | ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 503 | ev->rm.req_ie_len = req_ie_len; |
| 504 | memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len); |
| 505 | ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 506 | ev->rm.resp_ie_len = resp_ie_len; |
| 507 | memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len); |
| 508 | |
| 509 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 510 | list_add_tail(&ev->list, &wdev->event_list); |
| 511 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 512 | schedule_work(&rdev->event_work); |
| 513 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 514 | EXPORT_SYMBOL(cfg80211_roamed); |
| 515 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 516 | void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 517 | size_t ie_len, u16 reason, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 518 | { |
| 519 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 520 | #ifdef CONFIG_WIRELESS_EXT |
| 521 | union iwreq_data wrqu; |
| 522 | #endif |
| 523 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 524 | ASSERT_WDEV_LOCK(wdev); |
| 525 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 526 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 527 | return; |
| 528 | |
| 529 | if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED)) |
| 530 | return; |
| 531 | |
| 532 | if (wdev->current_bss) { |
| 533 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 534 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | wdev->current_bss = NULL; |
| 538 | wdev->sme_state = CFG80211_SME_IDLE; |
| 539 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 540 | if (wdev->conn) { |
| 541 | kfree(wdev->conn->ie); |
| 542 | wdev->conn->ie = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 543 | kfree(wdev->conn); |
| 544 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 545 | } |
| 546 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 547 | nl80211_send_disconnected(wiphy_to_dev(wdev->wiphy), dev, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 548 | reason, ie, ie_len, from_ap); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 549 | |
| 550 | #ifdef CONFIG_WIRELESS_EXT |
| 551 | memset(&wrqu, 0, sizeof(wrqu)); |
| 552 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 553 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 554 | #endif |
| 555 | } |
| 556 | |
| 557 | void cfg80211_disconnected(struct net_device *dev, u16 reason, |
| 558 | u8 *ie, size_t ie_len, gfp_t gfp) |
| 559 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 560 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 561 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 562 | struct cfg80211_event *ev; |
| 563 | unsigned long flags; |
| 564 | |
| 565 | ev = kzalloc(sizeof(*ev) + ie_len, gfp); |
| 566 | if (!ev) |
| 567 | return; |
| 568 | |
| 569 | ev->type = EVENT_DISCONNECTED; |
| 570 | ev->dc.ie = ((u8 *)ev) + sizeof(*ev); |
| 571 | ev->dc.ie_len = ie_len; |
| 572 | memcpy((void *)ev->dc.ie, ie, ie_len); |
| 573 | ev->dc.reason = reason; |
| 574 | |
| 575 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 576 | list_add_tail(&ev->list, &wdev->event_list); |
| 577 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 578 | schedule_work(&rdev->event_work); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 579 | } |
| 580 | EXPORT_SYMBOL(cfg80211_disconnected); |
| 581 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 582 | int __cfg80211_connect(struct cfg80211_registered_device *rdev, |
| 583 | struct net_device *dev, |
| 584 | struct cfg80211_connect_params *connect) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 585 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 586 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 587 | int err; |
| 588 | |
| 589 | ASSERT_WDEV_LOCK(wdev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 590 | |
| 591 | if (wdev->sme_state != CFG80211_SME_IDLE) |
| 592 | return -EALREADY; |
| 593 | |
| 594 | if (!rdev->ops->connect) { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 595 | if (!rdev->ops->auth || !rdev->ops->assoc) |
| 596 | return -EOPNOTSUPP; |
| 597 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 598 | if (WARN_ON(wdev->conn)) |
| 599 | return -EINPROGRESS; |
| 600 | |
| 601 | wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL); |
| 602 | if (!wdev->conn) |
| 603 | return -ENOMEM; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 604 | |
| 605 | /* |
| 606 | * Copy all parameters, and treat explicitly IEs, BSSID, SSID. |
| 607 | */ |
| 608 | memcpy(&wdev->conn->params, connect, sizeof(*connect)); |
| 609 | if (connect->bssid) { |
| 610 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 611 | memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN); |
| 612 | } |
| 613 | |
| 614 | if (connect->ie) { |
| 615 | wdev->conn->ie = kmemdup(connect->ie, connect->ie_len, |
| 616 | GFP_KERNEL); |
| 617 | wdev->conn->params.ie = wdev->conn->ie; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 618 | if (!wdev->conn->ie) { |
| 619 | kfree(wdev->conn); |
| 620 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 621 | return -ENOMEM; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 622 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) { |
| 626 | wdev->conn->auto_auth = true; |
| 627 | /* start with open system ... should mostly work */ |
| 628 | wdev->conn->params.auth_type = |
| 629 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 630 | } else { |
| 631 | wdev->conn->auto_auth = false; |
| 632 | } |
| 633 | |
| 634 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); |
| 635 | wdev->ssid_len = connect->ssid_len; |
| 636 | wdev->conn->params.ssid = wdev->ssid; |
| 637 | wdev->conn->params.ssid_len = connect->ssid_len; |
| 638 | |
| 639 | /* don't care about result -- but fill bssid & channel */ |
| 640 | if (!wdev->conn->params.bssid || !wdev->conn->params.channel) |
| 641 | cfg80211_get_conn_bss(wdev); |
| 642 | |
| 643 | wdev->sme_state = CFG80211_SME_CONNECTING; |
| 644 | |
| 645 | /* we're good if we have both BSSID and channel */ |
| 646 | if (wdev->conn->params.bssid && wdev->conn->params.channel) { |
| 647 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 648 | err = cfg80211_conn_do_work(wdev); |
| 649 | } else { |
| 650 | /* otherwise we'll need to scan for the AP first */ |
| 651 | err = cfg80211_conn_scan(wdev); |
| 652 | /* |
| 653 | * If we can't scan right now, then we need to scan again |
| 654 | * after the current scan finished, since the parameters |
| 655 | * changed (unless we find a good AP anyway). |
| 656 | */ |
| 657 | if (err == -EBUSY) { |
| 658 | err = 0; |
| 659 | wdev->conn->state = CFG80211_CONN_SCAN_AGAIN; |
| 660 | } |
| 661 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 662 | if (err) { |
| 663 | kfree(wdev->conn); |
| 664 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 665 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 666 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 667 | |
| 668 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 669 | } else { |
| 670 | wdev->sme_state = CFG80211_SME_CONNECTING; |
| 671 | err = rdev->ops->connect(&rdev->wiphy, dev, connect); |
| 672 | if (err) { |
| 673 | wdev->sme_state = CFG80211_SME_IDLE; |
| 674 | return err; |
| 675 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 676 | |
| 677 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); |
| 678 | wdev->ssid_len = connect->ssid_len; |
| 679 | |
| 680 | return 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 681 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 682 | } |
| 683 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 684 | int cfg80211_connect(struct cfg80211_registered_device *rdev, |
| 685 | struct net_device *dev, |
| 686 | struct cfg80211_connect_params *connect) |
| 687 | { |
| 688 | int err; |
| 689 | |
| 690 | wdev_lock(dev->ieee80211_ptr); |
| 691 | err = __cfg80211_connect(rdev, dev, connect); |
| 692 | wdev_unlock(dev->ieee80211_ptr); |
| 693 | |
| 694 | return err; |
| 695 | } |
| 696 | |
| 697 | int __cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
| 698 | struct net_device *dev, u16 reason, bool wextev) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 699 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 700 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 701 | int err; |
| 702 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 703 | ASSERT_WDEV_LOCK(wdev); |
| 704 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 705 | if (wdev->sme_state == CFG80211_SME_IDLE) |
| 706 | return -EINVAL; |
| 707 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 708 | if (!rdev->ops->disconnect) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 709 | if (!rdev->ops->deauth) |
| 710 | return -EOPNOTSUPP; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 711 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 712 | /* was it connected by userspace SME? */ |
| 713 | if (!wdev->conn) { |
| 714 | cfg80211_mlme_down(rdev, dev); |
| 715 | return 0; |
| 716 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 717 | |
| 718 | if (wdev->sme_state == CFG80211_SME_CONNECTING && |
| 719 | (wdev->conn->state == CFG80211_CONN_SCANNING || |
| 720 | wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)) { |
| 721 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 722 | kfree(wdev->conn); |
| 723 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 724 | return 0; |
| 725 | } |
| 726 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 727 | /* wdev->conn->params.bssid must be set if > SCANNING */ |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 728 | err = __cfg80211_mlme_deauth(rdev, dev, |
| 729 | wdev->conn->params.bssid, |
| 730 | NULL, 0, reason); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 731 | if (err) |
| 732 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 733 | } else { |
| 734 | err = rdev->ops->disconnect(&rdev->wiphy, dev, reason); |
| 735 | if (err) |
| 736 | return err; |
| 737 | } |
| 738 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 739 | if (wdev->sme_state == CFG80211_SME_CONNECTED) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 740 | __cfg80211_disconnected(dev, NULL, 0, 0, false); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 741 | else if (wdev->sme_state == CFG80211_SME_CONNECTING) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 742 | __cfg80211_connect_result(dev, NULL, NULL, 0, NULL, 0, |
| 743 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 744 | wextev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 745 | |
| 746 | return 0; |
| 747 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 748 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 749 | int cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
| 750 | struct net_device *dev, |
| 751 | u16 reason, bool wextev) |
| 752 | { |
| 753 | int err; |
| 754 | |
| 755 | wdev_lock(dev->ieee80211_ptr); |
| 756 | err = __cfg80211_disconnect(rdev, dev, reason, wextev); |
| 757 | wdev_unlock(dev->ieee80211_ptr); |
| 758 | |
| 759 | return err; |
| 760 | } |
| 761 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 762 | void cfg80211_sme_disassoc(struct net_device *dev, int idx) |
| 763 | { |
| 764 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 765 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 766 | u8 bssid[ETH_ALEN]; |
| 767 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame^] | 768 | ASSERT_WDEV_LOCK(wdev); |
| 769 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 770 | if (!wdev->conn) |
| 771 | return; |
| 772 | |
| 773 | if (wdev->conn->state == CFG80211_CONN_IDLE) |
| 774 | return; |
| 775 | |
| 776 | /* |
| 777 | * Ok, so the association was made by this SME -- we don't |
| 778 | * want it any more so deauthenticate too. |
| 779 | */ |
| 780 | |
| 781 | if (!wdev->auth_bsses[idx]) |
| 782 | return; |
| 783 | |
| 784 | memcpy(bssid, wdev->auth_bsses[idx]->pub.bssid, ETH_ALEN); |
| 785 | if (cfg80211_mlme_deauth(rdev, dev, bssid, |
| 786 | NULL, 0, WLAN_REASON_DEAUTH_LEAVING)) { |
| 787 | /* whatever -- assume gone anyway */ |
| 788 | cfg80211_unhold_bss(wdev->auth_bsses[idx]); |
| 789 | cfg80211_put_bss(&wdev->auth_bsses[idx]->pub); |
| 790 | wdev->auth_bsses[idx] = NULL; |
| 791 | } |
| 792 | } |