Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 1 | /* |
| 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 Fietkau | c6fb08a | 2012-03-18 22:58:04 +0100 | [diff] [blame] | 9 | #include <linux/etherdevice.h> |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10 | #include <linux/netdevice.h> |
| 11 | #include <linux/nl80211.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 13 | #include <linux/wireless.h> |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14 | #include <net/cfg80211.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 15 | #include <net/iw_handler.h> |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16 | #include "core.h" |
| 17 | #include "nl80211.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 18 | #include "rdev-ops.h" |
| 19 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 20 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 21 | void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 22 | { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 23 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 24 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 25 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 26 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 27 | trace_cfg80211_send_rx_auth(dev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 28 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 29 | nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL); |
| 30 | cfg80211_sme_rx_auth(dev, buf, len); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 31 | } |
| 32 | EXPORT_SYMBOL(cfg80211_send_rx_auth); |
| 33 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 34 | void cfg80211_send_rx_assoc(struct net_device *dev, struct cfg80211_bss *bss, |
| 35 | const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 36 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 37 | u16 status_code; |
| 38 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 39 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 40 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 41 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 42 | u8 *ie = mgmt->u.assoc_resp.variable; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 43 | int ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 44 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 45 | trace_cfg80211_send_rx_assoc(dev, bss); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 46 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 47 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 48 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 49 | /* |
| 50 | * This is a bit of a hack, we don't notify userspace of |
| 51 | * a (re-)association reply if we tried to send a reassoc |
| 52 | * and got a reject -- we only try again with an assoc |
| 53 | * frame instead of reassoc. |
| 54 | */ |
| 55 | if (status_code != WLAN_STATUS_SUCCESS && wdev->conn && |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 56 | cfg80211_sme_failed_reassoc(wdev)) { |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 57 | cfg80211_put_bss(wiphy, bss); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame^] | 58 | return; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 59 | } |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 60 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 61 | nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 62 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 63 | if (status_code != WLAN_STATUS_SUCCESS && wdev->conn) { |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 64 | cfg80211_sme_failed_assoc(wdev); |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 65 | /* |
| 66 | * do not call connect_result() now because the |
| 67 | * sme will schedule work that does it later. |
| 68 | */ |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 69 | cfg80211_put_bss(wiphy, bss); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame^] | 70 | return; |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Johannes Berg | ea416a7 | 2009-08-17 12:22:14 +0200 | [diff] [blame] | 73 | if (!wdev->conn && wdev->sme_state == CFG80211_SME_IDLE) { |
| 74 | /* |
| 75 | * This is for the userspace SME, the CONNECTING |
| 76 | * state will be changed to CONNECTED by |
| 77 | * __cfg80211_connect_result() below. |
| 78 | */ |
| 79 | wdev->sme_state = CFG80211_SME_CONNECTING; |
| 80 | } |
| 81 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 82 | /* this consumes the bss reference */ |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 83 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs, |
| 84 | status_code, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 85 | status_code == WLAN_STATUS_SUCCESS, bss); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 86 | } |
| 87 | EXPORT_SYMBOL(cfg80211_send_rx_assoc); |
| 88 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame^] | 89 | void cfg80211_send_deauth(struct net_device *dev, |
| 90 | const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 91 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 92 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 93 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 94 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 95 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 96 | const u8 *bssid = mgmt->bssid; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 97 | bool was_current = false; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 98 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame^] | 99 | trace_cfg80211_send_deauth(dev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 100 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 101 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 102 | if (wdev->current_bss && |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 103 | ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 104 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 105 | cfg80211_put_bss(wiphy, &wdev->current_bss->pub); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 106 | wdev->current_bss = NULL; |
Johannes Berg | 3f3b6a8 | 2010-08-05 10:20:27 +0200 | [diff] [blame] | 107 | was_current = true; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 108 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 109 | |
Johannes Berg | 5fba4af | 2009-12-02 12:43:42 +0100 | [diff] [blame] | 110 | nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL); |
| 111 | |
Johannes Berg | 3f3b6a8 | 2010-08-05 10:20:27 +0200 | [diff] [blame] | 112 | if (wdev->sme_state == CFG80211_SME_CONNECTED && was_current) { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 113 | u16 reason_code; |
| 114 | bool from_ap; |
| 115 | |
| 116 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 117 | |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 118 | from_ap = !ether_addr_equal(mgmt->sa, dev->dev_addr); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 119 | __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 120 | } else if (wdev->sme_state == CFG80211_SME_CONNECTING) { |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 121 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0, |
| 122 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 123 | false, NULL); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 124 | } |
| 125 | } |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 126 | EXPORT_SYMBOL(cfg80211_send_deauth); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 127 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame^] | 128 | void cfg80211_send_disassoc(struct net_device *dev, |
| 129 | const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 130 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 131 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 132 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 133 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 134 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 135 | const u8 *bssid = mgmt->bssid; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 136 | u16 reason_code; |
| 137 | bool from_ap; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 138 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame^] | 139 | trace_cfg80211_send_disassoc(dev); |
Johannes Berg | 596a07c | 2009-07-11 00:17:32 +0200 | [diff] [blame] | 140 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 141 | |
| 142 | nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 143 | |
Johannes Berg | 596a07c | 2009-07-11 00:17:32 +0200 | [diff] [blame] | 144 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 145 | return; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 146 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 147 | if (wdev->current_bss && |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 148 | ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) { |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 149 | cfg80211_sme_disassoc(dev, wdev->current_bss); |
| 150 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 151 | cfg80211_put_bss(wiphy, &wdev->current_bss->pub); |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 152 | wdev->current_bss = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 153 | } else |
| 154 | WARN_ON(1); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 155 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 156 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 157 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 158 | |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 159 | from_ap = !ether_addr_equal(mgmt->sa, dev->dev_addr); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 160 | __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 161 | } |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 162 | EXPORT_SYMBOL(cfg80211_send_disassoc); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 163 | |
Johannes Berg | a58ce43 | 2009-11-19 12:45:42 +0100 | [diff] [blame] | 164 | void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr) |
| 165 | { |
| 166 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 167 | struct wiphy *wiphy = wdev->wiphy; |
| 168 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 169 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 170 | trace_cfg80211_send_auth_timeout(dev, addr); |
Johannes Berg | a58ce43 | 2009-11-19 12:45:42 +0100 | [diff] [blame] | 171 | |
| 172 | nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL); |
| 173 | if (wdev->sme_state == CFG80211_SME_CONNECTING) |
| 174 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, |
| 175 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 176 | false, NULL); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 177 | } |
| 178 | EXPORT_SYMBOL(cfg80211_send_auth_timeout); |
| 179 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 180 | void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 181 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 182 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 183 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 184 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 185 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 186 | trace_cfg80211_send_assoc_timeout(dev, addr); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 187 | |
| 188 | nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 189 | if (wdev->sme_state == CFG80211_SME_CONNECTING) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 190 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, |
| 191 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 192 | false, NULL); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 193 | } |
| 194 | EXPORT_SYMBOL(cfg80211_send_assoc_timeout); |
| 195 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 196 | void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr, |
| 197 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 198 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 199 | { |
| 200 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 201 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 202 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | f58d4ed | 2009-06-19 02:45:21 +0200 | [diff] [blame] | 203 | union iwreq_data wrqu; |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 204 | char *buf = kmalloc(128, gfp); |
Johannes Berg | f58d4ed | 2009-06-19 02:45:21 +0200 | [diff] [blame] | 205 | |
| 206 | if (buf) { |
| 207 | sprintf(buf, "MLME-MICHAELMICFAILURE.indication(" |
| 208 | "keyid=%d %scast addr=%pM)", key_id, |
| 209 | key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni", |
| 210 | addr); |
| 211 | memset(&wrqu, 0, sizeof(wrqu)); |
| 212 | wrqu.data.length = strlen(buf); |
| 213 | wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf); |
| 214 | kfree(buf); |
| 215 | } |
| 216 | #endif |
| 217 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 218 | trace_cfg80211_michael_mic_failure(dev, addr, key_type, key_id, tsc); |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 219 | nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 220 | } |
| 221 | EXPORT_SYMBOL(cfg80211_michael_mic_failure); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 222 | |
| 223 | /* some MLME handling for userspace SME */ |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 224 | int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
| 225 | struct net_device *dev, |
| 226 | struct ieee80211_channel *chan, |
| 227 | enum nl80211_auth_type auth_type, |
| 228 | const u8 *bssid, |
| 229 | const u8 *ssid, int ssid_len, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 230 | const u8 *ie, int ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 231 | const u8 *key, int key_len, int key_idx, |
| 232 | const u8 *sae_data, int sae_data_len) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 233 | { |
| 234 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 7ade703 | 2013-05-13 11:37:30 +0200 | [diff] [blame] | 235 | struct cfg80211_auth_request req = { |
| 236 | .ie = ie, |
| 237 | .ie_len = ie_len, |
| 238 | .sae_data = sae_data, |
| 239 | .sae_data_len = sae_data_len, |
| 240 | .auth_type = auth_type, |
| 241 | .key = key, |
| 242 | .key_len = key_len, |
| 243 | .key_idx = key_idx, |
| 244 | }; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 245 | int err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 246 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 247 | ASSERT_WDEV_LOCK(wdev); |
| 248 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 249 | if (auth_type == NL80211_AUTHTYPE_SHARED_KEY) |
| 250 | if (!key || !key_len || key_idx < 0 || key_idx > 4) |
| 251 | return -EINVAL; |
| 252 | |
Johannes Berg | 0a9b5e1 | 2009-07-02 18:26:18 +0200 | [diff] [blame] | 253 | if (wdev->current_bss && |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 254 | ether_addr_equal(bssid, wdev->current_bss->pub.bssid)) |
Johannes Berg | 0a9b5e1 | 2009-07-02 18:26:18 +0200 | [diff] [blame] | 255 | return -EALREADY; |
| 256 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 257 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
| 258 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
| 259 | if (!req.bss) |
| 260 | return -ENOENT; |
| 261 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 262 | err = cfg80211_can_use_chan(rdev, wdev, req.bss->channel, |
| 263 | CHAN_MODE_SHARED); |
| 264 | if (err) |
| 265 | goto out; |
| 266 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 267 | err = rdev_auth(rdev, dev, &req); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 268 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 269 | out: |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 270 | cfg80211_put_bss(&rdev->wiphy, req.bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 271 | return err; |
| 272 | } |
| 273 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 274 | int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
| 275 | struct net_device *dev, struct ieee80211_channel *chan, |
| 276 | enum nl80211_auth_type auth_type, const u8 *bssid, |
| 277 | const u8 *ssid, int ssid_len, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 278 | const u8 *ie, int ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 279 | const u8 *key, int key_len, int key_idx, |
| 280 | const u8 *sae_data, int sae_data_len) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 281 | { |
| 282 | int err; |
| 283 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 284 | ASSERT_RTNL(); |
| 285 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 286 | wdev_lock(dev->ieee80211_ptr); |
| 287 | err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 288 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 289 | key, key_len, key_idx, |
| 290 | sae_data, sae_data_len); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 291 | wdev_unlock(dev->ieee80211_ptr); |
| 292 | |
| 293 | return err; |
| 294 | } |
| 295 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 296 | /* Do a logical ht_capa &= ht_capa_mask. */ |
| 297 | void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa, |
| 298 | const struct ieee80211_ht_cap *ht_capa_mask) |
| 299 | { |
| 300 | int i; |
| 301 | u8 *p1, *p2; |
| 302 | if (!ht_capa_mask) { |
| 303 | memset(ht_capa, 0, sizeof(*ht_capa)); |
| 304 | return; |
| 305 | } |
| 306 | |
| 307 | p1 = (u8*)(ht_capa); |
| 308 | p2 = (u8*)(ht_capa_mask); |
| 309 | for (i = 0; i<sizeof(*ht_capa); i++) |
| 310 | p1[i] &= p2[i]; |
| 311 | } |
| 312 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 313 | /* Do a logical ht_capa &= ht_capa_mask. */ |
| 314 | void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa, |
| 315 | const struct ieee80211_vht_cap *vht_capa_mask) |
| 316 | { |
| 317 | int i; |
| 318 | u8 *p1, *p2; |
| 319 | if (!vht_capa_mask) { |
| 320 | memset(vht_capa, 0, sizeof(*vht_capa)); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | p1 = (u8*)(vht_capa); |
| 325 | p2 = (u8*)(vht_capa_mask); |
| 326 | for (i = 0; i < sizeof(*vht_capa); i++) |
| 327 | p1[i] &= p2[i]; |
| 328 | } |
| 329 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 330 | int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
| 331 | struct net_device *dev, |
| 332 | struct ieee80211_channel *chan, |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 333 | const u8 *bssid, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 334 | const u8 *ssid, int ssid_len, |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 335 | struct cfg80211_assoc_request *req) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 336 | { |
| 337 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 338 | int err; |
Jouni Malinen | 24b6b15 | 2009-11-17 21:35:38 +0200 | [diff] [blame] | 339 | bool was_connected = false; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 340 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 341 | ASSERT_WDEV_LOCK(wdev); |
| 342 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 343 | if (wdev->current_bss && req->prev_bssid && |
| 344 | ether_addr_equal(wdev->current_bss->pub.bssid, req->prev_bssid)) { |
Jouni Malinen | 24b6b15 | 2009-11-17 21:35:38 +0200 | [diff] [blame] | 345 | /* |
| 346 | * Trying to reassociate: Allow this to proceed and let the old |
| 347 | * association to be dropped when the new one is completed. |
| 348 | */ |
| 349 | if (wdev->sme_state == CFG80211_SME_CONNECTED) { |
| 350 | was_connected = true; |
| 351 | wdev->sme_state = CFG80211_SME_CONNECTING; |
| 352 | } |
| 353 | } else if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 354 | return -EALREADY; |
| 355 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 356 | cfg80211_oper_and_ht_capa(&req->ht_capa_mask, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 357 | rdev->wiphy.ht_capa_mod_mask); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 358 | cfg80211_oper_and_vht_capa(&req->vht_capa_mask, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 359 | rdev->wiphy.vht_capa_mod_mask); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 360 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 361 | req->bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
| 362 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
| 363 | if (!req->bss) { |
Jouni Malinen | 24b6b15 | 2009-11-17 21:35:38 +0200 | [diff] [blame] | 364 | if (was_connected) |
| 365 | wdev->sme_state = CFG80211_SME_CONNECTED; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 366 | return -ENOENT; |
Jouni Malinen | 24b6b15 | 2009-11-17 21:35:38 +0200 | [diff] [blame] | 367 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 368 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 369 | err = cfg80211_can_use_chan(rdev, wdev, chan, CHAN_MODE_SHARED); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 370 | if (err) |
| 371 | goto out; |
| 372 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 373 | err = rdev_assoc(rdev, dev, req); |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 374 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 375 | out: |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 376 | if (err) { |
| 377 | if (was_connected) |
| 378 | wdev->sme_state = CFG80211_SME_CONNECTED; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 379 | cfg80211_put_bss(&rdev->wiphy, req->bss); |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 380 | } |
| 381 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 382 | return err; |
| 383 | } |
| 384 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 385 | int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
| 386 | struct net_device *dev, |
| 387 | struct ieee80211_channel *chan, |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 388 | const u8 *bssid, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 389 | const u8 *ssid, int ssid_len, |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 390 | struct cfg80211_assoc_request *req) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 391 | { |
| 392 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 393 | int err; |
| 394 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 395 | ASSERT_RTNL(); |
| 396 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 397 | wdev_lock(wdev); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 398 | err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 399 | ssid, ssid_len, req); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 400 | wdev_unlock(wdev); |
| 401 | |
| 402 | return err; |
| 403 | } |
| 404 | |
| 405 | int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
| 406 | struct net_device *dev, const u8 *bssid, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 407 | const u8 *ie, int ie_len, u16 reason, |
| 408 | bool local_state_change) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 409 | { |
| 410 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 411 | struct cfg80211_deauth_request req = { |
| 412 | .bssid = bssid, |
| 413 | .reason_code = reason, |
| 414 | .ie = ie, |
| 415 | .ie_len = ie_len, |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 416 | .local_state_change = local_state_change, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 417 | }; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 418 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 419 | ASSERT_WDEV_LOCK(wdev); |
| 420 | |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 421 | if (local_state_change && (!wdev->current_bss || |
| 422 | !ether_addr_equal(wdev->current_bss->pub.bssid, bssid))) |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 423 | return 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 424 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 425 | return rdev_deauth(rdev, dev, &req); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 426 | } |
| 427 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 428 | int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
| 429 | struct net_device *dev, const u8 *bssid, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 430 | const u8 *ie, int ie_len, u16 reason, |
| 431 | bool local_state_change) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 432 | { |
| 433 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 434 | int err; |
| 435 | |
| 436 | wdev_lock(wdev); |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 437 | err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason, |
| 438 | local_state_change); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 439 | wdev_unlock(wdev); |
| 440 | |
| 441 | return err; |
| 442 | } |
| 443 | |
| 444 | static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, |
| 445 | struct net_device *dev, const u8 *bssid, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 446 | const u8 *ie, int ie_len, u16 reason, |
| 447 | bool local_state_change) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 448 | { |
| 449 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 7ade703 | 2013-05-13 11:37:30 +0200 | [diff] [blame] | 450 | struct cfg80211_disassoc_request req = { |
| 451 | .reason_code = reason, |
| 452 | .local_state_change = local_state_change, |
| 453 | .ie = ie, |
| 454 | .ie_len = ie_len, |
| 455 | }; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 456 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 457 | ASSERT_WDEV_LOCK(wdev); |
| 458 | |
Johannes Berg | f9d6b40 | 2009-07-27 10:22:28 +0200 | [diff] [blame] | 459 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 460 | return -ENOTCONN; |
| 461 | |
Johannes Berg | 8dcf011 | 2013-01-26 22:16:08 +0100 | [diff] [blame] | 462 | if (WARN(!wdev->current_bss, "sme_state=%d\n", wdev->sme_state)) |
Johannes Berg | f9d6b40 | 2009-07-27 10:22:28 +0200 | [diff] [blame] | 463 | return -ENOTCONN; |
| 464 | |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 465 | if (ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 466 | req.bss = &wdev->current_bss->pub; |
| 467 | else |
| 468 | return -ENOTCONN; |
| 469 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 470 | return rdev_disassoc(rdev, dev, &req); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, |
| 474 | struct net_device *dev, const u8 *bssid, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 475 | const u8 *ie, int ie_len, u16 reason, |
| 476 | bool local_state_change) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 477 | { |
| 478 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 479 | int err; |
| 480 | |
| 481 | wdev_lock(wdev); |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 482 | err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason, |
| 483 | local_state_change); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 484 | wdev_unlock(wdev); |
| 485 | |
| 486 | return err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | void cfg80211_mlme_down(struct cfg80211_registered_device *rdev, |
| 490 | struct net_device *dev) |
| 491 | { |
| 492 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 493 | u8 bssid[ETH_ALEN]; |
Johannes Berg | 7ade703 | 2013-05-13 11:37:30 +0200 | [diff] [blame] | 494 | struct cfg80211_deauth_request req = { |
| 495 | .reason_code = WLAN_REASON_DEAUTH_LEAVING, |
| 496 | .bssid = bssid, |
| 497 | }; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 498 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 499 | ASSERT_WDEV_LOCK(wdev); |
| 500 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 501 | if (!rdev->ops->deauth) |
| 502 | return; |
| 503 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 504 | if (!wdev->current_bss) |
| 505 | return; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 506 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 507 | memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 508 | rdev_deauth(rdev, dev, &req); |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 509 | |
| 510 | if (wdev->current_bss) { |
| 511 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 512 | cfg80211_put_bss(&rdev->wiphy, &wdev->current_bss->pub); |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 513 | wdev->current_bss = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 514 | } |
| 515 | } |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 516 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 517 | struct cfg80211_mgmt_registration { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 518 | struct list_head list; |
| 519 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 520 | u32 nlportid; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 521 | |
| 522 | int match_len; |
| 523 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 524 | __le16 frame_type; |
| 525 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 526 | u8 match[]; |
| 527 | }; |
| 528 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 529 | int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_portid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 530 | u16 frame_type, const u8 *match_data, |
| 531 | int match_len) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 532 | { |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 533 | struct wiphy *wiphy = wdev->wiphy; |
| 534 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 535 | struct cfg80211_mgmt_registration *reg, *nreg; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 536 | int err = 0; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 537 | u16 mgmt_type; |
| 538 | |
| 539 | if (!wdev->wiphy->mgmt_stypes) |
| 540 | return -EOPNOTSUPP; |
| 541 | |
| 542 | if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT) |
| 543 | return -EINVAL; |
| 544 | |
| 545 | if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) |
| 546 | return -EINVAL; |
| 547 | |
| 548 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; |
| 549 | if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type))) |
| 550 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 551 | |
| 552 | nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL); |
| 553 | if (!nreg) |
| 554 | return -ENOMEM; |
| 555 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 556 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 557 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 558 | list_for_each_entry(reg, &wdev->mgmt_registrations, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 559 | int mlen = min(match_len, reg->match_len); |
| 560 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 561 | if (frame_type != le16_to_cpu(reg->frame_type)) |
| 562 | continue; |
| 563 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 564 | if (memcmp(reg->match, match_data, mlen) == 0) { |
| 565 | err = -EALREADY; |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | if (err) { |
| 571 | kfree(nreg); |
| 572 | goto out; |
| 573 | } |
| 574 | |
| 575 | memcpy(nreg->match, match_data, match_len); |
| 576 | nreg->match_len = match_len; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 577 | nreg->nlportid = snd_portid; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 578 | nreg->frame_type = cpu_to_le16(frame_type); |
| 579 | list_add(&nreg->list, &wdev->mgmt_registrations); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 580 | |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 581 | if (rdev->ops->mgmt_frame_register) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 582 | rdev_mgmt_frame_register(rdev, wdev, frame_type, true); |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 583 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 584 | out: |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 585 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 586 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 587 | return err; |
| 588 | } |
| 589 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 590 | void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlportid) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 591 | { |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 592 | struct wiphy *wiphy = wdev->wiphy; |
| 593 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 594 | struct cfg80211_mgmt_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 595 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 596 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 597 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 598 | list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 599 | if (reg->nlportid != nlportid) |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 600 | continue; |
| 601 | |
| 602 | if (rdev->ops->mgmt_frame_register) { |
| 603 | u16 frame_type = le16_to_cpu(reg->frame_type); |
| 604 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 605 | rdev_mgmt_frame_register(rdev, wdev, |
| 606 | frame_type, false); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 607 | } |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 608 | |
| 609 | list_del(®->list); |
| 610 | kfree(reg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 611 | } |
| 612 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 613 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 614 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 615 | if (nlportid && rdev->crit_proto_nlportid == nlportid) { |
| 616 | rdev->crit_proto_nlportid = 0; |
| 617 | rdev_crit_proto_stop(rdev, wdev); |
| 618 | } |
| 619 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 620 | if (nlportid == wdev->ap_unexpected_nlportid) |
| 621 | wdev->ap_unexpected_nlportid = 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 622 | } |
| 623 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 624 | void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 625 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 626 | struct cfg80211_mgmt_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 627 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 628 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 629 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 630 | list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 631 | list_del(®->list); |
| 632 | kfree(reg); |
| 633 | } |
| 634 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 635 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 636 | } |
| 637 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 638 | int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 639 | struct wireless_dev *wdev, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 640 | struct ieee80211_channel *chan, bool offchan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 641 | unsigned int wait, const u8 *buf, size_t len, |
| 642 | bool no_cck, bool dont_wait_for_ack, u64 *cookie) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 643 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 644 | const struct ieee80211_mgmt *mgmt; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 645 | u16 stype; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 646 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 647 | if (!wdev->wiphy->mgmt_stypes) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 648 | return -EOPNOTSUPP; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 649 | |
| 650 | if (!rdev->ops->mgmt_tx) |
| 651 | return -EOPNOTSUPP; |
| 652 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 653 | if (len < 24 + 1) |
| 654 | return -EINVAL; |
| 655 | |
| 656 | mgmt = (const struct ieee80211_mgmt *) buf; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 657 | |
| 658 | if (!ieee80211_is_mgmt(mgmt->frame_control)) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 659 | return -EINVAL; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 660 | |
| 661 | stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; |
| 662 | if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4))) |
| 663 | return -EINVAL; |
| 664 | |
| 665 | if (ieee80211_is_action(mgmt->frame_control) && |
| 666 | mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) { |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 667 | int err = 0; |
| 668 | |
Johannes Berg | fe100ac | 2010-08-09 15:52:03 +0200 | [diff] [blame] | 669 | wdev_lock(wdev); |
| 670 | |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 671 | switch (wdev->iftype) { |
| 672 | case NL80211_IFTYPE_ADHOC: |
| 673 | case NL80211_IFTYPE_STATION: |
| 674 | case NL80211_IFTYPE_P2P_CLIENT: |
| 675 | if (!wdev->current_bss) { |
| 676 | err = -ENOTCONN; |
| 677 | break; |
| 678 | } |
Johannes Berg | fe100ac | 2010-08-09 15:52:03 +0200 | [diff] [blame] | 679 | |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 680 | if (!ether_addr_equal(wdev->current_bss->pub.bssid, |
| 681 | mgmt->bssid)) { |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 682 | err = -ENOTCONN; |
| 683 | break; |
| 684 | } |
| 685 | |
| 686 | /* |
| 687 | * check for IBSS DA must be done by driver as |
| 688 | * cfg80211 doesn't track the stations |
| 689 | */ |
| 690 | if (wdev->iftype == NL80211_IFTYPE_ADHOC) |
| 691 | break; |
| 692 | |
| 693 | /* for station, check that DA is the AP */ |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 694 | if (!ether_addr_equal(wdev->current_bss->pub.bssid, |
| 695 | mgmt->da)) { |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 696 | err = -ENOTCONN; |
| 697 | break; |
| 698 | } |
| 699 | break; |
| 700 | case NL80211_IFTYPE_AP: |
| 701 | case NL80211_IFTYPE_P2P_GO: |
| 702 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 703 | if (!ether_addr_equal(mgmt->bssid, wdev_address(wdev))) |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 704 | err = -EINVAL; |
| 705 | break; |
Javier Cardona | 0778a6a | 2011-05-03 16:57:08 -0700 | [diff] [blame] | 706 | case NL80211_IFTYPE_MESH_POINT: |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 707 | if (!ether_addr_equal(mgmt->sa, mgmt->bssid)) { |
Javier Cardona | 0778a6a | 2011-05-03 16:57:08 -0700 | [diff] [blame] | 708 | err = -EINVAL; |
| 709 | break; |
| 710 | } |
| 711 | /* |
| 712 | * check for mesh DA must be done by driver as |
| 713 | * cfg80211 doesn't track the stations |
| 714 | */ |
| 715 | break; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 716 | case NL80211_IFTYPE_P2P_DEVICE: |
| 717 | /* |
| 718 | * fall through, P2P device only supports |
| 719 | * public action frames |
| 720 | */ |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 721 | default: |
| 722 | err = -EOPNOTSUPP; |
| 723 | break; |
| 724 | } |
Johannes Berg | fe100ac | 2010-08-09 15:52:03 +0200 | [diff] [blame] | 725 | wdev_unlock(wdev); |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 726 | |
| 727 | if (err) |
| 728 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 729 | } |
| 730 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 731 | if (!ether_addr_equal(mgmt->sa, wdev_address(wdev))) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 732 | return -EINVAL; |
| 733 | |
| 734 | /* Transmit the Action frame as requested by user space */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 735 | return rdev_mgmt_tx(rdev, wdev, chan, offchan, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 736 | wait, buf, len, no_cck, dont_wait_for_ack, |
| 737 | cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 738 | } |
| 739 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 740 | bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_mbm, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 741 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 742 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 743 | struct wiphy *wiphy = wdev->wiphy; |
| 744 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 745 | struct cfg80211_mgmt_registration *reg; |
| 746 | const struct ieee80211_txrx_stypes *stypes = |
| 747 | &wiphy->mgmt_stypes[wdev->iftype]; |
| 748 | struct ieee80211_mgmt *mgmt = (void *)buf; |
| 749 | const u8 *data; |
| 750 | int data_len; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 751 | bool result = false; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 752 | __le16 ftype = mgmt->frame_control & |
| 753 | cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE); |
| 754 | u16 stype; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 755 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 756 | trace_cfg80211_rx_mgmt(wdev, freq, sig_mbm); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 757 | stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 758 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 759 | if (!(stypes->rx & BIT(stype))) { |
| 760 | trace_cfg80211_return_bool(false); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 761 | return false; |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 762 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 763 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 764 | data = buf + ieee80211_hdrlen(mgmt->frame_control); |
| 765 | data_len = len - ieee80211_hdrlen(mgmt->frame_control); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 766 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 767 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
| 768 | |
| 769 | list_for_each_entry(reg, &wdev->mgmt_registrations, list) { |
| 770 | if (reg->frame_type != ftype) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 771 | continue; |
| 772 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 773 | if (reg->match_len > data_len) |
| 774 | continue; |
| 775 | |
| 776 | if (memcmp(reg->match, data, reg->match_len)) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 777 | continue; |
| 778 | |
| 779 | /* found match! */ |
| 780 | |
| 781 | /* Indicate the received Action frame to user space */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 782 | if (nl80211_send_mgmt(rdev, wdev, reg->nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 783 | freq, sig_mbm, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 784 | buf, len, gfp)) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 785 | continue; |
| 786 | |
| 787 | result = true; |
| 788 | break; |
| 789 | } |
| 790 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 791 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 792 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 793 | trace_cfg80211_return_bool(result); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 794 | return result; |
| 795 | } |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 796 | EXPORT_SYMBOL(cfg80211_rx_mgmt); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 797 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 798 | void cfg80211_dfs_channels_update_work(struct work_struct *work) |
| 799 | { |
| 800 | struct delayed_work *delayed_work; |
| 801 | struct cfg80211_registered_device *rdev; |
| 802 | struct cfg80211_chan_def chandef; |
| 803 | struct ieee80211_supported_band *sband; |
| 804 | struct ieee80211_channel *c; |
| 805 | struct wiphy *wiphy; |
| 806 | bool check_again = false; |
| 807 | unsigned long timeout, next_time = 0; |
| 808 | int bandid, i; |
| 809 | |
| 810 | delayed_work = container_of(work, struct delayed_work, work); |
| 811 | rdev = container_of(delayed_work, struct cfg80211_registered_device, |
| 812 | dfs_update_channels_wk); |
| 813 | wiphy = &rdev->wiphy; |
| 814 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 815 | rtnl_lock(); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 816 | for (bandid = 0; bandid < IEEE80211_NUM_BANDS; bandid++) { |
| 817 | sband = wiphy->bands[bandid]; |
| 818 | if (!sband) |
| 819 | continue; |
| 820 | |
| 821 | for (i = 0; i < sband->n_channels; i++) { |
| 822 | c = &sband->channels[i]; |
| 823 | |
| 824 | if (c->dfs_state != NL80211_DFS_UNAVAILABLE) |
| 825 | continue; |
| 826 | |
| 827 | timeout = c->dfs_state_entered + |
| 828 | IEEE80211_DFS_MIN_NOP_TIME_MS; |
| 829 | |
| 830 | if (time_after_eq(jiffies, timeout)) { |
| 831 | c->dfs_state = NL80211_DFS_USABLE; |
| 832 | cfg80211_chandef_create(&chandef, c, |
| 833 | NL80211_CHAN_NO_HT); |
| 834 | |
| 835 | nl80211_radar_notify(rdev, &chandef, |
| 836 | NL80211_RADAR_NOP_FINISHED, |
| 837 | NULL, GFP_ATOMIC); |
| 838 | continue; |
| 839 | } |
| 840 | |
| 841 | if (!check_again) |
| 842 | next_time = timeout - jiffies; |
| 843 | else |
| 844 | next_time = min(next_time, timeout - jiffies); |
| 845 | check_again = true; |
| 846 | } |
| 847 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 848 | rtnl_unlock(); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 849 | |
| 850 | /* reschedule if there are other channels waiting to be cleared again */ |
| 851 | if (check_again) |
| 852 | queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk, |
| 853 | next_time); |
| 854 | } |
| 855 | |
| 856 | |
| 857 | void cfg80211_radar_event(struct wiphy *wiphy, |
| 858 | struct cfg80211_chan_def *chandef, |
| 859 | gfp_t gfp) |
| 860 | { |
| 861 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 862 | unsigned long timeout; |
| 863 | |
| 864 | trace_cfg80211_radar_event(wiphy, chandef); |
| 865 | |
| 866 | /* only set the chandef supplied channel to unavailable, in |
| 867 | * case the radar is detected on only one of multiple channels |
| 868 | * spanned by the chandef. |
| 869 | */ |
| 870 | cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_UNAVAILABLE); |
| 871 | |
| 872 | timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_NOP_TIME_MS); |
| 873 | queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk, |
| 874 | timeout); |
| 875 | |
| 876 | nl80211_radar_notify(rdev, chandef, NL80211_RADAR_DETECTED, NULL, gfp); |
| 877 | } |
| 878 | EXPORT_SYMBOL(cfg80211_radar_event); |
| 879 | |
| 880 | void cfg80211_cac_event(struct net_device *netdev, |
| 881 | enum nl80211_radar_event event, gfp_t gfp) |
| 882 | { |
| 883 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 884 | struct wiphy *wiphy = wdev->wiphy; |
| 885 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 886 | struct cfg80211_chan_def chandef; |
| 887 | unsigned long timeout; |
| 888 | |
| 889 | trace_cfg80211_cac_event(netdev, event); |
| 890 | |
| 891 | if (WARN_ON(!wdev->cac_started)) |
| 892 | return; |
| 893 | |
| 894 | if (WARN_ON(!wdev->channel)) |
| 895 | return; |
| 896 | |
| 897 | cfg80211_chandef_create(&chandef, wdev->channel, NL80211_CHAN_NO_HT); |
| 898 | |
| 899 | switch (event) { |
| 900 | case NL80211_RADAR_CAC_FINISHED: |
| 901 | timeout = wdev->cac_start_time + |
| 902 | msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS); |
| 903 | WARN_ON(!time_after_eq(jiffies, timeout)); |
| 904 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_AVAILABLE); |
| 905 | break; |
| 906 | case NL80211_RADAR_CAC_ABORTED: |
| 907 | break; |
| 908 | default: |
| 909 | WARN_ON(1); |
| 910 | return; |
| 911 | } |
| 912 | wdev->cac_started = false; |
| 913 | |
| 914 | nl80211_radar_notify(rdev, &chandef, event, netdev, gfp); |
| 915 | } |
| 916 | EXPORT_SYMBOL(cfg80211_cac_event); |