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