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