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