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 | 6829c878 | 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; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 30 | u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN]; |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 31 | u8 *ie; |
| 32 | size_t ie_len; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 33 | bool auto_auth, prev_bssid_valid; |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 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; |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 84 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 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; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 112 | const u8 *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 113 | int err; |
Johannes Berg | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 138 | if (wdev->conn->prev_bssid_valid) |
| 139 | prev_bssid = wdev->conn->prev_bssid; |
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, |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 142 | prev_bssid, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 182 | false, NULL); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 183 | wdev_unlock(wdev); |
Johannes Berg | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 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 | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 227 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
| 228 | return; |
| 229 | |
Zhu Yi | d4b1a68 | 2009-07-16 17:34:14 +0800 | [diff] [blame] | 230 | if (!wdev->conn) |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 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 | 6829c878 | 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, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 247 | false, NULL); |
Johannes Berg | 6829c878 | 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 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 255 | mutex_lock(&wiphy_to_dev(wdev->wiphy)->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 256 | wdev_lock(wdev); |
| 257 | __cfg80211_sme_scan_done(dev); |
| 258 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 259 | mutex_unlock(&wiphy_to_dev(wdev->wiphy)->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void cfg80211_sme_rx_auth(struct net_device *dev, |
| 263 | const u8 *buf, size_t len) |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 264 | { |
| 265 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 266 | struct wiphy *wiphy = wdev->wiphy; |
| 267 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 268 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 269 | u16 status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 270 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 271 | ASSERT_WDEV_LOCK(wdev); |
| 272 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 273 | /* should only RX auth frames when connecting */ |
| 274 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
| 275 | return; |
| 276 | |
| 277 | if (WARN_ON(!wdev->conn)) |
| 278 | return; |
| 279 | |
| 280 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG && |
| 281 | wdev->conn->auto_auth && |
| 282 | wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) { |
| 283 | /* select automatically between only open, shared, leap */ |
| 284 | switch (wdev->conn->params.auth_type) { |
| 285 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 286 | if (wdev->connect_keys) |
| 287 | wdev->conn->params.auth_type = |
| 288 | NL80211_AUTHTYPE_SHARED_KEY; |
| 289 | else |
| 290 | wdev->conn->params.auth_type = |
| 291 | NL80211_AUTHTYPE_NETWORK_EAP; |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 292 | break; |
| 293 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 294 | wdev->conn->params.auth_type = |
| 295 | NL80211_AUTHTYPE_NETWORK_EAP; |
| 296 | break; |
| 297 | default: |
| 298 | /* huh? */ |
| 299 | wdev->conn->params.auth_type = |
| 300 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 301 | break; |
| 302 | } |
| 303 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 304 | schedule_work(&rdev->conn_work); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 305 | } else if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | 4bde0f7 | 2009-07-07 23:46:51 +0200 | [diff] [blame] | 306 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 307 | status_code, false, NULL); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 308 | } else if (wdev->sme_state == CFG80211_SME_CONNECTING && |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 309 | wdev->conn->state == CFG80211_CONN_AUTHENTICATING) { |
| 310 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 311 | schedule_work(&rdev->conn_work); |
| 312 | } |
| 313 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 314 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 315 | bool cfg80211_sme_failed_reassoc(struct wireless_dev *wdev) |
| 316 | { |
| 317 | struct wiphy *wiphy = wdev->wiphy; |
| 318 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 319 | |
| 320 | if (WARN_ON(!wdev->conn)) |
| 321 | return false; |
| 322 | |
| 323 | if (!wdev->conn->prev_bssid_valid) |
| 324 | return false; |
| 325 | |
| 326 | /* |
| 327 | * Some stupid APs don't accept reassoc, so we |
| 328 | * need to fall back to trying regular assoc. |
| 329 | */ |
| 330 | wdev->conn->prev_bssid_valid = false; |
| 331 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 332 | schedule_work(&rdev->conn_work); |
| 333 | |
| 334 | return true; |
| 335 | } |
| 336 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 337 | void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 338 | const u8 *req_ie, size_t req_ie_len, |
| 339 | const u8 *resp_ie, size_t resp_ie_len, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 340 | u16 status, bool wextev, |
| 341 | struct cfg80211_bss *bss) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 342 | { |
| 343 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 344 | u8 *country_ie; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 345 | #ifdef CONFIG_WIRELESS_EXT |
| 346 | union iwreq_data wrqu; |
| 347 | #endif |
| 348 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 349 | ASSERT_WDEV_LOCK(wdev); |
| 350 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 351 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 352 | return; |
| 353 | |
Johannes Berg | ea416a7 | 2009-08-17 12:22:14 +0200 | [diff] [blame] | 354 | if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTING)) |
| 355 | return; |
| 356 | |
| 357 | nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev, |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 358 | bssid, req_ie, req_ie_len, |
Johannes Berg | ea416a7 | 2009-08-17 12:22:14 +0200 | [diff] [blame] | 359 | resp_ie, resp_ie_len, |
| 360 | status, GFP_KERNEL); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 361 | |
| 362 | #ifdef CONFIG_WIRELESS_EXT |
| 363 | if (wextev) { |
| 364 | if (req_ie && status == WLAN_STATUS_SUCCESS) { |
| 365 | memset(&wrqu, 0, sizeof(wrqu)); |
| 366 | wrqu.data.length = req_ie_len; |
Zhu Yi | 3409ff7 | 2009-07-20 11:47:44 +0800 | [diff] [blame] | 367 | wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | if (resp_ie && status == WLAN_STATUS_SUCCESS) { |
| 371 | memset(&wrqu, 0, sizeof(wrqu)); |
| 372 | wrqu.data.length = resp_ie_len; |
| 373 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie); |
| 374 | } |
| 375 | |
| 376 | memset(&wrqu, 0, sizeof(wrqu)); |
| 377 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 378 | if (bssid && status == WLAN_STATUS_SUCCESS) { |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 379 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 380 | memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN); |
| 381 | wdev->wext.prev_bssid_valid = true; |
| 382 | } |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 383 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 384 | } |
| 385 | #endif |
| 386 | |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 387 | if (wdev->current_bss) { |
| 388 | cfg80211_unhold_bss(wdev->current_bss); |
| 389 | cfg80211_put_bss(&wdev->current_bss->pub); |
| 390 | wdev->current_bss = NULL; |
| 391 | } |
| 392 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 393 | if (wdev->conn) |
| 394 | wdev->conn->state = CFG80211_CONN_IDLE; |
| 395 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 396 | if (status != WLAN_STATUS_SUCCESS) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 397 | wdev->sme_state = CFG80211_SME_IDLE; |
David Kilroy | 415ad1ef | 2009-08-19 00:43:31 +0100 | [diff] [blame^] | 398 | if (wdev->conn) |
| 399 | kfree(wdev->conn->ie); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 400 | kfree(wdev->conn); |
| 401 | wdev->conn = NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 402 | kfree(wdev->connect_keys); |
| 403 | wdev->connect_keys = NULL; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 404 | wdev->ssid_len = 0; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 405 | return; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 406 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 407 | |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 408 | if (!bss) |
| 409 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
| 410 | wdev->ssid, wdev->ssid_len, |
| 411 | WLAN_CAPABILITY_ESS, |
| 412 | WLAN_CAPABILITY_ESS); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 413 | |
| 414 | if (WARN_ON(!bss)) |
| 415 | return; |
| 416 | |
| 417 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 418 | wdev->current_bss = bss_from_pub(bss); |
| 419 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 420 | wdev->sme_state = CFG80211_SME_CONNECTED; |
| 421 | cfg80211_upload_connect_keys(wdev); |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 422 | |
| 423 | country_ie = (u8 *) ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY); |
| 424 | |
| 425 | if (!country_ie) |
| 426 | return; |
| 427 | |
| 428 | /* |
| 429 | * ieee80211_bss_get_ie() ensures we can access: |
| 430 | * - country_ie + 2, the start of the country ie data, and |
| 431 | * - and country_ie[1] which is the IE length |
| 432 | */ |
| 433 | regulatory_hint_11d(wdev->wiphy, |
| 434 | country_ie + 2, |
| 435 | country_ie[1]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 436 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 437 | |
| 438 | void cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 439 | const u8 *req_ie, size_t req_ie_len, |
| 440 | const u8 *resp_ie, size_t resp_ie_len, |
| 441 | u16 status, gfp_t gfp) |
| 442 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 443 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 444 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 445 | struct cfg80211_event *ev; |
| 446 | unsigned long flags; |
| 447 | |
| 448 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 449 | if (!ev) |
| 450 | return; |
| 451 | |
| 452 | ev->type = EVENT_CONNECT_RESULT; |
| 453 | memcpy(ev->cr.bssid, bssid, ETH_ALEN); |
| 454 | ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 455 | ev->cr.req_ie_len = req_ie_len; |
| 456 | memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len); |
| 457 | ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 458 | ev->cr.resp_ie_len = resp_ie_len; |
| 459 | memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len); |
| 460 | ev->cr.status = status; |
| 461 | |
| 462 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 463 | list_add_tail(&ev->list, &wdev->event_list); |
| 464 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 465 | schedule_work(&rdev->event_work); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 466 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 467 | EXPORT_SYMBOL(cfg80211_connect_result); |
| 468 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 469 | void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid, |
| 470 | const u8 *req_ie, size_t req_ie_len, |
| 471 | const u8 *resp_ie, size_t resp_ie_len) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 472 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 473 | struct cfg80211_bss *bss; |
| 474 | #ifdef CONFIG_WIRELESS_EXT |
| 475 | union iwreq_data wrqu; |
| 476 | #endif |
| 477 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 478 | ASSERT_WDEV_LOCK(wdev); |
| 479 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 480 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 481 | return; |
| 482 | |
| 483 | if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED)) |
| 484 | return; |
| 485 | |
| 486 | /* internal error -- how did we get to CONNECTED w/o BSS? */ |
| 487 | if (WARN_ON(!wdev->current_bss)) { |
| 488 | return; |
| 489 | } |
| 490 | |
| 491 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 492 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 493 | wdev->current_bss = NULL; |
| 494 | |
| 495 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
| 496 | wdev->ssid, wdev->ssid_len, |
| 497 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
| 498 | |
| 499 | if (WARN_ON(!bss)) |
| 500 | return; |
| 501 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 502 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 503 | wdev->current_bss = bss_from_pub(bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 504 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 505 | nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), wdev->netdev, bssid, |
| 506 | req_ie, req_ie_len, resp_ie, resp_ie_len, |
| 507 | GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 508 | |
| 509 | #ifdef CONFIG_WIRELESS_EXT |
| 510 | if (req_ie) { |
| 511 | memset(&wrqu, 0, sizeof(wrqu)); |
| 512 | wrqu.data.length = req_ie_len; |
Zhu Yi | 3409ff7 | 2009-07-20 11:47:44 +0800 | [diff] [blame] | 513 | wireless_send_event(wdev->netdev, IWEVASSOCREQIE, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 514 | &wrqu, req_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | if (resp_ie) { |
| 518 | memset(&wrqu, 0, sizeof(wrqu)); |
| 519 | wrqu.data.length = resp_ie_len; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 520 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, |
| 521 | &wrqu, resp_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | memset(&wrqu, 0, sizeof(wrqu)); |
| 525 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 526 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 527 | memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN); |
| 528 | wdev->wext.prev_bssid_valid = true; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 529 | wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 530 | #endif |
| 531 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 532 | |
| 533 | void cfg80211_roamed(struct net_device *dev, const u8 *bssid, |
| 534 | const u8 *req_ie, size_t req_ie_len, |
| 535 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 536 | { |
| 537 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 538 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 539 | struct cfg80211_event *ev; |
| 540 | unsigned long flags; |
| 541 | |
| 542 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 543 | if (!ev) |
| 544 | return; |
| 545 | |
| 546 | ev->type = EVENT_ROAMED; |
| 547 | memcpy(ev->rm.bssid, bssid, ETH_ALEN); |
| 548 | ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 549 | ev->rm.req_ie_len = req_ie_len; |
| 550 | memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len); |
| 551 | ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 552 | ev->rm.resp_ie_len = resp_ie_len; |
| 553 | memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len); |
| 554 | |
| 555 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 556 | list_add_tail(&ev->list, &wdev->event_list); |
| 557 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 558 | schedule_work(&rdev->event_work); |
| 559 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 560 | EXPORT_SYMBOL(cfg80211_roamed); |
| 561 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 562 | void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 563 | size_t ie_len, u16 reason, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 564 | { |
| 565 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 566 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 567 | int i; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 568 | #ifdef CONFIG_WIRELESS_EXT |
| 569 | union iwreq_data wrqu; |
| 570 | #endif |
| 571 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 572 | ASSERT_WDEV_LOCK(wdev); |
| 573 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 574 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 575 | return; |
| 576 | |
| 577 | if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED)) |
| 578 | return; |
| 579 | |
| 580 | if (wdev->current_bss) { |
| 581 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 582 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | wdev->current_bss = NULL; |
| 586 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 587 | wdev->ssid_len = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 588 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 589 | if (wdev->conn) { |
Johannes Berg | b6f0b63 | 2009-08-06 20:41:34 +0200 | [diff] [blame] | 590 | const u8 *bssid; |
| 591 | int ret; |
| 592 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 593 | kfree(wdev->conn->ie); |
| 594 | wdev->conn->ie = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 595 | kfree(wdev->conn); |
| 596 | wdev->conn = NULL; |
Johannes Berg | b6f0b63 | 2009-08-06 20:41:34 +0200 | [diff] [blame] | 597 | |
| 598 | /* |
| 599 | * If this disconnect was due to a disassoc, we |
| 600 | * we might still have an auth BSS around. For |
| 601 | * the userspace SME that's currently expected, |
| 602 | * but for the kernel SME (nl80211 CONNECT or |
| 603 | * wireless extensions) we want to clear up all |
| 604 | * state. |
| 605 | */ |
| 606 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 607 | if (!wdev->auth_bsses[i]) |
| 608 | continue; |
| 609 | bssid = wdev->auth_bsses[i]->pub.bssid; |
| 610 | ret = __cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0, |
| 611 | WLAN_REASON_DEAUTH_LEAVING); |
| 612 | WARN(ret, "deauth failed: %d\n", ret); |
| 613 | } |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 614 | } |
| 615 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 616 | nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap); |
| 617 | |
| 618 | /* |
| 619 | * Delete all the keys ... pairwise keys can't really |
| 620 | * exist any more anyway, but default keys might. |
| 621 | */ |
| 622 | if (rdev->ops->del_key) |
| 623 | for (i = 0; i < 6; i++) |
| 624 | rdev->ops->del_key(wdev->wiphy, dev, i, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 625 | |
| 626 | #ifdef CONFIG_WIRELESS_EXT |
| 627 | memset(&wrqu, 0, sizeof(wrqu)); |
| 628 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 629 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 630 | #endif |
| 631 | } |
| 632 | |
| 633 | void cfg80211_disconnected(struct net_device *dev, u16 reason, |
| 634 | u8 *ie, size_t ie_len, gfp_t gfp) |
| 635 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 636 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 637 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 638 | struct cfg80211_event *ev; |
| 639 | unsigned long flags; |
| 640 | |
| 641 | ev = kzalloc(sizeof(*ev) + ie_len, gfp); |
| 642 | if (!ev) |
| 643 | return; |
| 644 | |
| 645 | ev->type = EVENT_DISCONNECTED; |
| 646 | ev->dc.ie = ((u8 *)ev) + sizeof(*ev); |
| 647 | ev->dc.ie_len = ie_len; |
| 648 | memcpy((void *)ev->dc.ie, ie, ie_len); |
| 649 | ev->dc.reason = reason; |
| 650 | |
| 651 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 652 | list_add_tail(&ev->list, &wdev->event_list); |
| 653 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 654 | schedule_work(&rdev->event_work); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 655 | } |
| 656 | EXPORT_SYMBOL(cfg80211_disconnected); |
| 657 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 658 | int __cfg80211_connect(struct cfg80211_registered_device *rdev, |
| 659 | struct net_device *dev, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 660 | struct cfg80211_connect_params *connect, |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 661 | struct cfg80211_cached_keys *connkeys, |
| 662 | const u8 *prev_bssid) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 663 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 664 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 665 | struct ieee80211_channel *chan; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 666 | int err; |
| 667 | |
| 668 | ASSERT_WDEV_LOCK(wdev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 669 | |
| 670 | if (wdev->sme_state != CFG80211_SME_IDLE) |
| 671 | return -EALREADY; |
| 672 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 673 | chan = rdev_fixed_channel(rdev, wdev); |
| 674 | if (chan && chan != connect->channel) |
| 675 | return -EBUSY; |
| 676 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 677 | if (WARN_ON(wdev->connect_keys)) { |
| 678 | kfree(wdev->connect_keys); |
| 679 | wdev->connect_keys = NULL; |
| 680 | } |
| 681 | |
| 682 | if (connkeys && connkeys->def >= 0) { |
| 683 | int idx; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 684 | u32 cipher; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 685 | |
| 686 | idx = connkeys->def; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 687 | cipher = connkeys->params[idx].cipher; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 688 | /* If given a WEP key we may need it for shared key auth */ |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 689 | if (cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 690 | cipher == WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 691 | connect->key_idx = idx; |
| 692 | connect->key = connkeys->params[idx].key; |
| 693 | connect->key_len = connkeys->params[idx].key_len; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 694 | |
| 695 | /* |
| 696 | * If ciphers are not set (e.g. when going through |
| 697 | * iwconfig), we have to set them appropriately here. |
| 698 | */ |
| 699 | if (connect->crypto.cipher_group == 0) |
| 700 | connect->crypto.cipher_group = cipher; |
| 701 | |
| 702 | if (connect->crypto.n_ciphers_pairwise == 0) { |
| 703 | connect->crypto.n_ciphers_pairwise = 1; |
| 704 | connect->crypto.ciphers_pairwise[0] = cipher; |
| 705 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 709 | if (!rdev->ops->connect) { |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 710 | if (!rdev->ops->auth || !rdev->ops->assoc) |
| 711 | return -EOPNOTSUPP; |
| 712 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 713 | if (WARN_ON(wdev->conn)) |
| 714 | return -EINPROGRESS; |
| 715 | |
| 716 | wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL); |
| 717 | if (!wdev->conn) |
| 718 | return -ENOMEM; |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 719 | |
| 720 | /* |
| 721 | * Copy all parameters, and treat explicitly IEs, BSSID, SSID. |
| 722 | */ |
| 723 | memcpy(&wdev->conn->params, connect, sizeof(*connect)); |
| 724 | if (connect->bssid) { |
| 725 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 726 | memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN); |
| 727 | } |
| 728 | |
| 729 | if (connect->ie) { |
| 730 | wdev->conn->ie = kmemdup(connect->ie, connect->ie_len, |
| 731 | GFP_KERNEL); |
| 732 | wdev->conn->params.ie = wdev->conn->ie; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 733 | if (!wdev->conn->ie) { |
| 734 | kfree(wdev->conn); |
| 735 | wdev->conn = NULL; |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 736 | return -ENOMEM; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 737 | } |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) { |
| 741 | wdev->conn->auto_auth = true; |
| 742 | /* start with open system ... should mostly work */ |
| 743 | wdev->conn->params.auth_type = |
| 744 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 745 | } else { |
| 746 | wdev->conn->auto_auth = false; |
| 747 | } |
| 748 | |
| 749 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); |
| 750 | wdev->ssid_len = connect->ssid_len; |
| 751 | wdev->conn->params.ssid = wdev->ssid; |
| 752 | wdev->conn->params.ssid_len = connect->ssid_len; |
| 753 | |
| 754 | /* don't care about result -- but fill bssid & channel */ |
| 755 | if (!wdev->conn->params.bssid || !wdev->conn->params.channel) |
| 756 | cfg80211_get_conn_bss(wdev); |
| 757 | |
| 758 | wdev->sme_state = CFG80211_SME_CONNECTING; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 759 | wdev->connect_keys = connkeys; |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 760 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 761 | if (prev_bssid) { |
| 762 | memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN); |
| 763 | wdev->conn->prev_bssid_valid = true; |
| 764 | } |
| 765 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 766 | /* we're good if we have both BSSID and channel */ |
| 767 | if (wdev->conn->params.bssid && wdev->conn->params.channel) { |
| 768 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 769 | err = cfg80211_conn_do_work(wdev); |
| 770 | } else { |
| 771 | /* otherwise we'll need to scan for the AP first */ |
| 772 | err = cfg80211_conn_scan(wdev); |
| 773 | /* |
| 774 | * If we can't scan right now, then we need to scan again |
| 775 | * after the current scan finished, since the parameters |
| 776 | * changed (unless we find a good AP anyway). |
| 777 | */ |
| 778 | if (err == -EBUSY) { |
| 779 | err = 0; |
| 780 | wdev->conn->state = CFG80211_CONN_SCAN_AGAIN; |
| 781 | } |
| 782 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 783 | if (err) { |
David Kilroy | 415ad1ef | 2009-08-19 00:43:31 +0100 | [diff] [blame^] | 784 | kfree(wdev->conn->ie); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 785 | kfree(wdev->conn); |
| 786 | wdev->conn = NULL; |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 787 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 788 | wdev->connect_keys = NULL; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 789 | wdev->ssid_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 790 | } |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 791 | |
| 792 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 793 | } else { |
| 794 | wdev->sme_state = CFG80211_SME_CONNECTING; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 795 | wdev->connect_keys = connkeys; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 796 | err = rdev->ops->connect(&rdev->wiphy, dev, connect); |
| 797 | if (err) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 798 | wdev->connect_keys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 799 | wdev->sme_state = CFG80211_SME_IDLE; |
| 800 | return err; |
| 801 | } |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 802 | |
| 803 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); |
| 804 | wdev->ssid_len = connect->ssid_len; |
| 805 | |
| 806 | return 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 807 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 808 | } |
| 809 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 810 | int cfg80211_connect(struct cfg80211_registered_device *rdev, |
| 811 | struct net_device *dev, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 812 | struct cfg80211_connect_params *connect, |
| 813 | struct cfg80211_cached_keys *connkeys) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 814 | { |
| 815 | int err; |
| 816 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 817 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 818 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 819 | err = __cfg80211_connect(rdev, dev, connect, connkeys, NULL); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 820 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 821 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 822 | |
| 823 | return err; |
| 824 | } |
| 825 | |
| 826 | int __cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
| 827 | struct net_device *dev, u16 reason, bool wextev) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 828 | { |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 829 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 830 | int err; |
| 831 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 832 | ASSERT_WDEV_LOCK(wdev); |
| 833 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 834 | if (wdev->sme_state == CFG80211_SME_IDLE) |
| 835 | return -EINVAL; |
| 836 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 837 | kfree(wdev->connect_keys); |
| 838 | wdev->connect_keys = NULL; |
| 839 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 840 | if (!rdev->ops->disconnect) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 841 | if (!rdev->ops->deauth) |
| 842 | return -EOPNOTSUPP; |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 843 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 844 | /* was it connected by userspace SME? */ |
| 845 | if (!wdev->conn) { |
| 846 | cfg80211_mlme_down(rdev, dev); |
| 847 | return 0; |
| 848 | } |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 849 | |
| 850 | if (wdev->sme_state == CFG80211_SME_CONNECTING && |
| 851 | (wdev->conn->state == CFG80211_CONN_SCANNING || |
| 852 | wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)) { |
| 853 | wdev->sme_state = CFG80211_SME_IDLE; |
David Kilroy | 415ad1ef | 2009-08-19 00:43:31 +0100 | [diff] [blame^] | 854 | kfree(wdev->conn->ie); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 855 | kfree(wdev->conn); |
| 856 | wdev->conn = NULL; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 857 | wdev->ssid_len = 0; |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 858 | return 0; |
| 859 | } |
| 860 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 861 | /* wdev->conn->params.bssid must be set if > SCANNING */ |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 862 | err = __cfg80211_mlme_deauth(rdev, dev, |
| 863 | wdev->conn->params.bssid, |
| 864 | NULL, 0, reason); |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 865 | if (err) |
| 866 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 867 | } else { |
| 868 | err = rdev->ops->disconnect(&rdev->wiphy, dev, reason); |
| 869 | if (err) |
| 870 | return err; |
| 871 | } |
| 872 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 873 | if (wdev->sme_state == CFG80211_SME_CONNECTED) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 874 | __cfg80211_disconnected(dev, NULL, 0, 0, false); |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 875 | else if (wdev->sme_state == CFG80211_SME_CONNECTING) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 876 | __cfg80211_connect_result(dev, NULL, NULL, 0, NULL, 0, |
| 877 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 878 | wextev, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 879 | |
| 880 | return 0; |
| 881 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 882 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 883 | int cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
| 884 | struct net_device *dev, |
| 885 | u16 reason, bool wextev) |
| 886 | { |
| 887 | int err; |
| 888 | |
| 889 | wdev_lock(dev->ieee80211_ptr); |
| 890 | err = __cfg80211_disconnect(rdev, dev, reason, wextev); |
| 891 | wdev_unlock(dev->ieee80211_ptr); |
| 892 | |
| 893 | return err; |
| 894 | } |
| 895 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 896 | void cfg80211_sme_disassoc(struct net_device *dev, int idx) |
| 897 | { |
| 898 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 899 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 900 | u8 bssid[ETH_ALEN]; |
| 901 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 902 | ASSERT_WDEV_LOCK(wdev); |
| 903 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 904 | if (!wdev->conn) |
| 905 | return; |
| 906 | |
| 907 | if (wdev->conn->state == CFG80211_CONN_IDLE) |
| 908 | return; |
| 909 | |
| 910 | /* |
| 911 | * Ok, so the association was made by this SME -- we don't |
| 912 | * want it any more so deauthenticate too. |
| 913 | */ |
| 914 | |
| 915 | if (!wdev->auth_bsses[idx]) |
| 916 | return; |
| 917 | |
| 918 | memcpy(bssid, wdev->auth_bsses[idx]->pub.bssid, ETH_ALEN); |
Johannes Berg | ec3f149 | 2009-07-10 02:45:38 +0200 | [diff] [blame] | 919 | if (__cfg80211_mlme_deauth(rdev, dev, bssid, |
| 920 | NULL, 0, WLAN_REASON_DEAUTH_LEAVING)) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 921 | /* whatever -- assume gone anyway */ |
| 922 | cfg80211_unhold_bss(wdev->auth_bsses[idx]); |
| 923 | cfg80211_put_bss(&wdev->auth_bsses[idx]->pub); |
| 924 | wdev->auth_bsses[idx] = NULL; |
| 925 | } |
| 926 | } |