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