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