blob: 5e8123ee63fd316d48e224fe65b8336300ec2b79 [file] [log] [blame]
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001/*
2 * cfg80211 MLME SAP interface
3 *
4 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
5 */
6
7#include <linux/kernel.h>
8#include <linux/module.h>
Felix Fietkauc6fb08a2012-03-18 22:58:04 +01009#include <linux/etherdevice.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010#include <linux/netdevice.h>
11#include <linux/nl80211.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berga9a11622009-07-27 12:01:53 +020013#include <linux/wireless.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014#include <net/cfg80211.h>
Johannes Berga9a11622009-07-27 12:01:53 +020015#include <net/iw_handler.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020016#include "core.h"
17#include "nl80211.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030018#include "rdev-ops.h"
19
Jouni Malinen6039f6d2009-03-19 13:39:21 +020020
Johannes Bergcb0b4be2009-07-07 03:56:07 +020021void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020022{
Johannes Berg19957bb2009-07-02 17:20:43 +020023 struct wireless_dev *wdev = dev->ieee80211_ptr;
24 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020025 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +020026
Beni Lev4ee3e062012-08-27 12:49:39 +030027 trace_cfg80211_send_rx_auth(dev);
Johannes Berg667503dd2009-07-07 03:56:11 +020028 wdev_lock(wdev);
Johannes Bergcb0b4be2009-07-07 03:56:07 +020029
Johannes Berg95de8172012-01-20 13:55:25 +010030 nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL);
31 cfg80211_sme_rx_auth(dev, buf, len);
Johannes Berg667503dd2009-07-07 03:56:11 +020032
33 wdev_unlock(wdev);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020034}
35EXPORT_SYMBOL(cfg80211_send_rx_auth);
36
Johannes Berg95de8172012-01-20 13:55:25 +010037void cfg80211_send_rx_assoc(struct net_device *dev, struct cfg80211_bss *bss,
38 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020039{
Johannes Berg6829c872009-07-02 09:13:27 +020040 u16 status_code;
41 struct wireless_dev *wdev = dev->ieee80211_ptr;
42 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020043 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020044 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
45 u8 *ie = mgmt->u.assoc_resp.variable;
Johannes Berg95de8172012-01-20 13:55:25 +010046 int ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
Johannes Berg6829c872009-07-02 09:13:27 +020047
Beni Lev4ee3e062012-08-27 12:49:39 +030048 trace_cfg80211_send_rx_assoc(dev, bss);
Johannes Berg667503dd2009-07-07 03:56:11 +020049 wdev_lock(wdev);
Johannes Bergcb0b4be2009-07-07 03:56:07 +020050
Johannes Berg6829c872009-07-02 09:13:27 +020051 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
52
Johannes Bergf401a6f2009-08-07 14:51:05 +020053 /*
54 * This is a bit of a hack, we don't notify userspace of
55 * a (re-)association reply if we tried to send a reassoc
56 * and got a reject -- we only try again with an assoc
57 * frame instead of reassoc.
58 */
59 if (status_code != WLAN_STATUS_SUCCESS && wdev->conn &&
Johannes Berg95de8172012-01-20 13:55:25 +010060 cfg80211_sme_failed_reassoc(wdev)) {
61 cfg80211_put_bss(bss);
Johannes Bergf401a6f2009-08-07 14:51:05 +020062 goto out;
Johannes Berg95de8172012-01-20 13:55:25 +010063 }
Johannes Bergf401a6f2009-08-07 14:51:05 +020064
Johannes Bergcb0b4be2009-07-07 03:56:07 +020065 nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL);
Johannes Berg6829c872009-07-02 09:13:27 +020066
Johannes Berg95de8172012-01-20 13:55:25 +010067 if (status_code != WLAN_STATUS_SUCCESS && wdev->conn) {
Johannes Berg7d930bc2009-10-20 15:08:53 +090068 cfg80211_sme_failed_assoc(wdev);
Johannes Berg7d930bc2009-10-20 15:08:53 +090069 /*
70 * do not call connect_result() now because the
71 * sme will schedule work that does it later.
72 */
Johannes Berg95de8172012-01-20 13:55:25 +010073 cfg80211_put_bss(bss);
Johannes Berg7d930bc2009-10-20 15:08:53 +090074 goto out;
Johannes Bergdf7fc0f2009-07-29 11:23:49 +020075 }
76
Johannes Bergea416a72009-08-17 12:22:14 +020077 if (!wdev->conn && wdev->sme_state == CFG80211_SME_IDLE) {
78 /*
79 * This is for the userspace SME, the CONNECTING
80 * state will be changed to CONNECTED by
81 * __cfg80211_connect_result() below.
82 */
83 wdev->sme_state = CFG80211_SME_CONNECTING;
84 }
85
Johannes Berg95de8172012-01-20 13:55:25 +010086 /* this consumes the bss reference */
Johannes Bergdf7fc0f2009-07-29 11:23:49 +020087 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs,
88 status_code,
Johannes Berg95de8172012-01-20 13:55:25 +010089 status_code == WLAN_STATUS_SUCCESS, bss);
Johannes Bergf401a6f2009-08-07 14:51:05 +020090 out:
Johannes Berg667503dd2009-07-07 03:56:11 +020091 wdev_unlock(wdev);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020092}
93EXPORT_SYMBOL(cfg80211_send_rx_assoc);
94
Holger Schurigce470612009-10-13 13:28:13 +020095void __cfg80211_send_deauth(struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +020096 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020097{
Johannes Berg6829c872009-07-02 09:13:27 +020098 struct wireless_dev *wdev = dev->ieee80211_ptr;
99 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen6039f6d2009-03-19 13:39:21 +0200100 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200101 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
Johannes Berg19957bb2009-07-02 17:20:43 +0200102 const u8 *bssid = mgmt->bssid;
Johannes Berg95de8172012-01-20 13:55:25 +0100103 bool was_current = false;
Johannes Berg6829c872009-07-02 09:13:27 +0200104
Beni Lev4ee3e062012-08-27 12:49:39 +0300105 trace___cfg80211_send_deauth(dev);
Johannes Berg667503dd2009-07-07 03:56:11 +0200106 ASSERT_WDEV_LOCK(wdev);
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200107
Johannes Berg19957bb2009-07-02 17:20:43 +0200108 if (wdev->current_bss &&
Joe Perchesac422d32012-05-08 18:56:55 +0000109 ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) {
Johannes Berg19957bb2009-07-02 17:20:43 +0200110 cfg80211_unhold_bss(wdev->current_bss);
111 cfg80211_put_bss(&wdev->current_bss->pub);
112 wdev->current_bss = NULL;
Johannes Berg3f3b6a82010-08-05 10:20:27 +0200113 was_current = true;
Johannes Berg19957bb2009-07-02 17:20:43 +0200114 }
Johannes Berg19957bb2009-07-02 17:20:43 +0200115
Johannes Berg5fba4af2009-12-02 12:43:42 +0100116 nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
117
Johannes Berg3f3b6a82010-08-05 10:20:27 +0200118 if (wdev->sme_state == CFG80211_SME_CONNECTED && was_current) {
Johannes Berg6829c872009-07-02 09:13:27 +0200119 u16 reason_code;
120 bool from_ap;
121
122 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
123
Joe Perchesac422d32012-05-08 18:56:55 +0000124 from_ap = !ether_addr_equal(mgmt->sa, dev->dev_addr);
Johannes Berg667503dd2009-07-07 03:56:11 +0200125 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
Johannes Berg6829c872009-07-02 09:13:27 +0200126 } else if (wdev->sme_state == CFG80211_SME_CONNECTING) {
Johannes Berg667503dd2009-07-07 03:56:11 +0200127 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0,
128 WLAN_STATUS_UNSPECIFIED_FAILURE,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200129 false, NULL);
Johannes Berg667503dd2009-07-07 03:56:11 +0200130 }
131}
Holger Schurigce470612009-10-13 13:28:13 +0200132EXPORT_SYMBOL(__cfg80211_send_deauth);
Johannes Berg667503dd2009-07-07 03:56:11 +0200133
Holger Schurigce470612009-10-13 13:28:13 +0200134void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len)
Johannes Berg667503dd2009-07-07 03:56:11 +0200135{
136 struct wireless_dev *wdev = dev->ieee80211_ptr;
137
Holger Schurigce470612009-10-13 13:28:13 +0200138 wdev_lock(wdev);
139 __cfg80211_send_deauth(dev, buf, len);
140 wdev_unlock(wdev);
Jouni Malinen6039f6d2009-03-19 13:39:21 +0200141}
Jouni Malinen53b46b82009-03-27 20:53:56 +0200142EXPORT_SYMBOL(cfg80211_send_deauth);
Jouni Malinen6039f6d2009-03-19 13:39:21 +0200143
Holger Schurigce470612009-10-13 13:28:13 +0200144void __cfg80211_send_disassoc(struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +0200145 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +0200146{
Johannes Berg6829c872009-07-02 09:13:27 +0200147 struct wireless_dev *wdev = dev->ieee80211_ptr;
148 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen6039f6d2009-03-19 13:39:21 +0200149 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200150 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
Johannes Berg19957bb2009-07-02 17:20:43 +0200151 const u8 *bssid = mgmt->bssid;
Johannes Berg19957bb2009-07-02 17:20:43 +0200152 u16 reason_code;
153 bool from_ap;
Johannes Berg6829c872009-07-02 09:13:27 +0200154
Beni Lev4ee3e062012-08-27 12:49:39 +0300155 trace___cfg80211_send_disassoc(dev);
Johannes Berg596a07c2009-07-11 00:17:32 +0200156 ASSERT_WDEV_LOCK(wdev);
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200157
158 nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL);
Johannes Berg6829c872009-07-02 09:13:27 +0200159
Johannes Berg596a07c2009-07-11 00:17:32 +0200160 if (wdev->sme_state != CFG80211_SME_CONNECTED)
161 return;
Johannes Berg6829c872009-07-02 09:13:27 +0200162
Johannes Berg19957bb2009-07-02 17:20:43 +0200163 if (wdev->current_bss &&
Joe Perchesac422d32012-05-08 18:56:55 +0000164 ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) {
Johannes Berg95de8172012-01-20 13:55:25 +0100165 cfg80211_sme_disassoc(dev, wdev->current_bss);
166 cfg80211_unhold_bss(wdev->current_bss);
167 cfg80211_put_bss(&wdev->current_bss->pub);
168 wdev->current_bss = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +0200169 } else
170 WARN_ON(1);
Johannes Berg6829c872009-07-02 09:13:27 +0200171
Johannes Berg6829c872009-07-02 09:13:27 +0200172
Johannes Berg19957bb2009-07-02 17:20:43 +0200173 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
174
Joe Perchesac422d32012-05-08 18:56:55 +0000175 from_ap = !ether_addr_equal(mgmt->sa, dev->dev_addr);
Johannes Berg667503dd2009-07-07 03:56:11 +0200176 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
Johannes Berg667503dd2009-07-07 03:56:11 +0200177}
Holger Schurigce470612009-10-13 13:28:13 +0200178EXPORT_SYMBOL(__cfg80211_send_disassoc);
Johannes Berg667503dd2009-07-07 03:56:11 +0200179
Holger Schurigce470612009-10-13 13:28:13 +0200180void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len)
Johannes Berg667503dd2009-07-07 03:56:11 +0200181{
182 struct wireless_dev *wdev = dev->ieee80211_ptr;
183
Holger Schurigce470612009-10-13 13:28:13 +0200184 wdev_lock(wdev);
185 __cfg80211_send_disassoc(dev, buf, len);
186 wdev_unlock(wdev);
Jouni Malinen6039f6d2009-03-19 13:39:21 +0200187}
Jouni Malinen53b46b82009-03-27 20:53:56 +0200188EXPORT_SYMBOL(cfg80211_send_disassoc);
Jouni Malinena3b8b052009-03-27 21:59:49 +0200189
Jouni Malinencf4e5942010-12-16 00:52:40 +0200190void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
191 size_t len)
192{
193 struct wireless_dev *wdev = dev->ieee80211_ptr;
194 struct wiphy *wiphy = wdev->wiphy;
195 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
196
Beni Lev4ee3e062012-08-27 12:49:39 +0300197 trace_cfg80211_send_unprot_deauth(dev);
Jouni Malinencf4e5942010-12-16 00:52:40 +0200198 nl80211_send_unprot_deauth(rdev, dev, buf, len, GFP_ATOMIC);
199}
200EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
201
202void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
203 size_t len)
204{
205 struct wireless_dev *wdev = dev->ieee80211_ptr;
206 struct wiphy *wiphy = wdev->wiphy;
207 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
208
Beni Lev4ee3e062012-08-27 12:49:39 +0300209 trace_cfg80211_send_unprot_disassoc(dev);
Jouni Malinencf4e5942010-12-16 00:52:40 +0200210 nl80211_send_unprot_disassoc(rdev, dev, buf, len, GFP_ATOMIC);
211}
212EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
213
Johannes Berga58ce432009-11-19 12:45:42 +0100214void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr)
215{
216 struct wireless_dev *wdev = dev->ieee80211_ptr;
217 struct wiphy *wiphy = wdev->wiphy;
218 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
219
Beni Lev4ee3e062012-08-27 12:49:39 +0300220 trace_cfg80211_send_auth_timeout(dev, addr);
Johannes Berga58ce432009-11-19 12:45:42 +0100221 wdev_lock(wdev);
222
223 nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
224 if (wdev->sme_state == CFG80211_SME_CONNECTING)
225 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
226 WLAN_STATUS_UNSPECIFIED_FAILURE,
227 false, NULL);
228
Johannes Berg667503dd2009-07-07 03:56:11 +0200229 wdev_unlock(wdev);
Jouni Malinen1965c852009-04-22 21:38:25 +0300230}
231EXPORT_SYMBOL(cfg80211_send_auth_timeout);
232
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200233void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr)
Jouni Malinen1965c852009-04-22 21:38:25 +0300234{
Johannes Berg6829c872009-07-02 09:13:27 +0200235 struct wireless_dev *wdev = dev->ieee80211_ptr;
236 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen1965c852009-04-22 21:38:25 +0300237 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +0200238
Beni Lev4ee3e062012-08-27 12:49:39 +0300239 trace_cfg80211_send_assoc_timeout(dev, addr);
Johannes Berg667503dd2009-07-07 03:56:11 +0200240 wdev_lock(wdev);
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200241
242 nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL);
Johannes Berg6829c872009-07-02 09:13:27 +0200243 if (wdev->sme_state == CFG80211_SME_CONNECTING)
Johannes Berg667503dd2009-07-07 03:56:11 +0200244 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
245 WLAN_STATUS_UNSPECIFIED_FAILURE,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200246 false, NULL);
Johannes Berg19957bb2009-07-02 17:20:43 +0200247
Johannes Berg667503dd2009-07-07 03:56:11 +0200248 wdev_unlock(wdev);
Jouni Malinen1965c852009-04-22 21:38:25 +0300249}
250EXPORT_SYMBOL(cfg80211_send_assoc_timeout);
251
Jouni Malinena3b8b052009-03-27 21:59:49 +0200252void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
253 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +0200254 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +0200255{
256 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
257 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg3d23e342009-09-29 23:27:28 +0200258#ifdef CONFIG_CFG80211_WEXT
Johannes Bergf58d4ed2009-06-19 02:45:21 +0200259 union iwreq_data wrqu;
Johannes Berge6d6e342009-07-01 21:26:47 +0200260 char *buf = kmalloc(128, gfp);
Johannes Bergf58d4ed2009-06-19 02:45:21 +0200261
262 if (buf) {
263 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
264 "keyid=%d %scast addr=%pM)", key_id,
265 key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni",
266 addr);
267 memset(&wrqu, 0, sizeof(wrqu));
268 wrqu.data.length = strlen(buf);
269 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
270 kfree(buf);
271 }
272#endif
273
Beni Lev4ee3e062012-08-27 12:49:39 +0300274 trace_cfg80211_michael_mic_failure(dev, addr, key_type, key_id, tsc);
Johannes Berge6d6e342009-07-01 21:26:47 +0200275 nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +0200276}
277EXPORT_SYMBOL(cfg80211_michael_mic_failure);
Johannes Berg19957bb2009-07-02 17:20:43 +0200278
279/* some MLME handling for userspace SME */
Johannes Berg667503dd2009-07-07 03:56:11 +0200280int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
281 struct net_device *dev,
282 struct ieee80211_channel *chan,
283 enum nl80211_auth_type auth_type,
284 const u8 *bssid,
285 const u8 *ssid, int ssid_len,
Johannes Bergfffd0932009-07-08 14:22:54 +0200286 const u8 *ie, int ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +0300287 const u8 *key, int key_len, int key_idx,
288 const u8 *sae_data, int sae_data_len)
Johannes Berg19957bb2009-07-02 17:20:43 +0200289{
290 struct wireless_dev *wdev = dev->ieee80211_ptr;
291 struct cfg80211_auth_request req;
Johannes Berg95de8172012-01-20 13:55:25 +0100292 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200293
Johannes Berg667503dd2009-07-07 03:56:11 +0200294 ASSERT_WDEV_LOCK(wdev);
295
Johannes Bergfffd0932009-07-08 14:22:54 +0200296 if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
297 if (!key || !key_len || key_idx < 0 || key_idx > 4)
298 return -EINVAL;
299
Johannes Berg0a9b5e12009-07-02 18:26:18 +0200300 if (wdev->current_bss &&
Joe Perchesac422d32012-05-08 18:56:55 +0000301 ether_addr_equal(bssid, wdev->current_bss->pub.bssid))
Johannes Berg0a9b5e12009-07-02 18:26:18 +0200302 return -EALREADY;
303
Johannes Berg19957bb2009-07-02 17:20:43 +0200304 memset(&req, 0, sizeof(req));
305
306 req.ie = ie;
307 req.ie_len = ie_len;
Jouni Malinene39e5b52012-09-30 19:29:39 +0300308 req.sae_data = sae_data;
309 req.sae_data_len = sae_data_len;
Johannes Berg19957bb2009-07-02 17:20:43 +0200310 req.auth_type = auth_type;
311 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
312 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
Johannes Bergfffd0932009-07-08 14:22:54 +0200313 req.key = key;
314 req.key_len = key_len;
315 req.key_idx = key_idx;
Johannes Berg19957bb2009-07-02 17:20:43 +0200316 if (!req.bss)
317 return -ENOENT;
318
Michal Kaziore4e32452012-06-29 12:47:08 +0200319 err = cfg80211_can_use_chan(rdev, wdev, req.bss->channel,
320 CHAN_MODE_SHARED);
321 if (err)
322 goto out;
323
Hila Gonene35e4d22012-06-27 17:19:42 +0300324 err = rdev_auth(rdev, dev, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200325
Michal Kaziore4e32452012-06-29 12:47:08 +0200326out:
Johannes Berg95de8172012-01-20 13:55:25 +0100327 cfg80211_put_bss(req.bss);
Johannes Berg19957bb2009-07-02 17:20:43 +0200328 return err;
329}
330
Johannes Berg667503dd2009-07-07 03:56:11 +0200331int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
332 struct net_device *dev, struct ieee80211_channel *chan,
333 enum nl80211_auth_type auth_type, const u8 *bssid,
334 const u8 *ssid, int ssid_len,
Johannes Bergfffd0932009-07-08 14:22:54 +0200335 const u8 *ie, int ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +0300336 const u8 *key, int key_len, int key_idx,
337 const u8 *sae_data, int sae_data_len)
Johannes Berg667503dd2009-07-07 03:56:11 +0200338{
339 int err;
340
Michal Kaziore4e32452012-06-29 12:47:08 +0200341 mutex_lock(&rdev->devlist_mtx);
Johannes Berg667503dd2009-07-07 03:56:11 +0200342 wdev_lock(dev->ieee80211_ptr);
343 err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
Johannes Bergfffd0932009-07-08 14:22:54 +0200344 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +0300345 key, key_len, key_idx,
346 sae_data, sae_data_len);
Johannes Berg667503dd2009-07-07 03:56:11 +0200347 wdev_unlock(dev->ieee80211_ptr);
Michal Kaziore4e32452012-06-29 12:47:08 +0200348 mutex_unlock(&rdev->devlist_mtx);
Johannes Berg667503dd2009-07-07 03:56:11 +0200349
350 return err;
351}
352
Ben Greear7e7c8922011-11-18 11:31:59 -0800353/* Do a logical ht_capa &= ht_capa_mask. */
354void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
355 const struct ieee80211_ht_cap *ht_capa_mask)
356{
357 int i;
358 u8 *p1, *p2;
359 if (!ht_capa_mask) {
360 memset(ht_capa, 0, sizeof(*ht_capa));
361 return;
362 }
363
364 p1 = (u8*)(ht_capa);
365 p2 = (u8*)(ht_capa_mask);
366 for (i = 0; i<sizeof(*ht_capa); i++)
367 p1[i] &= p2[i];
368}
369
Johannes Berg667503dd2009-07-07 03:56:11 +0200370int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
371 struct net_device *dev,
372 struct ieee80211_channel *chan,
373 const u8 *bssid, const u8 *prev_bssid,
374 const u8 *ssid, int ssid_len,
375 const u8 *ie, int ie_len, bool use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -0800376 struct cfg80211_crypto_settings *crypt,
377 u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
378 struct ieee80211_ht_cap *ht_capa_mask)
Johannes Berg19957bb2009-07-02 17:20:43 +0200379{
380 struct wireless_dev *wdev = dev->ieee80211_ptr;
381 struct cfg80211_assoc_request req;
Johannes Berg95de8172012-01-20 13:55:25 +0100382 int err;
Jouni Malinen24b6b152009-11-17 21:35:38 +0200383 bool was_connected = false;
Johannes Berg19957bb2009-07-02 17:20:43 +0200384
Johannes Berg667503dd2009-07-07 03:56:11 +0200385 ASSERT_WDEV_LOCK(wdev);
386
Johannes Berg19957bb2009-07-02 17:20:43 +0200387 memset(&req, 0, sizeof(req));
388
Jouni Malinen24b6b152009-11-17 21:35:38 +0200389 if (wdev->current_bss && prev_bssid &&
Joe Perchesac422d32012-05-08 18:56:55 +0000390 ether_addr_equal(wdev->current_bss->pub.bssid, prev_bssid)) {
Jouni Malinen24b6b152009-11-17 21:35:38 +0200391 /*
392 * Trying to reassociate: Allow this to proceed and let the old
393 * association to be dropped when the new one is completed.
394 */
395 if (wdev->sme_state == CFG80211_SME_CONNECTED) {
396 was_connected = true;
397 wdev->sme_state = CFG80211_SME_CONNECTING;
398 }
399 } else if (wdev->current_bss)
Johannes Berg19957bb2009-07-02 17:20:43 +0200400 return -EALREADY;
401
402 req.ie = ie;
403 req.ie_len = ie_len;
404 memcpy(&req.crypto, crypt, sizeof(req.crypto));
405 req.use_mfp = use_mfp;
Johannes Berg3e5d7642009-07-07 14:37:26 +0200406 req.prev_bssid = prev_bssid;
Ben Greear7e7c8922011-11-18 11:31:59 -0800407 req.flags = assoc_flags;
408 if (ht_capa)
409 memcpy(&req.ht_capa, ht_capa, sizeof(req.ht_capa));
410 if (ht_capa_mask)
411 memcpy(&req.ht_capa_mask, ht_capa_mask,
412 sizeof(req.ht_capa_mask));
413 cfg80211_oper_and_ht_capa(&req.ht_capa_mask,
414 rdev->wiphy.ht_capa_mod_mask);
415
Johannes Berg19957bb2009-07-02 17:20:43 +0200416 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
417 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
Jouni Malinen24b6b152009-11-17 21:35:38 +0200418 if (!req.bss) {
419 if (was_connected)
420 wdev->sme_state = CFG80211_SME_CONNECTED;
Johannes Berg19957bb2009-07-02 17:20:43 +0200421 return -ENOENT;
Jouni Malinen24b6b152009-11-17 21:35:38 +0200422 }
Johannes Berg19957bb2009-07-02 17:20:43 +0200423
Michal Kaziore4e32452012-06-29 12:47:08 +0200424 err = cfg80211_can_use_chan(rdev, wdev, req.bss->channel,
425 CHAN_MODE_SHARED);
426 if (err)
427 goto out;
428
Hila Gonene35e4d22012-06-27 17:19:42 +0300429 err = rdev_assoc(rdev, dev, &req);
Johannes Berg95de8172012-01-20 13:55:25 +0100430
Michal Kaziore4e32452012-06-29 12:47:08 +0200431out:
Johannes Berg95de8172012-01-20 13:55:25 +0100432 if (err) {
433 if (was_connected)
434 wdev->sme_state = CFG80211_SME_CONNECTED;
435 cfg80211_put_bss(req.bss);
436 }
437
Johannes Berg19957bb2009-07-02 17:20:43 +0200438 return err;
439}
440
Johannes Berg667503dd2009-07-07 03:56:11 +0200441int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
442 struct net_device *dev,
443 struct ieee80211_channel *chan,
444 const u8 *bssid, const u8 *prev_bssid,
445 const u8 *ssid, int ssid_len,
446 const u8 *ie, int ie_len, bool use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -0800447 struct cfg80211_crypto_settings *crypt,
448 u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
449 struct ieee80211_ht_cap *ht_capa_mask)
Johannes Berg667503dd2009-07-07 03:56:11 +0200450{
451 struct wireless_dev *wdev = dev->ieee80211_ptr;
452 int err;
453
Michal Kaziore4e32452012-06-29 12:47:08 +0200454 mutex_lock(&rdev->devlist_mtx);
Johannes Berg667503dd2009-07-07 03:56:11 +0200455 wdev_lock(wdev);
456 err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
Ben Greear7e7c8922011-11-18 11:31:59 -0800457 ssid, ssid_len, ie, ie_len, use_mfp, crypt,
458 assoc_flags, ht_capa, ht_capa_mask);
Johannes Berg667503dd2009-07-07 03:56:11 +0200459 wdev_unlock(wdev);
Michal Kaziore4e32452012-06-29 12:47:08 +0200460 mutex_unlock(&rdev->devlist_mtx);
Johannes Berg667503dd2009-07-07 03:56:11 +0200461
462 return err;
463}
464
465int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
466 struct net_device *dev, const u8 *bssid,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300467 const u8 *ie, int ie_len, u16 reason,
468 bool local_state_change)
Johannes Berg19957bb2009-07-02 17:20:43 +0200469{
470 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100471 struct cfg80211_deauth_request req = {
472 .bssid = bssid,
473 .reason_code = reason,
474 .ie = ie,
475 .ie_len = ie_len,
Stanislaw Gruszka68632552012-10-15 14:52:41 +0200476 .local_state_change = local_state_change,
Johannes Berg95de8172012-01-20 13:55:25 +0100477 };
Johannes Berg19957bb2009-07-02 17:20:43 +0200478
Johannes Berg667503dd2009-07-07 03:56:11 +0200479 ASSERT_WDEV_LOCK(wdev);
480
Stanislaw Gruszka68632552012-10-15 14:52:41 +0200481 if (local_state_change && (!wdev->current_bss ||
482 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
Johannes Berg95de8172012-01-20 13:55:25 +0100483 return 0;
Johannes Berg19957bb2009-07-02 17:20:43 +0200484
Hila Gonene35e4d22012-06-27 17:19:42 +0300485 return rdev_deauth(rdev, dev, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200486}
487
Johannes Berg667503dd2009-07-07 03:56:11 +0200488int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
489 struct net_device *dev, const u8 *bssid,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300490 const u8 *ie, int ie_len, u16 reason,
491 bool local_state_change)
Johannes Berg667503dd2009-07-07 03:56:11 +0200492{
493 struct wireless_dev *wdev = dev->ieee80211_ptr;
494 int err;
495
496 wdev_lock(wdev);
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300497 err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason,
498 local_state_change);
Johannes Berg667503dd2009-07-07 03:56:11 +0200499 wdev_unlock(wdev);
500
501 return err;
502}
503
504static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
505 struct net_device *dev, const u8 *bssid,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300506 const u8 *ie, int ie_len, u16 reason,
507 bool local_state_change)
Johannes Berg19957bb2009-07-02 17:20:43 +0200508{
509 struct wireless_dev *wdev = dev->ieee80211_ptr;
510 struct cfg80211_disassoc_request req;
511
Johannes Berg667503dd2009-07-07 03:56:11 +0200512 ASSERT_WDEV_LOCK(wdev);
513
Johannes Bergf9d6b402009-07-27 10:22:28 +0200514 if (wdev->sme_state != CFG80211_SME_CONNECTED)
515 return -ENOTCONN;
516
517 if (WARN_ON(!wdev->current_bss))
518 return -ENOTCONN;
519
Johannes Berg19957bb2009-07-02 17:20:43 +0200520 memset(&req, 0, sizeof(req));
521 req.reason_code = reason;
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300522 req.local_state_change = local_state_change;
Johannes Berg19957bb2009-07-02 17:20:43 +0200523 req.ie = ie;
524 req.ie_len = ie_len;
Joe Perchesac422d32012-05-08 18:56:55 +0000525 if (ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
Johannes Berg19957bb2009-07-02 17:20:43 +0200526 req.bss = &wdev->current_bss->pub;
527 else
528 return -ENOTCONN;
529
Hila Gonene35e4d22012-06-27 17:19:42 +0300530 return rdev_disassoc(rdev, dev, &req);
Johannes Berg667503dd2009-07-07 03:56:11 +0200531}
532
533int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
534 struct net_device *dev, const u8 *bssid,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300535 const u8 *ie, int ie_len, u16 reason,
536 bool local_state_change)
Johannes Berg667503dd2009-07-07 03:56:11 +0200537{
538 struct wireless_dev *wdev = dev->ieee80211_ptr;
539 int err;
540
541 wdev_lock(wdev);
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300542 err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason,
543 local_state_change);
Johannes Berg667503dd2009-07-07 03:56:11 +0200544 wdev_unlock(wdev);
545
546 return err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200547}
548
549void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
550 struct net_device *dev)
551{
552 struct wireless_dev *wdev = dev->ieee80211_ptr;
553 struct cfg80211_deauth_request req;
Johannes Berg95de8172012-01-20 13:55:25 +0100554 u8 bssid[ETH_ALEN];
Johannes Berg19957bb2009-07-02 17:20:43 +0200555
Johannes Berg667503dd2009-07-07 03:56:11 +0200556 ASSERT_WDEV_LOCK(wdev);
557
Johannes Berg19957bb2009-07-02 17:20:43 +0200558 if (!rdev->ops->deauth)
559 return;
560
561 memset(&req, 0, sizeof(req));
562 req.reason_code = WLAN_REASON_DEAUTH_LEAVING;
563 req.ie = NULL;
564 req.ie_len = 0;
565
Johannes Berg95de8172012-01-20 13:55:25 +0100566 if (!wdev->current_bss)
567 return;
Johannes Berg19957bb2009-07-02 17:20:43 +0200568
Johannes Berg95de8172012-01-20 13:55:25 +0100569 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
570 req.bssid = bssid;
Hila Gonene35e4d22012-06-27 17:19:42 +0300571 rdev_deauth(rdev, dev, &req);
Johannes Berg95de8172012-01-20 13:55:25 +0100572
573 if (wdev->current_bss) {
574 cfg80211_unhold_bss(wdev->current_bss);
575 cfg80211_put_bss(&wdev->current_bss->pub);
576 wdev->current_bss = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +0200577 }
578}
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100579
Johannes Berg71bbc992012-06-15 15:30:18 +0200580void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100581 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100582 unsigned int duration, gfp_t gfp)
583{
Johannes Berg71bbc992012-06-15 15:30:18 +0200584 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100585 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
586
Johannes Berg42d97a52012-11-08 18:31:02 +0100587 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
588 nl80211_send_remain_on_channel(rdev, wdev, cookie, chan, duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100589}
590EXPORT_SYMBOL(cfg80211_ready_on_channel);
591
Johannes Berg71bbc992012-06-15 15:30:18 +0200592void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100593 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100594 gfp_t gfp)
595{
Johannes Berg71bbc992012-06-15 15:30:18 +0200596 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100597 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
598
Johannes Berg42d97a52012-11-08 18:31:02 +0100599 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
600 nl80211_send_remain_on_channel_cancel(rdev, wdev, cookie, chan, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100601}
602EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Johannes Berg98b62182009-12-23 13:15:44 +0100603
604void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
605 struct station_info *sinfo, gfp_t gfp)
606{
607 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
608 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
609
Beni Lev4ee3e062012-08-27 12:49:39 +0300610 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
Johannes Berg98b62182009-12-23 13:15:44 +0100611 nl80211_send_sta_event(rdev, dev, mac_addr, sinfo, gfp);
612}
613EXPORT_SYMBOL(cfg80211_new_sta);
Jouni Malinen026331c2010-02-15 12:53:10 +0200614
Jouni Malinenec15e682011-03-23 15:29:52 +0200615void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
616{
617 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
618 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
619
Beni Lev4ee3e062012-08-27 12:49:39 +0300620 trace_cfg80211_del_sta(dev, mac_addr);
Jouni Malinenec15e682011-03-23 15:29:52 +0200621 nl80211_send_sta_del_event(rdev, dev, mac_addr, gfp);
622}
623EXPORT_SYMBOL(cfg80211_del_sta);
624
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +0530625void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
626 enum nl80211_connect_failed_reason reason,
627 gfp_t gfp)
628{
629 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
630 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
631
632 nl80211_send_conn_failed_event(rdev, dev, mac_addr, reason, gfp);
633}
634EXPORT_SYMBOL(cfg80211_conn_failed);
635
Johannes Berg2e161f72010-08-12 15:38:38 +0200636struct cfg80211_mgmt_registration {
Jouni Malinen026331c2010-02-15 12:53:10 +0200637 struct list_head list;
638
Eric W. Biederman15e47302012-09-07 20:12:54 +0000639 u32 nlportid;
Jouni Malinen026331c2010-02-15 12:53:10 +0200640
641 int match_len;
642
Johannes Berg2e161f72010-08-12 15:38:38 +0200643 __le16 frame_type;
644
Jouni Malinen026331c2010-02-15 12:53:10 +0200645 u8 match[];
646};
647
Eric W. Biederman15e47302012-09-07 20:12:54 +0000648int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_portid,
Johannes Berg2e161f72010-08-12 15:38:38 +0200649 u16 frame_type, const u8 *match_data,
650 int match_len)
Jouni Malinen026331c2010-02-15 12:53:10 +0200651{
Johannes Berg271733c2010-10-13 12:06:23 +0200652 struct wiphy *wiphy = wdev->wiphy;
653 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg2e161f72010-08-12 15:38:38 +0200654 struct cfg80211_mgmt_registration *reg, *nreg;
Jouni Malinen026331c2010-02-15 12:53:10 +0200655 int err = 0;
Johannes Berg2e161f72010-08-12 15:38:38 +0200656 u16 mgmt_type;
657
658 if (!wdev->wiphy->mgmt_stypes)
659 return -EOPNOTSUPP;
660
661 if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
662 return -EINVAL;
663
664 if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
665 return -EINVAL;
666
667 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
668 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type)))
669 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +0200670
671 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL);
672 if (!nreg)
673 return -ENOMEM;
674
Johannes Berg2e161f72010-08-12 15:38:38 +0200675 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200676
Johannes Berg2e161f72010-08-12 15:38:38 +0200677 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +0200678 int mlen = min(match_len, reg->match_len);
679
Johannes Berg2e161f72010-08-12 15:38:38 +0200680 if (frame_type != le16_to_cpu(reg->frame_type))
681 continue;
682
Jouni Malinen026331c2010-02-15 12:53:10 +0200683 if (memcmp(reg->match, match_data, mlen) == 0) {
684 err = -EALREADY;
685 break;
686 }
687 }
688
689 if (err) {
690 kfree(nreg);
691 goto out;
692 }
693
694 memcpy(nreg->match, match_data, match_len);
695 nreg->match_len = match_len;
Eric W. Biederman15e47302012-09-07 20:12:54 +0000696 nreg->nlportid = snd_portid;
Johannes Berg2e161f72010-08-12 15:38:38 +0200697 nreg->frame_type = cpu_to_le16(frame_type);
698 list_add(&nreg->list, &wdev->mgmt_registrations);
Jouni Malinen026331c2010-02-15 12:53:10 +0200699
Johannes Berg271733c2010-10-13 12:06:23 +0200700 if (rdev->ops->mgmt_frame_register)
Hila Gonene35e4d22012-06-27 17:19:42 +0300701 rdev_mgmt_frame_register(rdev, wdev, frame_type, true);
Johannes Berg271733c2010-10-13 12:06:23 +0200702
Jouni Malinen026331c2010-02-15 12:53:10 +0200703 out:
Johannes Berg2e161f72010-08-12 15:38:38 +0200704 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg271733c2010-10-13 12:06:23 +0200705
Jouni Malinen026331c2010-02-15 12:53:10 +0200706 return err;
707}
708
Eric W. Biederman15e47302012-09-07 20:12:54 +0000709void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlportid)
Jouni Malinen026331c2010-02-15 12:53:10 +0200710{
Johannes Berg271733c2010-10-13 12:06:23 +0200711 struct wiphy *wiphy = wdev->wiphy;
712 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg2e161f72010-08-12 15:38:38 +0200713 struct cfg80211_mgmt_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +0200714
Johannes Berg2e161f72010-08-12 15:38:38 +0200715 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200716
Johannes Berg2e161f72010-08-12 15:38:38 +0200717 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +0000718 if (reg->nlportid != nlportid)
Johannes Berg271733c2010-10-13 12:06:23 +0200719 continue;
720
721 if (rdev->ops->mgmt_frame_register) {
722 u16 frame_type = le16_to_cpu(reg->frame_type);
723
Hila Gonene35e4d22012-06-27 17:19:42 +0300724 rdev_mgmt_frame_register(rdev, wdev,
725 frame_type, false);
Jouni Malinen026331c2010-02-15 12:53:10 +0200726 }
Johannes Berg271733c2010-10-13 12:06:23 +0200727
728 list_del(&reg->list);
729 kfree(reg);
Jouni Malinen026331c2010-02-15 12:53:10 +0200730 }
731
Johannes Berg2e161f72010-08-12 15:38:38 +0200732 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg28946da2011-11-04 11:18:12 +0100733
Eric W. Biederman15e47302012-09-07 20:12:54 +0000734 if (nlportid == wdev->ap_unexpected_nlportid)
735 wdev->ap_unexpected_nlportid = 0;
Jouni Malinen026331c2010-02-15 12:53:10 +0200736}
737
Johannes Berg2e161f72010-08-12 15:38:38 +0200738void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev)
Jouni Malinen026331c2010-02-15 12:53:10 +0200739{
Johannes Berg2e161f72010-08-12 15:38:38 +0200740 struct cfg80211_mgmt_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +0200741
Johannes Berg2e161f72010-08-12 15:38:38 +0200742 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200743
Johannes Berg2e161f72010-08-12 15:38:38 +0200744 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +0200745 list_del(&reg->list);
746 kfree(reg);
747 }
748
Johannes Berg2e161f72010-08-12 15:38:38 +0200749 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200750}
751
Johannes Berg2e161f72010-08-12 15:38:38 +0200752int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +0200753 struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100754 struct ieee80211_channel *chan, bool offchan,
Johannes Berg42d97a52012-11-08 18:31:02 +0100755 unsigned int wait, const u8 *buf, size_t len,
756 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +0200757{
Jouni Malinen026331c2010-02-15 12:53:10 +0200758 const struct ieee80211_mgmt *mgmt;
Johannes Berg2e161f72010-08-12 15:38:38 +0200759 u16 stype;
Jouni Malinen026331c2010-02-15 12:53:10 +0200760
Johannes Berg2e161f72010-08-12 15:38:38 +0200761 if (!wdev->wiphy->mgmt_stypes)
Jouni Malinen026331c2010-02-15 12:53:10 +0200762 return -EOPNOTSUPP;
Johannes Berg2e161f72010-08-12 15:38:38 +0200763
764 if (!rdev->ops->mgmt_tx)
765 return -EOPNOTSUPP;
766
Jouni Malinen026331c2010-02-15 12:53:10 +0200767 if (len < 24 + 1)
768 return -EINVAL;
769
770 mgmt = (const struct ieee80211_mgmt *) buf;
Johannes Berg2e161f72010-08-12 15:38:38 +0200771
772 if (!ieee80211_is_mgmt(mgmt->frame_control))
Jouni Malinen026331c2010-02-15 12:53:10 +0200773 return -EINVAL;
Johannes Berg2e161f72010-08-12 15:38:38 +0200774
775 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
776 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4)))
777 return -EINVAL;
778
779 if (ieee80211_is_action(mgmt->frame_control) &&
780 mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200781 int err = 0;
782
Johannes Bergfe100ac2010-08-09 15:52:03 +0200783 wdev_lock(wdev);
784
Johannes Berg663fcaf2010-09-30 21:06:09 +0200785 switch (wdev->iftype) {
786 case NL80211_IFTYPE_ADHOC:
787 case NL80211_IFTYPE_STATION:
788 case NL80211_IFTYPE_P2P_CLIENT:
789 if (!wdev->current_bss) {
790 err = -ENOTCONN;
791 break;
792 }
Johannes Bergfe100ac2010-08-09 15:52:03 +0200793
Joe Perchesac422d32012-05-08 18:56:55 +0000794 if (!ether_addr_equal(wdev->current_bss->pub.bssid,
795 mgmt->bssid)) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200796 err = -ENOTCONN;
797 break;
798 }
799
800 /*
801 * check for IBSS DA must be done by driver as
802 * cfg80211 doesn't track the stations
803 */
804 if (wdev->iftype == NL80211_IFTYPE_ADHOC)
805 break;
806
807 /* for station, check that DA is the AP */
Joe Perchesac422d32012-05-08 18:56:55 +0000808 if (!ether_addr_equal(wdev->current_bss->pub.bssid,
809 mgmt->da)) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200810 err = -ENOTCONN;
811 break;
812 }
813 break;
814 case NL80211_IFTYPE_AP:
815 case NL80211_IFTYPE_P2P_GO:
816 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg98104fde2012-06-16 00:19:54 +0200817 if (!ether_addr_equal(mgmt->bssid, wdev_address(wdev)))
Johannes Berg663fcaf2010-09-30 21:06:09 +0200818 err = -EINVAL;
819 break;
Javier Cardona0778a6a2011-05-03 16:57:08 -0700820 case NL80211_IFTYPE_MESH_POINT:
Joe Perchesac422d32012-05-08 18:56:55 +0000821 if (!ether_addr_equal(mgmt->sa, mgmt->bssid)) {
Javier Cardona0778a6a2011-05-03 16:57:08 -0700822 err = -EINVAL;
823 break;
824 }
825 /*
826 * check for mesh DA must be done by driver as
827 * cfg80211 doesn't track the stations
828 */
829 break;
Johannes Berg98104fde2012-06-16 00:19:54 +0200830 case NL80211_IFTYPE_P2P_DEVICE:
831 /*
832 * fall through, P2P device only supports
833 * public action frames
834 */
Johannes Berg663fcaf2010-09-30 21:06:09 +0200835 default:
836 err = -EOPNOTSUPP;
837 break;
838 }
Johannes Bergfe100ac2010-08-09 15:52:03 +0200839 wdev_unlock(wdev);
Johannes Berg663fcaf2010-09-30 21:06:09 +0200840
841 if (err)
842 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +0200843 }
844
Johannes Berg98104fde2012-06-16 00:19:54 +0200845 if (!ether_addr_equal(mgmt->sa, wdev_address(wdev)))
Jouni Malinen026331c2010-02-15 12:53:10 +0200846 return -EINVAL;
847
848 /* Transmit the Action frame as requested by user space */
Hila Gonene35e4d22012-06-27 17:19:42 +0300849 return rdev_mgmt_tx(rdev, wdev, chan, offchan,
Hila Gonene35e4d22012-06-27 17:19:42 +0300850 wait, buf, len, no_cck, dont_wait_for_ack,
851 cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +0200852}
853
Johannes Berg71bbc992012-06-15 15:30:18 +0200854bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_mbm,
Johannes Berg804483e2012-03-05 22:18:41 +0100855 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +0200856{
Jouni Malinen026331c2010-02-15 12:53:10 +0200857 struct wiphy *wiphy = wdev->wiphy;
858 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg2e161f72010-08-12 15:38:38 +0200859 struct cfg80211_mgmt_registration *reg;
860 const struct ieee80211_txrx_stypes *stypes =
861 &wiphy->mgmt_stypes[wdev->iftype];
862 struct ieee80211_mgmt *mgmt = (void *)buf;
863 const u8 *data;
864 int data_len;
Jouni Malinen026331c2010-02-15 12:53:10 +0200865 bool result = false;
Johannes Berg2e161f72010-08-12 15:38:38 +0200866 __le16 ftype = mgmt->frame_control &
867 cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE);
868 u16 stype;
Jouni Malinen026331c2010-02-15 12:53:10 +0200869
Beni Lev4ee3e062012-08-27 12:49:39 +0300870 trace_cfg80211_rx_mgmt(wdev, freq, sig_mbm);
Johannes Berg2e161f72010-08-12 15:38:38 +0200871 stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4;
Jouni Malinen026331c2010-02-15 12:53:10 +0200872
Beni Lev4ee3e062012-08-27 12:49:39 +0300873 if (!(stypes->rx & BIT(stype))) {
874 trace_cfg80211_return_bool(false);
Johannes Berg2e161f72010-08-12 15:38:38 +0200875 return false;
Beni Lev4ee3e062012-08-27 12:49:39 +0300876 }
Jouni Malinen026331c2010-02-15 12:53:10 +0200877
Johannes Berg2e161f72010-08-12 15:38:38 +0200878 data = buf + ieee80211_hdrlen(mgmt->frame_control);
879 data_len = len - ieee80211_hdrlen(mgmt->frame_control);
Jouni Malinen026331c2010-02-15 12:53:10 +0200880
Johannes Berg2e161f72010-08-12 15:38:38 +0200881 spin_lock_bh(&wdev->mgmt_registrations_lock);
882
883 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
884 if (reg->frame_type != ftype)
Jouni Malinen026331c2010-02-15 12:53:10 +0200885 continue;
886
Johannes Berg2e161f72010-08-12 15:38:38 +0200887 if (reg->match_len > data_len)
888 continue;
889
890 if (memcmp(reg->match, data, reg->match_len))
Jouni Malinen026331c2010-02-15 12:53:10 +0200891 continue;
892
893 /* found match! */
894
895 /* Indicate the received Action frame to user space */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000896 if (nl80211_send_mgmt(rdev, wdev, reg->nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +0100897 freq, sig_mbm,
Johannes Berg2e161f72010-08-12 15:38:38 +0200898 buf, len, gfp))
Jouni Malinen026331c2010-02-15 12:53:10 +0200899 continue;
900
901 result = true;
902 break;
903 }
904
Johannes Berg2e161f72010-08-12 15:38:38 +0200905 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200906
Beni Lev4ee3e062012-08-27 12:49:39 +0300907 trace_cfg80211_return_bool(result);
Jouni Malinen026331c2010-02-15 12:53:10 +0200908 return result;
909}
Johannes Berg2e161f72010-08-12 15:38:38 +0200910EXPORT_SYMBOL(cfg80211_rx_mgmt);
Jouni Malinen026331c2010-02-15 12:53:10 +0200911
Johannes Berg71bbc992012-06-15 15:30:18 +0200912void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
Johannes Berg2e161f72010-08-12 15:38:38 +0200913 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +0200914{
Jouni Malinen026331c2010-02-15 12:53:10 +0200915 struct wiphy *wiphy = wdev->wiphy;
916 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
917
Beni Lev4ee3e062012-08-27 12:49:39 +0300918 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
919
Jouni Malinen026331c2010-02-15 12:53:10 +0200920 /* Indicate TX status of the Action frame to user space */
Johannes Berg71bbc992012-06-15 15:30:18 +0200921 nl80211_send_mgmt_tx_status(rdev, wdev, cookie, buf, len, ack, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +0200922}
Johannes Berg2e161f72010-08-12 15:38:38 +0200923EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200924
925void cfg80211_cqm_rssi_notify(struct net_device *dev,
926 enum nl80211_cqm_rssi_threshold_event rssi_event,
927 gfp_t gfp)
928{
929 struct wireless_dev *wdev = dev->ieee80211_ptr;
930 struct wiphy *wiphy = wdev->wiphy;
931 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
932
Beni Lev4ee3e062012-08-27 12:49:39 +0300933 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
934
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200935 /* Indicate roaming trigger event to user space */
936 nl80211_send_cqm_rssi_notify(rdev, dev, rssi_event, gfp);
937}
938EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +0100939
940void cfg80211_cqm_pktloss_notify(struct net_device *dev,
941 const u8 *peer, u32 num_packets, gfp_t gfp)
942{
943 struct wireless_dev *wdev = dev->ieee80211_ptr;
944 struct wiphy *wiphy = wdev->wiphy;
945 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
946
Beni Lev4ee3e062012-08-27 12:49:39 +0300947 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
948
Johannes Bergc063dbf2010-11-24 08:10:05 +0100949 /* Indicate roaming trigger event to user space */
950 nl80211_send_cqm_pktloss_notify(rdev, dev, peer, num_packets, gfp);
951}
952EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Berge5497d72011-07-05 16:35:40 +0200953
Thomas Pedersen84f10702012-07-12 16:17:33 -0700954void cfg80211_cqm_txe_notify(struct net_device *dev,
955 const u8 *peer, u32 num_packets,
956 u32 rate, u32 intvl, gfp_t gfp)
957{
958 struct wireless_dev *wdev = dev->ieee80211_ptr;
959 struct wiphy *wiphy = wdev->wiphy;
960 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
961
962 nl80211_send_cqm_txe_notify(rdev, dev, peer, num_packets,
963 rate, intvl, gfp);
964}
965EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
966
Johannes Berge5497d72011-07-05 16:35:40 +0200967void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
968 const u8 *replay_ctr, gfp_t gfp)
969{
970 struct wireless_dev *wdev = dev->ieee80211_ptr;
971 struct wiphy *wiphy = wdev->wiphy;
972 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
973
Beni Lev4ee3e062012-08-27 12:49:39 +0300974 trace_cfg80211_gtk_rekey_notify(dev, bssid);
Johannes Berge5497d72011-07-05 16:35:40 +0200975 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
976}
977EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
Jouni Malinenc9df56b2011-09-16 18:56:23 +0300978
979void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
980 const u8 *bssid, bool preauth, gfp_t gfp)
981{
982 struct wireless_dev *wdev = dev->ieee80211_ptr;
983 struct wiphy *wiphy = wdev->wiphy;
984 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
985
Beni Lev4ee3e062012-08-27 12:49:39 +0300986 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
Jouni Malinenc9df56b2011-09-16 18:56:23 +0300987 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
988}
989EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
Johannes Berg28946da2011-11-04 11:18:12 +0100990
Johannes Berg683b6d32012-11-08 21:25:48 +0100991void cfg80211_ch_switch_notify(struct net_device *dev,
992 struct cfg80211_chan_def *chandef)
Thomas Pedersen53145262012-04-06 13:35:47 -0700993{
994 struct wireless_dev *wdev = dev->ieee80211_ptr;
995 struct wiphy *wiphy = wdev->wiphy;
996 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen53145262012-04-06 13:35:47 -0700997
Johannes Berg683b6d32012-11-08 21:25:48 +0100998 trace_cfg80211_ch_switch_notify(dev, chandef);
Beni Lev4ee3e062012-08-27 12:49:39 +0300999
Thomas Pedersen53145262012-04-06 13:35:47 -07001000 wdev_lock(wdev);
1001
1002 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
1003 wdev->iftype != NL80211_IFTYPE_P2P_GO))
1004 goto out;
1005
Johannes Berg683b6d32012-11-08 21:25:48 +01001006 wdev->channel = chandef->chan;
1007 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Thomas Pedersen53145262012-04-06 13:35:47 -07001008out:
1009 wdev_unlock(wdev);
1010 return;
1011}
1012EXPORT_SYMBOL(cfg80211_ch_switch_notify);
1013
Johannes Berg28946da2011-11-04 11:18:12 +01001014bool cfg80211_rx_spurious_frame(struct net_device *dev,
1015 const u8 *addr, gfp_t gfp)
1016{
1017 struct wireless_dev *wdev = dev->ieee80211_ptr;
Beni Lev4ee3e062012-08-27 12:49:39 +03001018 bool ret;
1019
1020 trace_cfg80211_rx_spurious_frame(dev, addr);
Johannes Berg28946da2011-11-04 11:18:12 +01001021
1022 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Beni Lev4ee3e062012-08-27 12:49:39 +03001023 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
1024 trace_cfg80211_return_bool(false);
Johannes Berg28946da2011-11-04 11:18:12 +01001025 return false;
Beni Lev4ee3e062012-08-27 12:49:39 +03001026 }
1027 ret = nl80211_unexpected_frame(dev, addr, gfp);
1028 trace_cfg80211_return_bool(ret);
1029 return ret;
Johannes Berg28946da2011-11-04 11:18:12 +01001030}
1031EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01001032
1033bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
1034 const u8 *addr, gfp_t gfp)
1035{
1036 struct wireless_dev *wdev = dev->ieee80211_ptr;
Beni Lev4ee3e062012-08-27 12:49:39 +03001037 bool ret;
1038
1039 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01001040
1041 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
1042 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Beni Lev4ee3e062012-08-27 12:49:39 +03001043 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
1044 trace_cfg80211_return_bool(false);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01001045 return false;
Beni Lev4ee3e062012-08-27 12:49:39 +03001046 }
1047 ret = nl80211_unexpected_4addr_frame(dev, addr, gfp);
1048 trace_cfg80211_return_bool(ret);
1049 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01001050}
1051EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);