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