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