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