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