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