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