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