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