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