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