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 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 36 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 37 | struct cfg80211_scan_request *request; |
| 38 | int n_channels, err; |
| 39 | |
| 40 | ASSERT_RTNL(); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 41 | ASSERT_RDEV_LOCK(rdev); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 42 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 43 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 44 | if (rdev->scan_req) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 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; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 90 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 91 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 92 | rdev->scan_req = request; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 93 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 94 | err = rdev->ops->scan(wdev->wiphy, wdev->netdev, request); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 95 | if (!err) { |
| 96 | wdev->conn->state = CFG80211_CONN_SCANNING; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 97 | nl80211_send_scan_start(rdev, wdev->netdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 98 | } else { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 99 | rdev->scan_req = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 100 | kfree(request); |
| 101 | } |
| 102 | return err; |
| 103 | } |
| 104 | |
| 105 | static int cfg80211_conn_do_work(struct wireless_dev *wdev) |
| 106 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 107 | struct cfg80211_registered_device *rdev = 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 | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 122 | BUG_ON(!rdev->ops->auth); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 123 | wdev->conn->state = CFG80211_CONN_AUTHENTICATING; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 124 | return __cfg80211_mlme_auth(rdev, wdev->netdev, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 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 | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 130 | BUG_ON(!rdev->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 | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 138 | err = __cfg80211_mlme_assoc(rdev, wdev->netdev, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 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 | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 145 | __cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 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 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 156 | struct cfg80211_registered_device *rdev = |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 157 | container_of(work, struct cfg80211_registered_device, conn_work); |
| 158 | struct wireless_dev *wdev; |
| 159 | |
| 160 | rtnl_lock(); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 161 | cfg80211_lock_rdev(rdev); |
| 162 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 163 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 164 | list_for_each_entry(wdev, &rdev->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 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 184 | mutex_unlock(&rdev->devlist_mtx); |
| 185 | cfg80211_unlock_rdev(rdev); |
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 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 191 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 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; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 212 | schedule_work(&rdev->conn_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 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; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 221 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 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) |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 238 | schedule_work(&rdev->conn_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 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 | 4bde0f7 | 2009-07-07 23:46:51 +0200 | [diff] [blame^] | 298 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0, |
| 299 | status_code, false); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 300 | } else if (wdev->sme_state == CFG80211_SME_CONNECTING && |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 301 | wdev->conn->state == CFG80211_CONN_AUTHENTICATING) { |
| 302 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 303 | schedule_work(&rdev->conn_work); |
| 304 | } |
| 305 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 306 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 307 | void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 308 | const u8 *req_ie, size_t req_ie_len, |
| 309 | const u8 *resp_ie, size_t resp_ie_len, |
| 310 | u16 status, bool wextev) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 311 | { |
| 312 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 313 | struct cfg80211_bss *bss; |
| 314 | #ifdef CONFIG_WIRELESS_EXT |
| 315 | union iwreq_data wrqu; |
| 316 | #endif |
| 317 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 318 | ASSERT_WDEV_LOCK(wdev); |
| 319 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 320 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 321 | return; |
| 322 | |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 323 | if (wdev->sme_state == CFG80211_SME_CONNECTED) |
| 324 | nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), dev, |
| 325 | bssid, req_ie, req_ie_len, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 326 | resp_ie, resp_ie_len, GFP_KERNEL); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 327 | else |
| 328 | nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev, |
| 329 | bssid, req_ie, req_ie_len, |
| 330 | resp_ie, resp_ie_len, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 331 | status, GFP_KERNEL); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 332 | |
| 333 | #ifdef CONFIG_WIRELESS_EXT |
| 334 | if (wextev) { |
| 335 | if (req_ie && status == WLAN_STATUS_SUCCESS) { |
| 336 | memset(&wrqu, 0, sizeof(wrqu)); |
| 337 | wrqu.data.length = req_ie_len; |
| 338 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, req_ie); |
| 339 | } |
| 340 | |
| 341 | if (resp_ie && status == WLAN_STATUS_SUCCESS) { |
| 342 | memset(&wrqu, 0, sizeof(wrqu)); |
| 343 | wrqu.data.length = resp_ie_len; |
| 344 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie); |
| 345 | } |
| 346 | |
| 347 | memset(&wrqu, 0, sizeof(wrqu)); |
| 348 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 349 | if (bssid && status == WLAN_STATUS_SUCCESS) |
| 350 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
| 351 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 352 | } |
| 353 | #endif |
| 354 | |
| 355 | if (status == WLAN_STATUS_SUCCESS && |
| 356 | wdev->sme_state == CFG80211_SME_IDLE) { |
| 357 | wdev->sme_state = CFG80211_SME_CONNECTED; |
| 358 | return; |
| 359 | } |
| 360 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 361 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 362 | return; |
| 363 | |
| 364 | if (wdev->current_bss) { |
| 365 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 366 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 367 | wdev->current_bss = NULL; |
| 368 | } |
| 369 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 370 | if (wdev->conn) |
| 371 | wdev->conn->state = CFG80211_CONN_IDLE; |
| 372 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 373 | if (status == WLAN_STATUS_SUCCESS) { |
| 374 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
| 375 | wdev->ssid, wdev->ssid_len, |
| 376 | WLAN_CAPABILITY_ESS, |
| 377 | WLAN_CAPABILITY_ESS); |
| 378 | |
| 379 | if (WARN_ON(!bss)) |
| 380 | return; |
| 381 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 382 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 383 | wdev->current_bss = bss_from_pub(bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 384 | |
| 385 | wdev->sme_state = CFG80211_SME_CONNECTED; |
| 386 | } else { |
| 387 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 388 | kfree(wdev->conn); |
| 389 | wdev->conn = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 390 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 391 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 392 | |
| 393 | void cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 394 | const u8 *req_ie, size_t req_ie_len, |
| 395 | const u8 *resp_ie, size_t resp_ie_len, |
| 396 | u16 status, gfp_t gfp) |
| 397 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 398 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 399 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 400 | struct cfg80211_event *ev; |
| 401 | unsigned long flags; |
| 402 | |
| 403 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 404 | if (!ev) |
| 405 | return; |
| 406 | |
| 407 | ev->type = EVENT_CONNECT_RESULT; |
| 408 | memcpy(ev->cr.bssid, bssid, ETH_ALEN); |
| 409 | ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 410 | ev->cr.req_ie_len = req_ie_len; |
| 411 | memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len); |
| 412 | ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 413 | ev->cr.resp_ie_len = resp_ie_len; |
| 414 | memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len); |
| 415 | ev->cr.status = status; |
| 416 | |
| 417 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 418 | list_add_tail(&ev->list, &wdev->event_list); |
| 419 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 420 | schedule_work(&rdev->event_work); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 421 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 422 | EXPORT_SYMBOL(cfg80211_connect_result); |
| 423 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 424 | void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid, |
| 425 | const u8 *req_ie, size_t req_ie_len, |
| 426 | const u8 *resp_ie, size_t resp_ie_len) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 427 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 428 | struct cfg80211_bss *bss; |
| 429 | #ifdef CONFIG_WIRELESS_EXT |
| 430 | union iwreq_data wrqu; |
| 431 | #endif |
| 432 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 433 | ASSERT_WDEV_LOCK(wdev); |
| 434 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 435 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 436 | return; |
| 437 | |
| 438 | if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED)) |
| 439 | return; |
| 440 | |
| 441 | /* internal error -- how did we get to CONNECTED w/o BSS? */ |
| 442 | if (WARN_ON(!wdev->current_bss)) { |
| 443 | return; |
| 444 | } |
| 445 | |
| 446 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 447 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 448 | wdev->current_bss = NULL; |
| 449 | |
| 450 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
| 451 | wdev->ssid, wdev->ssid_len, |
| 452 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
| 453 | |
| 454 | if (WARN_ON(!bss)) |
| 455 | return; |
| 456 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 457 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 458 | wdev->current_bss = bss_from_pub(bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 459 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 460 | nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), wdev->netdev, bssid, |
| 461 | req_ie, req_ie_len, resp_ie, resp_ie_len, |
| 462 | GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 463 | |
| 464 | #ifdef CONFIG_WIRELESS_EXT |
| 465 | if (req_ie) { |
| 466 | memset(&wrqu, 0, sizeof(wrqu)); |
| 467 | wrqu.data.length = req_ie_len; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 468 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, |
| 469 | &wrqu, req_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | if (resp_ie) { |
| 473 | memset(&wrqu, 0, sizeof(wrqu)); |
| 474 | wrqu.data.length = resp_ie_len; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 475 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, |
| 476 | &wrqu, resp_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | memset(&wrqu, 0, sizeof(wrqu)); |
| 480 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 481 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 482 | wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 483 | #endif |
| 484 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 485 | |
| 486 | void cfg80211_roamed(struct net_device *dev, const u8 *bssid, |
| 487 | const u8 *req_ie, size_t req_ie_len, |
| 488 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 489 | { |
| 490 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 491 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 492 | struct cfg80211_event *ev; |
| 493 | unsigned long flags; |
| 494 | |
| 495 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 496 | if (!ev) |
| 497 | return; |
| 498 | |
| 499 | ev->type = EVENT_ROAMED; |
| 500 | memcpy(ev->rm.bssid, bssid, ETH_ALEN); |
| 501 | ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 502 | ev->rm.req_ie_len = req_ie_len; |
| 503 | memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len); |
| 504 | ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 505 | ev->rm.resp_ie_len = resp_ie_len; |
| 506 | memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len); |
| 507 | |
| 508 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 509 | list_add_tail(&ev->list, &wdev->event_list); |
| 510 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 511 | schedule_work(&rdev->event_work); |
| 512 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 513 | EXPORT_SYMBOL(cfg80211_roamed); |
| 514 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 515 | void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 516 | size_t ie_len, u16 reason, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 517 | { |
| 518 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 519 | #ifdef CONFIG_WIRELESS_EXT |
| 520 | union iwreq_data wrqu; |
| 521 | #endif |
| 522 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 523 | ASSERT_WDEV_LOCK(wdev); |
| 524 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 525 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 526 | return; |
| 527 | |
| 528 | if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED)) |
| 529 | return; |
| 530 | |
| 531 | if (wdev->current_bss) { |
| 532 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 533 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | wdev->current_bss = NULL; |
| 537 | wdev->sme_state = CFG80211_SME_IDLE; |
| 538 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 539 | if (wdev->conn) { |
| 540 | kfree(wdev->conn->ie); |
| 541 | wdev->conn->ie = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 542 | kfree(wdev->conn); |
| 543 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 544 | } |
| 545 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 546 | nl80211_send_disconnected(wiphy_to_dev(wdev->wiphy), dev, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 547 | reason, ie, ie_len, from_ap); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 548 | |
| 549 | #ifdef CONFIG_WIRELESS_EXT |
| 550 | memset(&wrqu, 0, sizeof(wrqu)); |
| 551 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 552 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 553 | #endif |
| 554 | } |
| 555 | |
| 556 | void cfg80211_disconnected(struct net_device *dev, u16 reason, |
| 557 | u8 *ie, size_t ie_len, gfp_t gfp) |
| 558 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 559 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 560 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 561 | struct cfg80211_event *ev; |
| 562 | unsigned long flags; |
| 563 | |
| 564 | ev = kzalloc(sizeof(*ev) + ie_len, gfp); |
| 565 | if (!ev) |
| 566 | return; |
| 567 | |
| 568 | ev->type = EVENT_DISCONNECTED; |
| 569 | ev->dc.ie = ((u8 *)ev) + sizeof(*ev); |
| 570 | ev->dc.ie_len = ie_len; |
| 571 | memcpy((void *)ev->dc.ie, ie, ie_len); |
| 572 | ev->dc.reason = reason; |
| 573 | |
| 574 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 575 | list_add_tail(&ev->list, &wdev->event_list); |
| 576 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 577 | schedule_work(&rdev->event_work); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 578 | } |
| 579 | EXPORT_SYMBOL(cfg80211_disconnected); |
| 580 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 581 | int __cfg80211_connect(struct cfg80211_registered_device *rdev, |
| 582 | struct net_device *dev, |
| 583 | struct cfg80211_connect_params *connect) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 584 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 585 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 586 | int err; |
| 587 | |
| 588 | ASSERT_WDEV_LOCK(wdev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 589 | |
| 590 | if (wdev->sme_state != CFG80211_SME_IDLE) |
| 591 | return -EALREADY; |
| 592 | |
| 593 | if (!rdev->ops->connect) { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 594 | if (!rdev->ops->auth || !rdev->ops->assoc) |
| 595 | return -EOPNOTSUPP; |
| 596 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 597 | if (WARN_ON(wdev->conn)) |
| 598 | return -EINPROGRESS; |
| 599 | |
| 600 | wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL); |
| 601 | if (!wdev->conn) |
| 602 | return -ENOMEM; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 603 | |
| 604 | /* |
| 605 | * Copy all parameters, and treat explicitly IEs, BSSID, SSID. |
| 606 | */ |
| 607 | memcpy(&wdev->conn->params, connect, sizeof(*connect)); |
| 608 | if (connect->bssid) { |
| 609 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 610 | memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN); |
| 611 | } |
| 612 | |
| 613 | if (connect->ie) { |
| 614 | wdev->conn->ie = kmemdup(connect->ie, connect->ie_len, |
| 615 | GFP_KERNEL); |
| 616 | wdev->conn->params.ie = wdev->conn->ie; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 617 | if (!wdev->conn->ie) { |
| 618 | kfree(wdev->conn); |
| 619 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 620 | return -ENOMEM; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 621 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) { |
| 625 | wdev->conn->auto_auth = true; |
| 626 | /* start with open system ... should mostly work */ |
| 627 | wdev->conn->params.auth_type = |
| 628 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 629 | } else { |
| 630 | wdev->conn->auto_auth = false; |
| 631 | } |
| 632 | |
| 633 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); |
| 634 | wdev->ssid_len = connect->ssid_len; |
| 635 | wdev->conn->params.ssid = wdev->ssid; |
| 636 | wdev->conn->params.ssid_len = connect->ssid_len; |
| 637 | |
| 638 | /* don't care about result -- but fill bssid & channel */ |
| 639 | if (!wdev->conn->params.bssid || !wdev->conn->params.channel) |
| 640 | cfg80211_get_conn_bss(wdev); |
| 641 | |
| 642 | wdev->sme_state = CFG80211_SME_CONNECTING; |
| 643 | |
| 644 | /* we're good if we have both BSSID and channel */ |
| 645 | if (wdev->conn->params.bssid && wdev->conn->params.channel) { |
| 646 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 647 | err = cfg80211_conn_do_work(wdev); |
| 648 | } else { |
| 649 | /* otherwise we'll need to scan for the AP first */ |
| 650 | err = cfg80211_conn_scan(wdev); |
| 651 | /* |
| 652 | * If we can't scan right now, then we need to scan again |
| 653 | * after the current scan finished, since the parameters |
| 654 | * changed (unless we find a good AP anyway). |
| 655 | */ |
| 656 | if (err == -EBUSY) { |
| 657 | err = 0; |
| 658 | wdev->conn->state = CFG80211_CONN_SCAN_AGAIN; |
| 659 | } |
| 660 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 661 | if (err) { |
| 662 | kfree(wdev->conn); |
| 663 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 664 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 665 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 666 | |
| 667 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 668 | } else { |
| 669 | wdev->sme_state = CFG80211_SME_CONNECTING; |
| 670 | err = rdev->ops->connect(&rdev->wiphy, dev, connect); |
| 671 | if (err) { |
| 672 | wdev->sme_state = CFG80211_SME_IDLE; |
| 673 | return err; |
| 674 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 675 | |
| 676 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); |
| 677 | wdev->ssid_len = connect->ssid_len; |
| 678 | |
| 679 | return 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 680 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 681 | } |
| 682 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 683 | int cfg80211_connect(struct cfg80211_registered_device *rdev, |
| 684 | struct net_device *dev, |
| 685 | struct cfg80211_connect_params *connect) |
| 686 | { |
| 687 | int err; |
| 688 | |
| 689 | wdev_lock(dev->ieee80211_ptr); |
| 690 | err = __cfg80211_connect(rdev, dev, connect); |
| 691 | wdev_unlock(dev->ieee80211_ptr); |
| 692 | |
| 693 | return err; |
| 694 | } |
| 695 | |
| 696 | int __cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
| 697 | struct net_device *dev, u16 reason, bool wextev) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 698 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 699 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 700 | int err; |
| 701 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 702 | ASSERT_WDEV_LOCK(wdev); |
| 703 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 704 | if (wdev->sme_state == CFG80211_SME_IDLE) |
| 705 | return -EINVAL; |
| 706 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 707 | if (!rdev->ops->disconnect) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 708 | if (!rdev->ops->deauth) |
| 709 | return -EOPNOTSUPP; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 710 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 711 | /* was it connected by userspace SME? */ |
| 712 | if (!wdev->conn) { |
| 713 | cfg80211_mlme_down(rdev, dev); |
| 714 | return 0; |
| 715 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 716 | |
| 717 | if (wdev->sme_state == CFG80211_SME_CONNECTING && |
| 718 | (wdev->conn->state == CFG80211_CONN_SCANNING || |
| 719 | wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)) { |
| 720 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 721 | kfree(wdev->conn); |
| 722 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 723 | return 0; |
| 724 | } |
| 725 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 726 | /* wdev->conn->params.bssid must be set if > SCANNING */ |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 727 | err = __cfg80211_mlme_deauth(rdev, dev, |
| 728 | wdev->conn->params.bssid, |
| 729 | NULL, 0, reason); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 730 | if (err) |
| 731 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 732 | } else { |
| 733 | err = rdev->ops->disconnect(&rdev->wiphy, dev, reason); |
| 734 | if (err) |
| 735 | return err; |
| 736 | } |
| 737 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 738 | if (wdev->sme_state == CFG80211_SME_CONNECTED) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 739 | __cfg80211_disconnected(dev, NULL, 0, 0, false); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 740 | else if (wdev->sme_state == CFG80211_SME_CONNECTING) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 741 | __cfg80211_connect_result(dev, NULL, NULL, 0, NULL, 0, |
| 742 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 743 | wextev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 744 | |
| 745 | return 0; |
| 746 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 747 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 748 | int cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
| 749 | struct net_device *dev, |
| 750 | u16 reason, bool wextev) |
| 751 | { |
| 752 | int err; |
| 753 | |
| 754 | wdev_lock(dev->ieee80211_ptr); |
| 755 | err = __cfg80211_disconnect(rdev, dev, reason, wextev); |
| 756 | wdev_unlock(dev->ieee80211_ptr); |
| 757 | |
| 758 | return err; |
| 759 | } |
| 760 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 761 | void cfg80211_sme_disassoc(struct net_device *dev, int idx) |
| 762 | { |
| 763 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 764 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 765 | u8 bssid[ETH_ALEN]; |
| 766 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 767 | ASSERT_WDEV_LOCK(wdev); |
| 768 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 769 | if (!wdev->conn) |
| 770 | return; |
| 771 | |
| 772 | if (wdev->conn->state == CFG80211_CONN_IDLE) |
| 773 | return; |
| 774 | |
| 775 | /* |
| 776 | * Ok, so the association was made by this SME -- we don't |
| 777 | * want it any more so deauthenticate too. |
| 778 | */ |
| 779 | |
| 780 | if (!wdev->auth_bsses[idx]) |
| 781 | return; |
| 782 | |
| 783 | memcpy(bssid, wdev->auth_bsses[idx]->pub.bssid, ETH_ALEN); |
| 784 | if (cfg80211_mlme_deauth(rdev, dev, bssid, |
| 785 | NULL, 0, WLAN_REASON_DEAUTH_LEAVING)) { |
| 786 | /* whatever -- assume gone anyway */ |
| 787 | cfg80211_unhold_bss(wdev->auth_bsses[idx]); |
| 788 | cfg80211_put_bss(&wdev->auth_bsses[idx]->pub); |
| 789 | wdev->auth_bsses[idx] = NULL; |
| 790 | } |
| 791 | } |