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