Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2 | /* |
| 3 | * This is the new netlink-based wireless configuration interface. |
| 4 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 2740f0c | 2014-09-03 15:24:58 +0300 | [diff] [blame] | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 7 | * Copyright 2015-2017 Intel Deutschland GmbH |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 8 | * Copyright (C) 2018-2019 Intel Corporation |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/if.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15 | #include <linux/list.h> |
| 16 | #include <linux/if_ether.h> |
| 17 | #include <linux/ieee80211.h> |
| 18 | #include <linux/nl80211.h> |
| 19 | #include <linux/rtnetlink.h> |
| 20 | #include <linux/netlink.h> |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 21 | #include <linux/nospec.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 22 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 23 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 24 | #include <net/genetlink.h> |
| 25 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 26 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 27 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 28 | #include "core.h" |
| 29 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 30 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 31 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 32 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 33 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 34 | struct genl_info *info, |
| 35 | struct cfg80211_crypto_settings *settings, |
| 36 | int cipher_limit); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 39 | static struct genl_family nl80211_fam; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 40 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 41 | /* multicast groups */ |
| 42 | enum nl80211_multicast_groups { |
| 43 | NL80211_MCGRP_CONFIG, |
| 44 | NL80211_MCGRP_SCAN, |
| 45 | NL80211_MCGRP_REGULATORY, |
| 46 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 47 | NL80211_MCGRP_VENDOR, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 48 | NL80211_MCGRP_NAN, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 49 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 50 | }; |
| 51 | |
| 52 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 53 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 54 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 55 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 56 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 57 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 58 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 59 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 60 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 61 | #endif |
| 62 | }; |
| 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | /* returns ERR_PTR values */ |
| 65 | static struct wireless_dev * |
| 66 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 67 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 68 | struct cfg80211_registered_device *rdev; |
| 69 | struct wireless_dev *result = NULL; |
| 70 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 71 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 72 | u64 wdev_id; |
| 73 | int wiphy_idx = -1; |
| 74 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 75 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 76 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 77 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 78 | if (!have_ifidx && !have_wdev_id) |
| 79 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 80 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 81 | if (have_ifidx) |
| 82 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 83 | if (have_wdev_id) { |
| 84 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 85 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 86 | } |
| 87 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 88 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 89 | struct wireless_dev *wdev; |
| 90 | |
| 91 | if (wiphy_net(&rdev->wiphy) != netns) |
| 92 | continue; |
| 93 | |
| 94 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 95 | continue; |
| 96 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 97 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 98 | if (have_ifidx && wdev->netdev && |
| 99 | wdev->netdev->ifindex == ifidx) { |
| 100 | result = wdev; |
| 101 | break; |
| 102 | } |
| 103 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 104 | result = wdev; |
| 105 | break; |
| 106 | } |
| 107 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 108 | |
| 109 | if (result) |
| 110 | break; |
| 111 | } |
| 112 | |
| 113 | if (result) |
| 114 | return result; |
| 115 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 116 | } |
| 117 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 118 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 120 | { |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 121 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 122 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 123 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 124 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 125 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 126 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 127 | !attrs[NL80211_ATTR_IFINDEX] && |
| 128 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 129 | return ERR_PTR(-EINVAL); |
| 130 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 131 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 132 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 133 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 134 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 135 | if (attrs[NL80211_ATTR_WDEV]) { |
| 136 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 137 | struct wireless_dev *wdev; |
| 138 | bool found = false; |
| 139 | |
| 140 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 141 | if (tmp) { |
| 142 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 143 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 144 | if (wdev->identifier != (u32)wdev_id) |
| 145 | continue; |
| 146 | found = true; |
| 147 | break; |
| 148 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 149 | |
| 150 | if (!found) |
| 151 | tmp = NULL; |
| 152 | |
| 153 | if (rdev && tmp != rdev) |
| 154 | return ERR_PTR(-EINVAL); |
| 155 | rdev = tmp; |
| 156 | } |
| 157 | } |
| 158 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 159 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 160 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 161 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 162 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 163 | if (netdev) { |
| 164 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 165 | tmp = wiphy_to_rdev( |
| 166 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 167 | else |
| 168 | tmp = NULL; |
| 169 | |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 170 | /* not wireless device -- return error */ |
| 171 | if (!tmp) |
| 172 | return ERR_PTR(-EINVAL); |
| 173 | |
| 174 | /* mismatch -- return error */ |
| 175 | if (rdev && tmp != rdev) |
| 176 | return ERR_PTR(-EINVAL); |
| 177 | |
| 178 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 179 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
| 181 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 182 | if (!rdev) |
| 183 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 184 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 185 | if (netns != wiphy_net(&rdev->wiphy)) |
| 186 | return ERR_PTR(-ENODEV); |
| 187 | |
| 188 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* |
| 192 | * This function returns a pointer to the driver |
| 193 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 194 | * |
| 195 | * The result of this can be a PTR_ERR and hence must |
| 196 | * be checked with IS_ERR() for errors. |
| 197 | */ |
| 198 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 199 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 200 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 201 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 202 | } |
| 203 | |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 204 | static int validate_beacon_head(const struct nlattr *attr, |
| 205 | struct netlink_ext_ack *extack) |
| 206 | { |
| 207 | const u8 *data = nla_data(attr); |
| 208 | unsigned int len = nla_len(attr); |
| 209 | const struct element *elem; |
| 210 | const struct ieee80211_mgmt *mgmt = (void *)data; |
| 211 | unsigned int fixedlen = offsetof(struct ieee80211_mgmt, |
| 212 | u.beacon.variable); |
| 213 | |
| 214 | if (len < fixedlen) |
| 215 | goto err; |
| 216 | |
| 217 | if (ieee80211_hdrlen(mgmt->frame_control) != |
| 218 | offsetof(struct ieee80211_mgmt, u.beacon)) |
| 219 | goto err; |
| 220 | |
| 221 | data += fixedlen; |
| 222 | len -= fixedlen; |
| 223 | |
| 224 | for_each_element(elem, data, len) { |
| 225 | /* nothing */ |
| 226 | } |
| 227 | |
| 228 | if (for_each_element_completed(elem, data, len)) |
| 229 | return 0; |
| 230 | |
| 231 | err: |
| 232 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); |
| 233 | return -EINVAL; |
| 234 | } |
| 235 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 236 | static int validate_ie_attr(const struct nlattr *attr, |
| 237 | struct netlink_ext_ack *extack) |
| 238 | { |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 239 | const u8 *data = nla_data(attr); |
| 240 | unsigned int len = nla_len(attr); |
Jouni Malinen | 7388afe | 2019-02-11 16:29:04 +0200 | [diff] [blame] | 241 | const struct element *elem; |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 242 | |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 243 | for_each_element(elem, data, len) { |
| 244 | /* nothing */ |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 245 | } |
| 246 | |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 247 | if (for_each_element_completed(elem, data, len)) |
| 248 | return 0; |
| 249 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 250 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); |
| 251 | return -EINVAL; |
| 252 | } |
| 253 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 254 | /* policy for the attributes */ |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 255 | static const struct nla_policy |
| 256 | nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { |
| 257 | [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, |
| 258 | [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, |
| 259 | .len = U8_MAX }, |
| 260 | [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, |
| 261 | .len = U8_MAX }, |
| 262 | }; |
| 263 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 264 | static const struct nla_policy |
| 265 | nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { |
| 266 | [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, |
| 267 | [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, |
| 268 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = |
| 269 | NLA_POLICY_MAX(NLA_U8, 15), |
| 270 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, |
| 271 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = |
| 272 | NLA_POLICY_MAX(NLA_U8, 15), |
| 273 | [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = |
Aviya Erenfeld | ea18709 | 2019-02-06 13:17:08 +0200 | [diff] [blame] | 274 | NLA_POLICY_MAX(NLA_U8, 31), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 275 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, |
| 276 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, |
| 277 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, |
| 278 | }; |
| 279 | |
| 280 | static const struct nla_policy |
| 281 | nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { |
| 282 | [NL80211_PMSR_TYPE_FTM] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 283 | NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 284 | }; |
| 285 | |
| 286 | static const struct nla_policy |
| 287 | nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { |
| 288 | [NL80211_PMSR_REQ_ATTR_DATA] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 289 | NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 290 | [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, |
| 291 | }; |
| 292 | |
| 293 | static const struct nla_policy |
| 294 | nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { |
| 295 | [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, |
| 296 | /* |
| 297 | * we could specify this again to be the top-level policy, |
| 298 | * but that would open us up to recursion problems ... |
| 299 | */ |
| 300 | [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_NESTED }, |
| 301 | [NL80211_PMSR_PEER_ATTR_REQ] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 302 | NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 303 | [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, |
| 304 | }; |
| 305 | |
| 306 | static const struct nla_policy |
| 307 | nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { |
| 308 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, |
| 309 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, |
| 310 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, |
| 311 | [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, |
| 312 | [NL80211_PMSR_ATTR_PEERS] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 313 | NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 314 | }; |
| 315 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 316 | static const struct nla_policy |
| 317 | he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { |
| 318 | [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = |
| 319 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 320 | [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = |
| 321 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 322 | }; |
| 323 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 324 | static const struct nla_policy |
| 325 | he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { |
| 326 | [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), |
| 327 | [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, |
| 328 | [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, |
| 329 | }; |
| 330 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 331 | static const struct nla_policy |
| 332 | nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 333 | [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, |
| 334 | [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 335 | [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 336 | [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 337 | [NL80211_TID_CONFIG_ATTR_NOACK] = |
| 338 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
| 339 | }; |
| 340 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 341 | const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 6d4dd4e | 2019-07-31 10:58:20 +0200 | [diff] [blame] | 342 | [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 343 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 344 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 345 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 346 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 347 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 349 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 350 | [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, |
| 351 | NL80211_EDMG_CHANNELS_MIN, |
| 352 | NL80211_EDMG_CHANNELS_MAX), |
| 353 | [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, |
| 354 | NL80211_EDMG_BW_CONFIG_MIN, |
| 355 | NL80211_EDMG_BW_CONFIG_MAX), |
| 356 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 357 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 358 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 359 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 360 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 361 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 362 | [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 363 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 364 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 365 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 366 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 367 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 368 | [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 369 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 370 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 371 | |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 372 | [NL80211_ATTR_MAC] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN }, |
| 373 | [NL80211_ATTR_PREV_BSSID] = { |
| 374 | .type = NLA_EXACT_LEN_WARN, |
| 375 | .len = ETH_ALEN |
| 376 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 377 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 379 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 380 | .len = WLAN_MAX_KEY_LEN }, |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 381 | [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 382 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 383 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 384 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 385 | [NL80211_ATTR_KEY_TYPE] = |
| 386 | NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 387 | |
| 388 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 389 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 390 | [NL80211_ATTR_BEACON_HEAD] = |
| 391 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, |
| 392 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 393 | [NL80211_ATTR_BEACON_TAIL] = |
| 394 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 395 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 396 | [NL80211_ATTR_STA_AID] = |
| 397 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 398 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 399 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 400 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 401 | .len = NL80211_MAX_SUPP_RATES }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 402 | [NL80211_ATTR_STA_PLINK_ACTION] = |
| 403 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 404 | [NL80211_ATTR_STA_TX_POWER_SETTING] = |
| 405 | NLA_POLICY_RANGE(NLA_U8, |
| 406 | NL80211_TX_POWER_AUTOMATIC, |
| 407 | NL80211_TX_POWER_FIXED), |
| 408 | [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 409 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 410 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 411 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 412 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Markus Theil | 1fab1b8 | 2019-10-29 10:30:03 +0100 | [diff] [blame] | 413 | [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 414 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 415 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 416 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 417 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 418 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 419 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 420 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 421 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 422 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 423 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 424 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 425 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 426 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 427 | |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 428 | [NL80211_ATTR_HT_CAPABILITY] = { |
| 429 | .type = NLA_EXACT_LEN_WARN, |
| 430 | .len = NL80211_HT_CAPABILITY_LEN |
| 431 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 432 | |
| 433 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 434 | [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, |
| 435 | validate_ie_attr, |
| 436 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 437 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 438 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 439 | |
| 440 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 441 | .len = IEEE80211_MAX_SSID_LEN }, |
| 442 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 443 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 444 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 445 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 446 | [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, |
| 447 | NL80211_MFP_NO, |
| 448 | NL80211_MFP_OPTIONAL), |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 449 | [NL80211_ATTR_STA_FLAGS2] = { |
| 450 | .len = sizeof(struct nl80211_sta_flag_update), |
| 451 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 452 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 453 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 454 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 455 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 456 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
Sergey Matyukevich | ea75080 | 2020-02-13 13:16:16 +0000 | [diff] [blame] | 457 | [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 458 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 459 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 460 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 461 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 462 | [NL80211_ATTR_PMKID] = { |
| 463 | .type = NLA_EXACT_LEN_WARN, |
| 464 | .len = WLAN_PMKID_LEN |
| 465 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 466 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 467 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 468 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 469 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 470 | .len = IEEE80211_MAX_DATA_LEN }, |
| 471 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 472 | [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, |
| 473 | NL80211_PS_DISABLED, |
| 474 | NL80211_PS_ENABLED), |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 475 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 476 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 477 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 478 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 479 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 480 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 481 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 482 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 483 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 484 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 485 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 486 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 487 | [NL80211_ATTR_STA_PLINK_STATE] = |
| 488 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), |
| 489 | [NL80211_ATTR_MESH_PEER_AID] = |
| 490 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 491 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 492 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 493 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 494 | [NL80211_ATTR_HIDDEN_SSID] = |
| 495 | NLA_POLICY_RANGE(NLA_U32, |
| 496 | NL80211_HIDDEN_SSID_NOT_IN_USE, |
| 497 | NL80211_HIDDEN_SSID_ZERO_CONTENTS), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 498 | [NL80211_ATTR_IE_PROBE_RESP] = |
| 499 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 500 | IEEE80211_MAX_DATA_LEN), |
| 501 | [NL80211_ATTR_IE_ASSOC_RESP] = |
| 502 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 503 | IEEE80211_MAX_DATA_LEN), |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 504 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 505 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 506 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 507 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 508 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 509 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 510 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 511 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 512 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 513 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 514 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 515 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 516 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 517 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 518 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 519 | .len = NL80211_HT_CAPABILITY_LEN |
| 520 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 521 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 522 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 523 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 524 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 525 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 526 | [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 527 | [NL80211_ATTR_VHT_CAPABILITY] = { |
| 528 | .type = NLA_EXACT_LEN_WARN, |
| 529 | .len = NL80211_VHT_CAPABILITY_LEN |
| 530 | }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 531 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 532 | [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), |
| 533 | [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 534 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = |
| 535 | NLA_POLICY_RANGE(NLA_U32, |
| 536 | NL80211_MESH_POWER_UNKNOWN + 1, |
| 537 | NL80211_MESH_POWER_MAX), |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 538 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 539 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 540 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 541 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 542 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 543 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 544 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 545 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 546 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 547 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 548 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 549 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 550 | [NL80211_ATTR_PEER_AID] = |
| 551 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 552 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 553 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 554 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 555 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 556 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 557 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 558 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 559 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 560 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 561 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 562 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 563 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 564 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 565 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 566 | [NL80211_ATTR_MAC_HINT] = { |
| 567 | .type = NLA_EXACT_LEN_WARN, |
| 568 | .len = ETH_ALEN |
| 569 | }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 570 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 571 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 572 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 573 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 574 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 575 | [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), |
| 576 | [NL80211_ATTR_USER_PRIO] = |
| 577 | NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 578 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 579 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 580 | [NL80211_ATTR_MAC_MASK] = { |
| 581 | .type = NLA_EXACT_LEN_WARN, |
| 582 | .len = ETH_ALEN |
| 583 | }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 584 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 585 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 586 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 587 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 588 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 589 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 590 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = |
| 591 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 592 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 593 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 594 | }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 595 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { |
| 596 | .type = NLA_EXACT_LEN_WARN, |
| 597 | .len = ETH_ALEN |
| 598 | }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 599 | [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 600 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 601 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 602 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 603 | .len = FILS_MAX_KEK_LEN }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 604 | [NL80211_ATTR_FILS_NONCES] = { |
| 605 | .type = NLA_EXACT_LEN_WARN, |
| 606 | .len = 2 * FILS_NONCE_LEN |
| 607 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 608 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 609 | [NL80211_ATTR_BSSID] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN }, |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 610 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 611 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 612 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 613 | }, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 614 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 615 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 616 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 617 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 618 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 619 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 620 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 621 | .len = FILS_ERP_MAX_RRK_LEN }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 622 | [NL80211_ATTR_FILS_CACHE_ID] = { .type = NLA_EXACT_LEN_WARN, .len = 2 }, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 623 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 624 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 625 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 626 | |
| 627 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, |
| 628 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, |
| 629 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 630 | [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY, |
| 631 | .len = NL80211_HE_MAX_CAPABILITY_LEN }, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 632 | |
| 633 | [NL80211_ATTR_FTM_RESPONDER] = { |
| 634 | .type = NLA_NESTED, |
| 635 | .validation_data = nl80211_ftm_responder_policy, |
| 636 | }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 637 | [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), |
| 638 | [NL80211_ATTR_PEER_MEASUREMENTS] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 639 | NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 640 | [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 641 | [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, |
| 642 | .len = SAE_PASSWORD_MAX_LEN }, |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 643 | [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 644 | [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 645 | [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2), |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 646 | [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 647 | [NL80211_ATTR_TID_CONFIG] = |
| 648 | NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 649 | }; |
| 650 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 651 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 652 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 653 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 654 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 655 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 656 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 657 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 658 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 659 | [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 660 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 661 | [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 662 | }; |
| 663 | |
| 664 | /* policy for the key default flags */ |
| 665 | static const struct nla_policy |
| 666 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 667 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 668 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 669 | }; |
| 670 | |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 671 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 672 | /* policy for WoWLAN attributes */ |
| 673 | static const struct nla_policy |
| 674 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 675 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 676 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 677 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 678 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 679 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 680 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 681 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 682 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 683 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 684 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 685 | }; |
| 686 | |
| 687 | static const struct nla_policy |
| 688 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 689 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 690 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 691 | [NL80211_WOWLAN_TCP_DST_MAC] = { |
| 692 | .type = NLA_EXACT_LEN_WARN, |
| 693 | .len = ETH_ALEN |
| 694 | }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 695 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 696 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 697 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 698 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 699 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 700 | }, |
| 701 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 702 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 703 | }, |
| 704 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 705 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 }, |
| 706 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 707 | }; |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 708 | #endif /* CONFIG_PM */ |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 709 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 710 | /* policy for coalesce rule attributes */ |
| 711 | static const struct nla_policy |
| 712 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 713 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 714 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = |
| 715 | NLA_POLICY_RANGE(NLA_U32, |
| 716 | NL80211_COALESCE_CONDITION_MATCH, |
| 717 | NL80211_COALESCE_CONDITION_NO_MATCH), |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 718 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 719 | }; |
| 720 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 721 | /* policy for GTK rekey offload attributes */ |
| 722 | static const struct nla_policy |
| 723 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
Johannes Berg | 180aa42 | 2019-05-28 14:19:07 +0200 | [diff] [blame] | 724 | [NL80211_REKEY_DATA_KEK] = { |
| 725 | .type = NLA_EXACT_LEN_WARN, |
| 726 | .len = NL80211_KEK_LEN, |
| 727 | }, |
| 728 | [NL80211_REKEY_DATA_KCK] = { |
| 729 | .type = NLA_EXACT_LEN_WARN, |
| 730 | .len = NL80211_KCK_LEN, |
| 731 | }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 732 | [NL80211_REKEY_DATA_REPLAY_CTR] = { |
| 733 | .type = NLA_EXACT_LEN_WARN, |
| 734 | .len = NL80211_REPLAY_CTR_LEN |
| 735 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 736 | }; |
| 737 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 738 | static const struct nla_policy |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 739 | nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { |
| 740 | [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, |
| 741 | [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, |
Arend van Spriel | e548a1c | 2019-08-02 13:31:02 +0200 | [diff] [blame] | 742 | [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 743 | [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, |
| 744 | }; |
| 745 | |
| 746 | static const struct nla_policy |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 747 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 748 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 749 | .len = IEEE80211_MAX_SSID_LEN }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 750 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { |
| 751 | .type = NLA_EXACT_LEN_WARN, |
| 752 | .len = ETH_ALEN |
| 753 | }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 754 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 755 | [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = |
| 756 | NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 757 | }; |
| 758 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 759 | static const struct nla_policy |
| 760 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 761 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 762 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 763 | }; |
| 764 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 765 | static const struct nla_policy |
| 766 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 767 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 768 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 769 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 770 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 771 | }, |
| 772 | }; |
| 773 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 774 | /* policy for NAN function attributes */ |
| 775 | static const struct nla_policy |
| 776 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
| 777 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, |
Srinivas Dasari | 0a27844 | 2017-07-07 01:43:40 +0300 | [diff] [blame] | 778 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 779 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 780 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 781 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 782 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 783 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 784 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
Johannes Berg | 1a28ed2 | 2019-05-28 14:18:07 +0200 | [diff] [blame] | 785 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { |
| 786 | .type = NLA_EXACT_LEN_WARN, |
| 787 | .len = ETH_ALEN |
| 788 | }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 789 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 790 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 791 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 792 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 793 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 794 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 795 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 796 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 797 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 798 | }; |
| 799 | |
| 800 | /* policy for Service Response Filter attributes */ |
| 801 | static const struct nla_policy |
| 802 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 803 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 804 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 805 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 806 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 807 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 808 | }; |
| 809 | |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 810 | /* policy for packet pattern attributes */ |
| 811 | static const struct nla_policy |
| 812 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { |
| 813 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, |
| 814 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, |
| 815 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, |
| 816 | }; |
| 817 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 818 | int nl80211_prepare_wdev_dump(struct netlink_callback *cb, |
| 819 | struct cfg80211_registered_device **rdev, |
| 820 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 821 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 822 | int err; |
| 823 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 824 | if (!cb->args[0]) { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 825 | struct nlattr **attrbuf; |
| 826 | |
| 827 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 828 | GFP_KERNEL); |
| 829 | if (!attrbuf) |
| 830 | return -ENOMEM; |
| 831 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 832 | err = nlmsg_parse_deprecated(cb->nlh, |
| 833 | GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 834 | attrbuf, nl80211_fam.maxattr, |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 835 | nl80211_policy, NULL); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 836 | if (err) { |
| 837 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 838 | return err; |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 839 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 840 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 841 | *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk), |
| 842 | attrbuf); |
| 843 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 844 | if (IS_ERR(*wdev)) |
| 845 | return PTR_ERR(*wdev); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 846 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 847 | /* 0 is the first index - add 1 to parse only once */ |
| 848 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 849 | cb->args[1] = (*wdev)->identifier; |
| 850 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 851 | /* subtract the 1 again here */ |
| 852 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 853 | struct wireless_dev *tmp; |
| 854 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 855 | if (!wiphy) |
| 856 | return -ENODEV; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 857 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 858 | *wdev = NULL; |
| 859 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 860 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 861 | if (tmp->identifier == cb->args[1]) { |
| 862 | *wdev = tmp; |
| 863 | break; |
| 864 | } |
| 865 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 866 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 867 | if (!*wdev) |
| 868 | return -ENODEV; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 869 | } |
| 870 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 871 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 872 | } |
| 873 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 874 | /* message building helper */ |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 875 | void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
| 876 | int flags, u8 cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 877 | { |
| 878 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 879 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 880 | } |
| 881 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 882 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, |
| 883 | const struct ieee80211_reg_rule *rule) |
| 884 | { |
| 885 | int j; |
| 886 | struct nlattr *nl_wmm_rules = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 887 | nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 888 | |
| 889 | if (!nl_wmm_rules) |
| 890 | goto nla_put_failure; |
| 891 | |
| 892 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 893 | struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 894 | |
| 895 | if (!nl_wmm_rule) |
| 896 | goto nla_put_failure; |
| 897 | |
| 898 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 899 | rule->wmm_rule.client[j].cw_min) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 900 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 901 | rule->wmm_rule.client[j].cw_max) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 902 | nla_put_u8(msg, NL80211_WMMR_AIFSN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 903 | rule->wmm_rule.client[j].aifsn) || |
Haim Dreyfuss | d3c89bb | 2018-08-21 09:22:19 +0300 | [diff] [blame] | 904 | nla_put_u16(msg, NL80211_WMMR_TXOP, |
| 905 | rule->wmm_rule.client[j].cot)) |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 906 | goto nla_put_failure; |
| 907 | |
| 908 | nla_nest_end(msg, nl_wmm_rule); |
| 909 | } |
| 910 | nla_nest_end(msg, nl_wmm_rules); |
| 911 | |
| 912 | return 0; |
| 913 | |
| 914 | nla_put_failure: |
| 915 | return -ENOBUFS; |
| 916 | } |
| 917 | |
| 918 | static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 919 | struct ieee80211_channel *chan, |
| 920 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 921 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 922 | /* Some channels must be completely excluded from the |
| 923 | * list to protect old user-space tools from breaking |
| 924 | */ |
| 925 | if (!large && chan->flags & |
| 926 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 927 | return 0; |
| 928 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 929 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 930 | chan->center_freq)) |
| 931 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 932 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 933 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 934 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 935 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 936 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 937 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 938 | goto nla_put_failure; |
| 939 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 940 | goto nla_put_failure; |
| 941 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 942 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 943 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 944 | goto nla_put_failure; |
| 945 | if (large) { |
| 946 | u32 time; |
| 947 | |
| 948 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 949 | |
| 950 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 951 | chan->dfs_state)) |
| 952 | goto nla_put_failure; |
| 953 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 954 | time)) |
| 955 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 956 | if (nla_put_u32(msg, |
| 957 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 958 | chan->dfs_cac_ms)) |
| 959 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 960 | } |
| 961 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 962 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 963 | if (large) { |
| 964 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 965 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 966 | goto nla_put_failure; |
| 967 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 968 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 969 | goto nla_put_failure; |
| 970 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 971 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 972 | goto nla_put_failure; |
| 973 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 974 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 975 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 976 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 977 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 978 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 979 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 980 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 981 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 982 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 983 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 984 | goto nla_put_failure; |
| 985 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 986 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 987 | goto nla_put_failure; |
Haim Dreyfuss | 1e61d82 | 2020-01-21 10:12:13 +0200 | [diff] [blame] | 988 | if ((chan->flags & IEEE80211_CHAN_NO_HE) && |
| 989 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) |
| 990 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 991 | } |
| 992 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 993 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 994 | DBM_TO_MBM(chan->max_power))) |
| 995 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 996 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 997 | if (large) { |
| 998 | const struct ieee80211_reg_rule *rule = |
Haim Dreyfuss | b88d26d | 2018-08-21 09:22:20 +0300 | [diff] [blame] | 999 | freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1000 | |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 1001 | if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1002 | if (nl80211_msg_put_wmm_rules(msg, rule)) |
| 1003 | goto nla_put_failure; |
| 1004 | } |
| 1005 | } |
| 1006 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1007 | return 0; |
| 1008 | |
| 1009 | nla_put_failure: |
| 1010 | return -ENOBUFS; |
| 1011 | } |
| 1012 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1013 | static bool nl80211_put_txq_stats(struct sk_buff *msg, |
| 1014 | struct cfg80211_txq_stats *txqstats, |
| 1015 | int attrtype) |
| 1016 | { |
| 1017 | struct nlattr *txqattr; |
| 1018 | |
| 1019 | #define PUT_TXQVAL_U32(attr, memb) do { \ |
| 1020 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ |
| 1021 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ |
| 1022 | return false; \ |
| 1023 | } while (0) |
| 1024 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1025 | txqattr = nla_nest_start_noflag(msg, attrtype); |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1026 | if (!txqattr) |
| 1027 | return false; |
| 1028 | |
| 1029 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); |
| 1030 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); |
| 1031 | PUT_TXQVAL_U32(FLOWS, flows); |
| 1032 | PUT_TXQVAL_U32(DROPS, drops); |
| 1033 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); |
| 1034 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); |
| 1035 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); |
| 1036 | PUT_TXQVAL_U32(COLLISIONS, collisions); |
| 1037 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); |
| 1038 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); |
| 1039 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); |
| 1040 | nla_nest_end(msg, txqattr); |
| 1041 | |
| 1042 | #undef PUT_TXQVAL_U32 |
| 1043 | return true; |
| 1044 | } |
| 1045 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1046 | /* netlink command implementations */ |
| 1047 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1048 | struct key_parse { |
| 1049 | struct key_params p; |
| 1050 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1051 | int type; |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1052 | bool def, defmgmt, defbeacon; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1053 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1054 | }; |
| 1055 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1056 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
| 1057 | struct key_parse *k) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1058 | { |
| 1059 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1060 | int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, |
| 1061 | nl80211_key_policy, |
| 1062 | info->extack); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1063 | if (err) |
| 1064 | return err; |
| 1065 | |
| 1066 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 1067 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1068 | k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1069 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1070 | if (k->def) { |
| 1071 | k->def_uni = true; |
| 1072 | k->def_multi = true; |
| 1073 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1074 | if (k->defmgmt || k->defbeacon) |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1075 | k->def_multi = true; |
| 1076 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1077 | if (tb[NL80211_KEY_IDX]) |
| 1078 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 1079 | |
| 1080 | if (tb[NL80211_KEY_DATA]) { |
| 1081 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 1082 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 1083 | } |
| 1084 | |
| 1085 | if (tb[NL80211_KEY_SEQ]) { |
| 1086 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 1087 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 1088 | } |
| 1089 | |
| 1090 | if (tb[NL80211_KEY_CIPHER]) |
| 1091 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 1092 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1093 | if (tb[NL80211_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1094 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1095 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1096 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 1097 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1098 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1099 | err = nla_parse_nested_deprecated(kdt, |
| 1100 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1101 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 1102 | nl80211_key_default_policy, |
| 1103 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1104 | if (err) |
| 1105 | return err; |
| 1106 | |
| 1107 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1108 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1109 | } |
| 1110 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 1111 | if (tb[NL80211_KEY_MODE]) |
| 1112 | k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); |
| 1113 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1114 | return 0; |
| 1115 | } |
| 1116 | |
| 1117 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 1118 | { |
| 1119 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 1120 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1121 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1122 | } |
| 1123 | |
| 1124 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 1125 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1126 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1127 | } |
| 1128 | |
| 1129 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1130 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1131 | |
| 1132 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 1133 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 1134 | |
| 1135 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 1136 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 1137 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1138 | if (k->def) { |
| 1139 | k->def_uni = true; |
| 1140 | k->def_multi = true; |
| 1141 | } |
| 1142 | if (k->defmgmt) |
| 1143 | k->def_multi = true; |
| 1144 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1145 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1146 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1147 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1148 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 1149 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1150 | int err = nla_parse_nested_deprecated(kdt, |
| 1151 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1152 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 1153 | nl80211_key_default_policy, |
| 1154 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1155 | if (err) |
| 1156 | return err; |
| 1157 | |
| 1158 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1159 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1160 | } |
| 1161 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1162 | return 0; |
| 1163 | } |
| 1164 | |
| 1165 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 1166 | { |
| 1167 | int err; |
| 1168 | |
| 1169 | memset(k, 0, sizeof(*k)); |
| 1170 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1171 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1172 | |
| 1173 | if (info->attrs[NL80211_ATTR_KEY]) |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1174 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1175 | else |
| 1176 | err = nl80211_parse_key_old(info, k); |
| 1177 | |
| 1178 | if (err) |
| 1179 | return err; |
| 1180 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1181 | if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + |
| 1182 | (k->defbeacon ? 1 : 0) > 1) { |
| 1183 | GENL_SET_ERR_MSG(info, |
| 1184 | "key with multiple default flags is invalid"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1185 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1186 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1187 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1188 | if (k->defmgmt || k->defbeacon) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1189 | if (k->def_uni || !k->def_multi) { |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1190 | GENL_SET_ERR_MSG(info, |
| 1191 | "defmgmt/defbeacon key must be mcast"); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1192 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1193 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1194 | } |
| 1195 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1196 | if (k->idx != -1) { |
| 1197 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1198 | if (k->idx < 4 || k->idx > 5) { |
| 1199 | GENL_SET_ERR_MSG(info, |
| 1200 | "defmgmt key idx not 4 or 5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1201 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1202 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1203 | } else if (k->defbeacon) { |
| 1204 | if (k->idx < 6 || k->idx > 7) { |
| 1205 | GENL_SET_ERR_MSG(info, |
| 1206 | "defbeacon key idx not 6 or 7"); |
| 1207 | return -EINVAL; |
| 1208 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1209 | } else if (k->def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1210 | if (k->idx < 0 || k->idx > 3) { |
| 1211 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1212 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1213 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1214 | } else { |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1215 | if (k->idx < 0 || k->idx > 7) { |
| 1216 | GENL_SET_ERR_MSG(info, "key idx not 0-7"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1217 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1218 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | return 0; |
| 1223 | } |
| 1224 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1225 | static struct cfg80211_cached_keys * |
| 1226 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1227 | struct genl_info *info, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1228 | { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1229 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1230 | struct key_parse parse; |
| 1231 | struct nlattr *key; |
| 1232 | struct cfg80211_cached_keys *result; |
| 1233 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1234 | bool have_key = false; |
| 1235 | |
| 1236 | nla_for_each_nested(key, keys, rem) { |
| 1237 | have_key = true; |
| 1238 | break; |
| 1239 | } |
| 1240 | |
| 1241 | if (!have_key) |
| 1242 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1243 | |
| 1244 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 1245 | if (!result) |
| 1246 | return ERR_PTR(-ENOMEM); |
| 1247 | |
| 1248 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1249 | |
| 1250 | nla_for_each_nested(key, keys, rem) { |
| 1251 | memset(&parse, 0, sizeof(parse)); |
| 1252 | parse.idx = -1; |
| 1253 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1254 | err = nl80211_parse_key_new(info, key, &parse); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1255 | if (err) |
| 1256 | goto error; |
| 1257 | err = -EINVAL; |
| 1258 | if (!parse.p.key) |
| 1259 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1260 | if (parse.idx < 0 || parse.idx > 3) { |
| 1261 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1262 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1263 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1264 | if (parse.def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1265 | if (def) { |
| 1266 | GENL_SET_ERR_MSG(info, |
| 1267 | "only one key can be default"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1268 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1269 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1270 | def = 1; |
| 1271 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1272 | if (!parse.def_uni || !parse.def_multi) |
| 1273 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1274 | } else if (parse.defmgmt) |
| 1275 | goto error; |
| 1276 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1277 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1278 | if (err) |
| 1279 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1280 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1281 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1282 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1283 | err = -EINVAL; |
| 1284 | goto error; |
| 1285 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1286 | result->params[parse.idx].cipher = parse.p.cipher; |
| 1287 | result->params[parse.idx].key_len = parse.p.key_len; |
| 1288 | result->params[parse.idx].key = result->data[parse.idx]; |
| 1289 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 1290 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1291 | /* must be WEP key if we got here */ |
| 1292 | if (no_ht) |
| 1293 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1294 | } |
| 1295 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1296 | if (result->def < 0) { |
| 1297 | err = -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1298 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1299 | goto error; |
| 1300 | } |
| 1301 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1302 | return result; |
| 1303 | error: |
| 1304 | kfree(result); |
| 1305 | return ERR_PTR(err); |
| 1306 | } |
| 1307 | |
| 1308 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 1309 | { |
| 1310 | ASSERT_WDEV_LOCK(wdev); |
| 1311 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1312 | switch (wdev->iftype) { |
| 1313 | case NL80211_IFTYPE_AP: |
| 1314 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1315 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 1316 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1317 | break; |
| 1318 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1319 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1320 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1321 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1322 | return -ENOLINK; |
| 1323 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1324 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 1325 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1326 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 1327 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1328 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1329 | case NL80211_IFTYPE_WDS: |
| 1330 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1331 | return -EINVAL; |
| 1332 | } |
| 1333 | |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1337 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 1338 | struct nlattr *tb) |
| 1339 | { |
| 1340 | struct ieee80211_channel *chan; |
| 1341 | |
| 1342 | if (tb == NULL) |
| 1343 | return NULL; |
| 1344 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 1345 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1346 | return NULL; |
| 1347 | return chan; |
| 1348 | } |
| 1349 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1350 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1351 | { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1352 | struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1353 | int i; |
| 1354 | |
| 1355 | if (!nl_modes) |
| 1356 | goto nla_put_failure; |
| 1357 | |
| 1358 | i = 0; |
| 1359 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1360 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1361 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1362 | ifmodes >>= 1; |
| 1363 | i++; |
| 1364 | } |
| 1365 | |
| 1366 | nla_nest_end(msg, nl_modes); |
| 1367 | return 0; |
| 1368 | |
| 1369 | nla_put_failure: |
| 1370 | return -ENOBUFS; |
| 1371 | } |
| 1372 | |
| 1373 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1374 | struct sk_buff *msg, |
| 1375 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1376 | { |
| 1377 | struct nlattr *nl_combis; |
| 1378 | int i, j; |
| 1379 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1380 | nl_combis = nla_nest_start_noflag(msg, |
| 1381 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1382 | if (!nl_combis) |
| 1383 | goto nla_put_failure; |
| 1384 | |
| 1385 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1386 | const struct ieee80211_iface_combination *c; |
| 1387 | struct nlattr *nl_combi, *nl_limits; |
| 1388 | |
| 1389 | c = &wiphy->iface_combinations[i]; |
| 1390 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1391 | nl_combi = nla_nest_start_noflag(msg, i + 1); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1392 | if (!nl_combi) |
| 1393 | goto nla_put_failure; |
| 1394 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1395 | nl_limits = nla_nest_start_noflag(msg, |
| 1396 | NL80211_IFACE_COMB_LIMITS); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1397 | if (!nl_limits) |
| 1398 | goto nla_put_failure; |
| 1399 | |
| 1400 | for (j = 0; j < c->n_limits; j++) { |
| 1401 | struct nlattr *nl_limit; |
| 1402 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1403 | nl_limit = nla_nest_start_noflag(msg, j + 1); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1404 | if (!nl_limit) |
| 1405 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1406 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1407 | c->limits[j].max)) |
| 1408 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1409 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1410 | c->limits[j].types)) |
| 1411 | goto nla_put_failure; |
| 1412 | nla_nest_end(msg, nl_limit); |
| 1413 | } |
| 1414 | |
| 1415 | nla_nest_end(msg, nl_limits); |
| 1416 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1417 | if (c->beacon_int_infra_match && |
| 1418 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1419 | goto nla_put_failure; |
| 1420 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1421 | c->num_different_channels) || |
| 1422 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1423 | c->max_interfaces)) |
| 1424 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1425 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1426 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1427 | c->radar_detect_widths) || |
| 1428 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1429 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1430 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1431 | if (c->beacon_int_min_gcd && |
| 1432 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1433 | c->beacon_int_min_gcd)) |
| 1434 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1435 | |
| 1436 | nla_nest_end(msg, nl_combi); |
| 1437 | } |
| 1438 | |
| 1439 | nla_nest_end(msg, nl_combis); |
| 1440 | |
| 1441 | return 0; |
| 1442 | nla_put_failure: |
| 1443 | return -ENOBUFS; |
| 1444 | } |
| 1445 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1446 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1447 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1448 | struct sk_buff *msg) |
| 1449 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1450 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1451 | struct nlattr *nl_tcp; |
| 1452 | |
| 1453 | if (!tcp) |
| 1454 | return 0; |
| 1455 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1456 | nl_tcp = nla_nest_start_noflag(msg, |
| 1457 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1458 | if (!nl_tcp) |
| 1459 | return -ENOBUFS; |
| 1460 | |
| 1461 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1462 | tcp->data_payload_max)) |
| 1463 | return -ENOBUFS; |
| 1464 | |
| 1465 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1466 | tcp->data_payload_max)) |
| 1467 | return -ENOBUFS; |
| 1468 | |
| 1469 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1470 | return -ENOBUFS; |
| 1471 | |
| 1472 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1473 | sizeof(*tcp->tok), tcp->tok)) |
| 1474 | return -ENOBUFS; |
| 1475 | |
| 1476 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1477 | tcp->data_interval_max)) |
| 1478 | return -ENOBUFS; |
| 1479 | |
| 1480 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1481 | tcp->wake_payload_max)) |
| 1482 | return -ENOBUFS; |
| 1483 | |
| 1484 | nla_nest_end(msg, nl_tcp); |
| 1485 | return 0; |
| 1486 | } |
| 1487 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1488 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1489 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1490 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1491 | { |
| 1492 | struct nlattr *nl_wowlan; |
| 1493 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1494 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1495 | return 0; |
| 1496 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1497 | nl_wowlan = nla_nest_start_noflag(msg, |
| 1498 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1499 | if (!nl_wowlan) |
| 1500 | return -ENOBUFS; |
| 1501 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1502 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1504 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1505 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1506 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1507 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1508 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1509 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1510 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1511 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1512 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1513 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1514 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1515 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1516 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1517 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1518 | return -ENOBUFS; |
| 1519 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1520 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1521 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1522 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1523 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1524 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1525 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1526 | }; |
| 1527 | |
| 1528 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1529 | sizeof(pat), &pat)) |
| 1530 | return -ENOBUFS; |
| 1531 | } |
| 1532 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1533 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1534 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1535 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1536 | return -ENOBUFS; |
| 1537 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1538 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1539 | return -ENOBUFS; |
| 1540 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1541 | nla_nest_end(msg, nl_wowlan); |
| 1542 | |
| 1543 | return 0; |
| 1544 | } |
| 1545 | #endif |
| 1546 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1547 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1548 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1549 | { |
| 1550 | struct nl80211_coalesce_rule_support rule; |
| 1551 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1552 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1553 | return 0; |
| 1554 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1555 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1556 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1557 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1558 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1559 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1560 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1561 | |
| 1562 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1563 | return -ENOBUFS; |
| 1564 | |
| 1565 | return 0; |
| 1566 | } |
| 1567 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1568 | static int |
| 1569 | nl80211_send_iftype_data(struct sk_buff *msg, |
| 1570 | const struct ieee80211_sband_iftype_data *iftdata) |
| 1571 | { |
| 1572 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; |
| 1573 | |
| 1574 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, |
| 1575 | iftdata->types_mask)) |
| 1576 | return -ENOBUFS; |
| 1577 | |
| 1578 | if (he_cap->has_he) { |
| 1579 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, |
| 1580 | sizeof(he_cap->he_cap_elem.mac_cap_info), |
| 1581 | he_cap->he_cap_elem.mac_cap_info) || |
| 1582 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, |
| 1583 | sizeof(he_cap->he_cap_elem.phy_cap_info), |
| 1584 | he_cap->he_cap_elem.phy_cap_info) || |
| 1585 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, |
| 1586 | sizeof(he_cap->he_mcs_nss_supp), |
| 1587 | &he_cap->he_mcs_nss_supp) || |
| 1588 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, |
| 1589 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) |
| 1590 | return -ENOBUFS; |
| 1591 | } |
| 1592 | |
| 1593 | return 0; |
| 1594 | } |
| 1595 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1596 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1597 | struct ieee80211_supported_band *sband) |
| 1598 | { |
| 1599 | struct nlattr *nl_rates, *nl_rate; |
| 1600 | struct ieee80211_rate *rate; |
| 1601 | int i; |
| 1602 | |
| 1603 | /* add HT info */ |
| 1604 | if (sband->ht_cap.ht_supported && |
| 1605 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1606 | sizeof(sband->ht_cap.mcs), |
| 1607 | &sband->ht_cap.mcs) || |
| 1608 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1609 | sband->ht_cap.cap) || |
| 1610 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1611 | sband->ht_cap.ampdu_factor) || |
| 1612 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1613 | sband->ht_cap.ampdu_density))) |
| 1614 | return -ENOBUFS; |
| 1615 | |
| 1616 | /* add VHT info */ |
| 1617 | if (sband->vht_cap.vht_supported && |
| 1618 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1619 | sizeof(sband->vht_cap.vht_mcs), |
| 1620 | &sband->vht_cap.vht_mcs) || |
| 1621 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1622 | sband->vht_cap.cap))) |
| 1623 | return -ENOBUFS; |
| 1624 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1625 | if (sband->n_iftype_data) { |
| 1626 | struct nlattr *nl_iftype_data = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1627 | nla_nest_start_noflag(msg, |
| 1628 | NL80211_BAND_ATTR_IFTYPE_DATA); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1629 | int err; |
| 1630 | |
| 1631 | if (!nl_iftype_data) |
| 1632 | return -ENOBUFS; |
| 1633 | |
| 1634 | for (i = 0; i < sband->n_iftype_data; i++) { |
| 1635 | struct nlattr *iftdata; |
| 1636 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1637 | iftdata = nla_nest_start_noflag(msg, i + 1); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1638 | if (!iftdata) |
| 1639 | return -ENOBUFS; |
| 1640 | |
| 1641 | err = nl80211_send_iftype_data(msg, |
| 1642 | &sband->iftype_data[i]); |
| 1643 | if (err) |
| 1644 | return err; |
| 1645 | |
| 1646 | nla_nest_end(msg, iftdata); |
| 1647 | } |
| 1648 | |
| 1649 | nla_nest_end(msg, nl_iftype_data); |
| 1650 | } |
| 1651 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 1652 | /* add EDMG info */ |
| 1653 | if (sband->edmg_cap.channels && |
| 1654 | (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, |
| 1655 | sband->edmg_cap.channels) || |
| 1656 | nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, |
| 1657 | sband->edmg_cap.bw_config))) |
| 1658 | |
| 1659 | return -ENOBUFS; |
| 1660 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1661 | /* add bitrates */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1662 | nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1663 | if (!nl_rates) |
| 1664 | return -ENOBUFS; |
| 1665 | |
| 1666 | for (i = 0; i < sband->n_bitrates; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1667 | nl_rate = nla_nest_start_noflag(msg, i); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1668 | if (!nl_rate) |
| 1669 | return -ENOBUFS; |
| 1670 | |
| 1671 | rate = &sband->bitrates[i]; |
| 1672 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1673 | rate->bitrate)) |
| 1674 | return -ENOBUFS; |
| 1675 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1676 | nla_put_flag(msg, |
| 1677 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1678 | return -ENOBUFS; |
| 1679 | |
| 1680 | nla_nest_end(msg, nl_rate); |
| 1681 | } |
| 1682 | |
| 1683 | nla_nest_end(msg, nl_rates); |
| 1684 | |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
| 1688 | static int |
| 1689 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1690 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1691 | { |
| 1692 | u16 stypes; |
| 1693 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1694 | enum nl80211_iftype ift; |
| 1695 | int i; |
| 1696 | |
| 1697 | if (!mgmt_stypes) |
| 1698 | return 0; |
| 1699 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1700 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1701 | if (!nl_ifs) |
| 1702 | return -ENOBUFS; |
| 1703 | |
| 1704 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1705 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1706 | if (!nl_ftypes) |
| 1707 | return -ENOBUFS; |
| 1708 | i = 0; |
| 1709 | stypes = mgmt_stypes[ift].tx; |
| 1710 | while (stypes) { |
| 1711 | if ((stypes & 1) && |
| 1712 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1713 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1714 | return -ENOBUFS; |
| 1715 | stypes >>= 1; |
| 1716 | i++; |
| 1717 | } |
| 1718 | nla_nest_end(msg, nl_ftypes); |
| 1719 | } |
| 1720 | |
| 1721 | nla_nest_end(msg, nl_ifs); |
| 1722 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1723 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1724 | if (!nl_ifs) |
| 1725 | return -ENOBUFS; |
| 1726 | |
| 1727 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1728 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1729 | if (!nl_ftypes) |
| 1730 | return -ENOBUFS; |
| 1731 | i = 0; |
| 1732 | stypes = mgmt_stypes[ift].rx; |
| 1733 | while (stypes) { |
| 1734 | if ((stypes & 1) && |
| 1735 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1736 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1737 | return -ENOBUFS; |
| 1738 | stypes >>= 1; |
| 1739 | i++; |
| 1740 | } |
| 1741 | nla_nest_end(msg, nl_ftypes); |
| 1742 | } |
| 1743 | nla_nest_end(msg, nl_ifs); |
| 1744 | |
| 1745 | return 0; |
| 1746 | } |
| 1747 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1748 | #define CMD(op, n) \ |
| 1749 | do { \ |
| 1750 | if (rdev->ops->op) { \ |
| 1751 | i++; \ |
| 1752 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1753 | goto nla_put_failure; \ |
| 1754 | } \ |
| 1755 | } while (0) |
| 1756 | |
| 1757 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1758 | struct sk_buff *msg) |
| 1759 | { |
| 1760 | int i = 0; |
| 1761 | |
| 1762 | /* |
| 1763 | * do *NOT* add anything into this function, new things need to be |
| 1764 | * advertised only to new versions of userspace that can deal with |
| 1765 | * the split (and they can't possibly care about new features... |
| 1766 | */ |
| 1767 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1768 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1769 | CMD(add_key, NEW_KEY); |
| 1770 | CMD(start_ap, START_AP); |
| 1771 | CMD(add_station, NEW_STATION); |
| 1772 | CMD(add_mpath, NEW_MPATH); |
| 1773 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1774 | CMD(change_bss, SET_BSS); |
| 1775 | CMD(auth, AUTHENTICATE); |
| 1776 | CMD(assoc, ASSOCIATE); |
| 1777 | CMD(deauth, DEAUTHENTICATE); |
| 1778 | CMD(disassoc, DISASSOCIATE); |
| 1779 | CMD(join_ibss, JOIN_IBSS); |
| 1780 | CMD(join_mesh, JOIN_MESH); |
| 1781 | CMD(set_pmksa, SET_PMKSA); |
| 1782 | CMD(del_pmksa, DEL_PMKSA); |
| 1783 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1784 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1785 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1786 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1787 | CMD(mgmt_tx, FRAME); |
| 1788 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1789 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1790 | i++; |
| 1791 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1792 | goto nla_put_failure; |
| 1793 | } |
| 1794 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1795 | rdev->ops->join_mesh) { |
| 1796 | i++; |
| 1797 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1798 | goto nla_put_failure; |
| 1799 | } |
| 1800 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1801 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1802 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1803 | CMD(tdls_oper, TDLS_OPER); |
| 1804 | } |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1805 | if (rdev->wiphy.max_sched_scan_reqs) |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1806 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1807 | CMD(probe_client, PROBE_CLIENT); |
| 1808 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1809 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1810 | i++; |
| 1811 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1812 | goto nla_put_failure; |
| 1813 | } |
| 1814 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1815 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1816 | #ifdef CONFIG_NL80211_TESTMODE |
| 1817 | CMD(testmode_cmd, TESTMODE); |
| 1818 | #endif |
| 1819 | |
| 1820 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1821 | i++; |
| 1822 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1823 | goto nla_put_failure; |
| 1824 | } |
| 1825 | |
| 1826 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1827 | i++; |
| 1828 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1829 | goto nla_put_failure; |
| 1830 | } |
| 1831 | |
| 1832 | return i; |
| 1833 | nla_put_failure: |
| 1834 | return -ENOBUFS; |
| 1835 | } |
| 1836 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1837 | static int |
| 1838 | nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, |
| 1839 | struct sk_buff *msg) |
| 1840 | { |
| 1841 | struct nlattr *ftm; |
| 1842 | |
| 1843 | if (!cap->ftm.supported) |
| 1844 | return 0; |
| 1845 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1846 | ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1847 | if (!ftm) |
| 1848 | return -ENOBUFS; |
| 1849 | |
| 1850 | if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) |
| 1851 | return -ENOBUFS; |
| 1852 | if (cap->ftm.non_asap && |
| 1853 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) |
| 1854 | return -ENOBUFS; |
| 1855 | if (cap->ftm.request_lci && |
| 1856 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) |
| 1857 | return -ENOBUFS; |
| 1858 | if (cap->ftm.request_civicloc && |
| 1859 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) |
| 1860 | return -ENOBUFS; |
| 1861 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, |
| 1862 | cap->ftm.preambles)) |
| 1863 | return -ENOBUFS; |
| 1864 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, |
| 1865 | cap->ftm.bandwidths)) |
| 1866 | return -ENOBUFS; |
| 1867 | if (cap->ftm.max_bursts_exponent >= 0 && |
| 1868 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, |
| 1869 | cap->ftm.max_bursts_exponent)) |
| 1870 | return -ENOBUFS; |
| 1871 | if (cap->ftm.max_ftms_per_burst && |
| 1872 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, |
| 1873 | cap->ftm.max_ftms_per_burst)) |
| 1874 | return -ENOBUFS; |
| 1875 | |
| 1876 | nla_nest_end(msg, ftm); |
| 1877 | return 0; |
| 1878 | } |
| 1879 | |
| 1880 | static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, |
| 1881 | struct sk_buff *msg) |
| 1882 | { |
| 1883 | const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; |
| 1884 | struct nlattr *pmsr, *caps; |
| 1885 | |
| 1886 | if (!cap) |
| 1887 | return 0; |
| 1888 | |
| 1889 | /* |
| 1890 | * we don't need to clean up anything here since the caller |
| 1891 | * will genlmsg_cancel() if we fail |
| 1892 | */ |
| 1893 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1894 | pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1895 | if (!pmsr) |
| 1896 | return -ENOBUFS; |
| 1897 | |
| 1898 | if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) |
| 1899 | return -ENOBUFS; |
| 1900 | |
| 1901 | if (cap->report_ap_tsf && |
| 1902 | nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) |
| 1903 | return -ENOBUFS; |
| 1904 | |
| 1905 | if (cap->randomize_mac_addr && |
| 1906 | nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) |
| 1907 | return -ENOBUFS; |
| 1908 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1909 | caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1910 | if (!caps) |
| 1911 | return -ENOBUFS; |
| 1912 | |
| 1913 | if (nl80211_send_pmsr_ftm_capa(cap, msg)) |
| 1914 | return -ENOBUFS; |
| 1915 | |
| 1916 | nla_nest_end(msg, caps); |
| 1917 | nla_nest_end(msg, pmsr); |
| 1918 | |
| 1919 | return 0; |
| 1920 | } |
| 1921 | |
Veerendranath Jakkam | d6039a3 | 2020-01-27 02:00:32 +0530 | [diff] [blame] | 1922 | static int |
| 1923 | nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, |
| 1924 | struct sk_buff *msg) |
| 1925 | { |
| 1926 | int i; |
| 1927 | struct nlattr *nested, *nested_akms; |
| 1928 | const struct wiphy_iftype_akm_suites *iftype_akms; |
| 1929 | |
| 1930 | if (!rdev->wiphy.num_iftype_akm_suites || |
| 1931 | !rdev->wiphy.iftype_akm_suites) |
| 1932 | return 0; |
| 1933 | |
| 1934 | nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); |
| 1935 | if (!nested) |
| 1936 | return -ENOBUFS; |
| 1937 | |
| 1938 | for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { |
| 1939 | nested_akms = nla_nest_start(msg, i + 1); |
| 1940 | if (!nested_akms) |
| 1941 | return -ENOBUFS; |
| 1942 | |
| 1943 | iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; |
| 1944 | |
| 1945 | if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, |
| 1946 | iftype_akms->iftypes_mask)) |
| 1947 | return -ENOBUFS; |
| 1948 | |
| 1949 | if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, |
| 1950 | sizeof(u32) * iftype_akms->n_akm_suites, |
| 1951 | iftype_akms->akm_suites)) { |
| 1952 | return -ENOBUFS; |
| 1953 | } |
| 1954 | nla_nest_end(msg, nested_akms); |
| 1955 | } |
| 1956 | |
| 1957 | nla_nest_end(msg, nested); |
| 1958 | |
| 1959 | return 0; |
| 1960 | } |
| 1961 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 1962 | static int |
| 1963 | nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, |
| 1964 | struct sk_buff *msg) |
| 1965 | { |
| 1966 | struct nlattr *supp; |
| 1967 | |
| 1968 | if (!rdev->wiphy.tid_config_support.vif && |
| 1969 | !rdev->wiphy.tid_config_support.peer) |
| 1970 | return 0; |
| 1971 | |
| 1972 | supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); |
| 1973 | if (!supp) |
| 1974 | return -ENOSPC; |
| 1975 | |
| 1976 | if (rdev->wiphy.tid_config_support.vif && |
| 1977 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, |
| 1978 | rdev->wiphy.tid_config_support.vif, |
| 1979 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 1980 | goto fail; |
| 1981 | |
| 1982 | if (rdev->wiphy.tid_config_support.peer && |
| 1983 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, |
| 1984 | rdev->wiphy.tid_config_support.peer, |
| 1985 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 1986 | goto fail; |
| 1987 | |
| 1988 | nla_nest_end(msg, supp); |
| 1989 | |
| 1990 | return 0; |
| 1991 | fail: |
| 1992 | nla_nest_cancel(msg, supp); |
| 1993 | return -ENOBUFS; |
| 1994 | } |
| 1995 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1996 | struct nl80211_dump_wiphy_state { |
| 1997 | s64 filter_wiphy; |
| 1998 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1999 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2000 | bool split; |
| 2001 | }; |
| 2002 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2003 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2004 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2005 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2006 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2007 | { |
| 2008 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2009 | struct nlattr *nl_bands, *nl_band; |
| 2010 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2011 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2012 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2013 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2014 | int i; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2015 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2016 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2017 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2018 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2019 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2020 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2021 | return -ENOBUFS; |
| 2022 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2023 | if (WARN_ON(!state)) |
| 2024 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2025 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2026 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2027 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2028 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2029 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2030 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2031 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2032 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2033 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 2034 | goto finish; |
| 2035 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2036 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2037 | case 0: |
| 2038 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2039 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2040 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2041 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2042 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2043 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2044 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2045 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2046 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2047 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2048 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2049 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2050 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2051 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2052 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2053 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2054 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2055 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2056 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 2057 | rdev->wiphy.max_match_sets) || |
| 2058 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 2059 | rdev->wiphy.max_sched_scan_plans) || |
| 2060 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 2061 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 2062 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 2063 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2064 | goto nla_put_failure; |
| 2065 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2066 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2067 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 2068 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2069 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2070 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 2071 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2072 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2073 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 2074 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2075 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2076 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 2077 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2078 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2079 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 2080 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2081 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2082 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2083 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2084 | state->split_start++; |
| 2085 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2086 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2087 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2088 | case 1: |
| 2089 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2090 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 2091 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 2092 | goto nla_put_failure; |
| 2093 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2094 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2095 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2096 | goto nla_put_failure; |
| 2097 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2098 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2099 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 2100 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2101 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2102 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2103 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2104 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2105 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2106 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2107 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2108 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2109 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2110 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2111 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 2112 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2113 | if ((rdev->wiphy.available_antennas_tx || |
| 2114 | rdev->wiphy.available_antennas_rx) && |
| 2115 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2116 | u32 tx_ant = 0, rx_ant = 0; |
| 2117 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2118 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2119 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2120 | if (!res) { |
| 2121 | if (nla_put_u32(msg, |
| 2122 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 2123 | tx_ant) || |
| 2124 | nla_put_u32(msg, |
| 2125 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 2126 | rx_ant)) |
| 2127 | goto nla_put_failure; |
| 2128 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2129 | } |
| 2130 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2131 | state->split_start++; |
| 2132 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2133 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2134 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2135 | case 2: |
| 2136 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2137 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2138 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2139 | state->split_start++; |
| 2140 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2141 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2142 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2143 | case 3: |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2144 | nl_bands = nla_nest_start_noflag(msg, |
| 2145 | NL80211_ATTR_WIPHY_BANDS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2146 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2147 | goto nla_put_failure; |
| 2148 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2149 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2150 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2151 | struct ieee80211_supported_band *sband; |
| 2152 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2153 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2154 | |
| 2155 | if (!sband) |
| 2156 | continue; |
| 2157 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2158 | nl_band = nla_nest_start_noflag(msg, band); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2159 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2160 | goto nla_put_failure; |
| 2161 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2162 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2163 | case 0: |
| 2164 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 2165 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2166 | state->chan_start++; |
| 2167 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2168 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2169 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2170 | default: |
| 2171 | /* add frequencies */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2172 | nl_freqs = nla_nest_start_noflag(msg, |
| 2173 | NL80211_BAND_ATTR_FREQS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2174 | if (!nl_freqs) |
| 2175 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2176 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2177 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2178 | i < sband->n_channels; |
| 2179 | i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2180 | nl_freq = nla_nest_start_noflag(msg, |
| 2181 | i); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2182 | if (!nl_freq) |
| 2183 | goto nla_put_failure; |
| 2184 | |
| 2185 | chan = &sband->channels[i]; |
| 2186 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2187 | if (nl80211_msg_put_channel( |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 2188 | msg, &rdev->wiphy, chan, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2189 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2190 | goto nla_put_failure; |
| 2191 | |
| 2192 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2193 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2194 | break; |
| 2195 | } |
| 2196 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2197 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2198 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2199 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2200 | nla_nest_end(msg, nl_freqs); |
| 2201 | } |
| 2202 | |
| 2203 | nla_nest_end(msg, nl_band); |
| 2204 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2205 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2206 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2207 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2208 | band--; |
| 2209 | break; |
| 2210 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2211 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2212 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2213 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2214 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2215 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2216 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2217 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2218 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2219 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2220 | if (state->band_start == 0 && state->chan_start == 0) |
| 2221 | state->split_start++; |
| 2222 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2223 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2224 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2225 | case 4: |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2226 | nl_cmds = nla_nest_start_noflag(msg, |
| 2227 | NL80211_ATTR_SUPPORTED_COMMANDS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2228 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2229 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2230 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 2231 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 2232 | if (i < 0) |
| 2233 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2234 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2235 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 2236 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2237 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 2238 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 2239 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 2240 | if (rdev->wiphy.features & |
| 2241 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 2242 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 2243 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 2244 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Matthew Wang | 7010998 | 2019-08-22 10:48:06 -0700 | [diff] [blame] | 2245 | CMD(update_ft_ies, UPDATE_FT_IES); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2246 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2247 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 2248 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2249 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2250 | state->split_start++; |
| 2251 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2252 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2253 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2254 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2255 | if (rdev->ops->remain_on_channel && |
| 2256 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2257 | nla_put_u32(msg, |
| 2258 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2259 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2260 | goto nla_put_failure; |
| 2261 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2262 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2263 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 2264 | goto nla_put_failure; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2265 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2266 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 2267 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2268 | state->split_start++; |
| 2269 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2270 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2271 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2272 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 2273 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2274 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2275 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2276 | state->split_start++; |
| 2277 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2278 | break; |
| 2279 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2280 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2281 | #endif |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2282 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2283 | case 7: |
| 2284 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2285 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2286 | goto nla_put_failure; |
| 2287 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2288 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2289 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2290 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2291 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2292 | state->split_start++; |
| 2293 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2294 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2295 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2296 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2297 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2298 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2299 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2300 | goto nla_put_failure; |
| 2301 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2302 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2303 | /* |
| 2304 | * We can only add the per-channel limit information if the |
| 2305 | * dump is split, otherwise it makes it too big. Therefore |
| 2306 | * only advertise it in that case. |
| 2307 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2308 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2309 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 2310 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2311 | goto nla_put_failure; |
| 2312 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2313 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2314 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2315 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 2316 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2317 | goto nla_put_failure; |
| 2318 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2319 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 2320 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2321 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2322 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2323 | goto nla_put_failure; |
| 2324 | |
| 2325 | /* |
| 2326 | * Any information below this point is only available to |
| 2327 | * applications that can deal with it being split. This |
| 2328 | * helps ensure that newly added capabilities don't break |
| 2329 | * older tools by overrunning their buffers. |
| 2330 | * |
| 2331 | * We still increment split_start so that in the split |
| 2332 | * case we'll continue with more data in the next round, |
| 2333 | * but break unconditionally so unsplit data stops here. |
| 2334 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2335 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2336 | break; |
| 2337 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2338 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2339 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2340 | rdev->wiphy.extended_capabilities_len, |
| 2341 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2342 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2343 | rdev->wiphy.extended_capabilities_len, |
| 2344 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2345 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2346 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2347 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2348 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2349 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 2350 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2351 | goto nla_put_failure; |
| 2352 | |
Denis Kenzior | ae6fa4d | 2019-07-22 06:33:12 -0500 | [diff] [blame] | 2353 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 2354 | rdev->wiphy.perm_addr)) |
| 2355 | goto nla_put_failure; |
| 2356 | |
| 2357 | if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && |
| 2358 | nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, |
| 2359 | rdev->wiphy.addr_mask)) |
| 2360 | goto nla_put_failure; |
| 2361 | |
| 2362 | if (rdev->wiphy.n_addresses > 1) { |
| 2363 | void *attr; |
| 2364 | |
| 2365 | attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); |
| 2366 | if (!attr) |
| 2367 | goto nla_put_failure; |
| 2368 | |
| 2369 | for (i = 0; i < rdev->wiphy.n_addresses; i++) |
| 2370 | if (nla_put(msg, i + 1, ETH_ALEN, |
| 2371 | rdev->wiphy.addresses[i].addr)) |
| 2372 | goto nla_put_failure; |
| 2373 | |
| 2374 | nla_nest_end(msg, attr); |
| 2375 | } |
| 2376 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2377 | state->split_start++; |
| 2378 | break; |
| 2379 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2380 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2381 | goto nla_put_failure; |
| 2382 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2383 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2384 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 2385 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 2386 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2387 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2388 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2389 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2390 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2391 | goto nla_put_failure; |
| 2392 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2393 | state->split_start++; |
| 2394 | break; |
| 2395 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2396 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2397 | const struct nl80211_vendor_cmd_info *info; |
| 2398 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2399 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2400 | nested = nla_nest_start_noflag(msg, |
| 2401 | NL80211_ATTR_VENDOR_DATA); |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2402 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2403 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2404 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2405 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 2406 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2407 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2408 | goto nla_put_failure; |
| 2409 | } |
| 2410 | nla_nest_end(msg, nested); |
| 2411 | } |
| 2412 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2413 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2414 | const struct nl80211_vendor_cmd_info *info; |
| 2415 | struct nlattr *nested; |
| 2416 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2417 | nested = nla_nest_start_noflag(msg, |
| 2418 | NL80211_ATTR_VENDOR_EVENTS); |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2419 | if (!nested) |
| 2420 | goto nla_put_failure; |
| 2421 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2422 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 2423 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2424 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2425 | goto nla_put_failure; |
| 2426 | } |
| 2427 | nla_nest_end(msg, nested); |
| 2428 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 2429 | state->split_start++; |
| 2430 | break; |
| 2431 | case 12: |
| 2432 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 2433 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 2434 | rdev->wiphy.max_num_csa_counters)) |
| 2435 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2436 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 2437 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 2438 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 2439 | goto nla_put_failure; |
| 2440 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 2441 | if (rdev->wiphy.max_sched_scan_reqs && |
| 2442 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, |
| 2443 | rdev->wiphy.max_sched_scan_reqs)) |
| 2444 | goto nla_put_failure; |
| 2445 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 2446 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 2447 | sizeof(rdev->wiphy.ext_features), |
| 2448 | rdev->wiphy.ext_features)) |
| 2449 | goto nla_put_failure; |
| 2450 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2451 | if (rdev->wiphy.bss_select_support) { |
| 2452 | struct nlattr *nested; |
| 2453 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 2454 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2455 | nested = nla_nest_start_noflag(msg, |
| 2456 | NL80211_ATTR_BSS_SELECT); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2457 | if (!nested) |
| 2458 | goto nla_put_failure; |
| 2459 | |
| 2460 | i = 0; |
| 2461 | while (bss_select_support) { |
| 2462 | if ((bss_select_support & 1) && |
| 2463 | nla_put_flag(msg, i)) |
| 2464 | goto nla_put_failure; |
| 2465 | i++; |
| 2466 | bss_select_support >>= 1; |
| 2467 | } |
| 2468 | nla_nest_end(msg, nested); |
| 2469 | } |
| 2470 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2471 | state->split_start++; |
| 2472 | break; |
| 2473 | case 13: |
| 2474 | if (rdev->wiphy.num_iftype_ext_capab && |
| 2475 | rdev->wiphy.iftype_ext_capab) { |
| 2476 | struct nlattr *nested_ext_capab, *nested; |
| 2477 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2478 | nested = nla_nest_start_noflag(msg, |
| 2479 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2480 | if (!nested) |
| 2481 | goto nla_put_failure; |
| 2482 | |
| 2483 | for (i = state->capa_start; |
| 2484 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 2485 | const struct wiphy_iftype_ext_capab *capab; |
| 2486 | |
| 2487 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 2488 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2489 | nested_ext_capab = nla_nest_start_noflag(msg, |
| 2490 | i); |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2491 | if (!nested_ext_capab || |
| 2492 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 2493 | capab->iftype) || |
| 2494 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 2495 | capab->extended_capabilities_len, |
| 2496 | capab->extended_capabilities) || |
| 2497 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 2498 | capab->extended_capabilities_len, |
| 2499 | capab->extended_capabilities_mask)) |
| 2500 | goto nla_put_failure; |
| 2501 | |
| 2502 | nla_nest_end(msg, nested_ext_capab); |
| 2503 | if (state->split) |
| 2504 | break; |
| 2505 | } |
| 2506 | nla_nest_end(msg, nested); |
| 2507 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 2508 | state->capa_start = i + 1; |
| 2509 | break; |
| 2510 | } |
| 2511 | } |
| 2512 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 2513 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 2514 | rdev->wiphy.nan_supported_bands)) |
| 2515 | goto nla_put_failure; |
| 2516 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2517 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 2518 | NL80211_EXT_FEATURE_TXQS)) { |
| 2519 | struct cfg80211_txq_stats txqstats = {}; |
| 2520 | int res; |
| 2521 | |
| 2522 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); |
| 2523 | if (!res && |
| 2524 | !nl80211_put_txq_stats(msg, &txqstats, |
| 2525 | NL80211_ATTR_TXQ_STATS)) |
| 2526 | goto nla_put_failure; |
| 2527 | |
| 2528 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, |
| 2529 | rdev->wiphy.txq_limit)) |
| 2530 | goto nla_put_failure; |
| 2531 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, |
| 2532 | rdev->wiphy.txq_memory_limit)) |
| 2533 | goto nla_put_failure; |
| 2534 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, |
| 2535 | rdev->wiphy.txq_quantum)) |
| 2536 | goto nla_put_failure; |
| 2537 | } |
| 2538 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2539 | state->split_start++; |
| 2540 | break; |
| 2541 | case 14: |
| 2542 | if (nl80211_send_pmsr_capa(rdev, msg)) |
| 2543 | goto nla_put_failure; |
| 2544 | |
Veerendranath Jakkam | ab4dfa2 | 2018-12-19 22:52:25 +0530 | [diff] [blame] | 2545 | state->split_start++; |
| 2546 | break; |
| 2547 | case 15: |
| 2548 | if (rdev->wiphy.akm_suites && |
| 2549 | nla_put(msg, NL80211_ATTR_AKM_SUITES, |
| 2550 | sizeof(u32) * rdev->wiphy.n_akm_suites, |
| 2551 | rdev->wiphy.akm_suites)) |
| 2552 | goto nla_put_failure; |
| 2553 | |
Veerendranath Jakkam | d6039a3 | 2020-01-27 02:00:32 +0530 | [diff] [blame] | 2554 | if (nl80211_put_iftype_akm_suites(rdev, msg)) |
| 2555 | goto nla_put_failure; |
| 2556 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 2557 | if (nl80211_put_tid_config_support(rdev, msg)) |
| 2558 | goto nla_put_failure; |
| 2559 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2560 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2561 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2562 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2563 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2564 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2565 | genlmsg_end(msg, hdr); |
| 2566 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2567 | |
| 2568 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2569 | genlmsg_cancel(msg, hdr); |
| 2570 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2571 | } |
| 2572 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2573 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 2574 | struct netlink_callback *cb, |
| 2575 | struct nl80211_dump_wiphy_state *state) |
| 2576 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2577 | struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
| 2578 | int ret; |
| 2579 | |
| 2580 | if (!tb) |
| 2581 | return -ENOMEM; |
| 2582 | |
| 2583 | ret = nlmsg_parse_deprecated(cb->nlh, |
| 2584 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 2585 | tb, nl80211_fam.maxattr, |
| 2586 | nl80211_policy, NULL); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2587 | /* ignore parse errors for backward compatibility */ |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2588 | if (ret) { |
| 2589 | ret = 0; |
| 2590 | goto out; |
| 2591 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2592 | |
| 2593 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 2594 | if (tb[NL80211_ATTR_WIPHY]) |
| 2595 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 2596 | if (tb[NL80211_ATTR_WDEV]) |
| 2597 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 2598 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 2599 | struct net_device *netdev; |
| 2600 | struct cfg80211_registered_device *rdev; |
| 2601 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 2602 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2603 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2604 | if (!netdev) { |
| 2605 | ret = -ENODEV; |
| 2606 | goto out; |
| 2607 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2608 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2609 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2610 | netdev->ieee80211_ptr->wiphy); |
| 2611 | state->filter_wiphy = rdev->wiphy_idx; |
| 2612 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2613 | } |
| 2614 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2615 | ret = 0; |
| 2616 | out: |
| 2617 | kfree(tb); |
| 2618 | return ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2619 | } |
| 2620 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2621 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 2622 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2623 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2624 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2625 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 2626 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2627 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2628 | if (!state) { |
| 2629 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 2630 | if (!state) { |
| 2631 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2632 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2633 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2634 | state->filter_wiphy = -1; |
| 2635 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 2636 | if (ret) { |
| 2637 | kfree(state); |
| 2638 | rtnl_unlock(); |
| 2639 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2640 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2641 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2642 | } |
| 2643 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2644 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2645 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2646 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2647 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2648 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2649 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2650 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2651 | continue; |
| 2652 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 2653 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2654 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 2655 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2656 | NETLINK_CB(cb->skb).portid, |
| 2657 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2658 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2659 | if (ret < 0) { |
| 2660 | /* |
| 2661 | * If sending the wiphy data didn't fit (ENOBUFS |
| 2662 | * or EMSGSIZE returned), this SKB is still |
| 2663 | * empty (so it's not too big because another |
| 2664 | * wiphy dataset is already in the skb) and |
| 2665 | * we've not tried to adjust the dump allocation |
| 2666 | * yet ... then adjust the alloc size to be |
| 2667 | * bigger, and return 1 but with the empty skb. |
| 2668 | * This results in an empty message being RX'ed |
| 2669 | * in userspace, but that is ignored. |
| 2670 | * |
| 2671 | * We can then retry with the larger buffer. |
| 2672 | */ |
| 2673 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2674 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2675 | cb->min_dump_alloc < 4096) { |
| 2676 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2677 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 2678 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2679 | return 1; |
| 2680 | } |
| 2681 | idx--; |
| 2682 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2683 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2684 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2685 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2686 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2687 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2688 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2689 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2690 | |
| 2691 | return skb->len; |
| 2692 | } |
| 2693 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2694 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2695 | { |
| 2696 | kfree((void *)cb->args[0]); |
| 2697 | return 0; |
| 2698 | } |
| 2699 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2700 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2701 | { |
| 2702 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2704 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2705 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2706 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2707 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2708 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2709 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2710 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2711 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2712 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2713 | nlmsg_free(msg); |
| 2714 | return -ENOBUFS; |
| 2715 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2716 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2717 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2718 | } |
| 2719 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2720 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2721 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2722 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2723 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2724 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2725 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2726 | }; |
| 2727 | |
| 2728 | static int parse_txq_params(struct nlattr *tb[], |
| 2729 | struct ieee80211_txq_params *txq_params) |
| 2730 | { |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2731 | u8 ac; |
| 2732 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2733 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2734 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2735 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2736 | return -EINVAL; |
| 2737 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2738 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2739 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2740 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2741 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2742 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2743 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2744 | if (ac >= NL80211_NUM_ACS) |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2745 | return -EINVAL; |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2746 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2747 | return 0; |
| 2748 | } |
| 2749 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2750 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2751 | { |
| 2752 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2753 | * You can only set the channel explicitly for WDS interfaces, |
| 2754 | * all others have their channel managed via their respective |
| 2755 | * "establish a connection" command (connect, join, ...) |
| 2756 | * |
| 2757 | * For AP/GO and mesh mode, the channel can be set with the |
| 2758 | * channel userspace API, but is only stored and passed to the |
| 2759 | * low-level driver when the AP starts or the mesh is joined. |
| 2760 | * This is for backward compatibility, userspace can also give |
| 2761 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2762 | * |
| 2763 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2764 | * whatever else is going on, so they have their own special |
| 2765 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2766 | */ |
| 2767 | return !wdev || |
| 2768 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2769 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2770 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2771 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2772 | } |
| 2773 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2774 | int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2775 | struct genl_info *info, |
| 2776 | struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2777 | { |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2778 | struct netlink_ext_ack *extack = info->extack; |
| 2779 | struct nlattr **attrs = info->attrs; |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2780 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2781 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2782 | if (!attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2783 | return -EINVAL; |
| 2784 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2785 | control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2786 | |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 2787 | memset(chandef, 0, sizeof(*chandef)); |
| 2788 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2789 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2790 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2791 | chandef->center_freq1 = control_freq; |
| 2792 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2793 | |
| 2794 | /* Primary channel not allowed */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2795 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { |
| 2796 | NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], |
| 2797 | "Channel is disabled"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2798 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2799 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2800 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2801 | if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2802 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2803 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2804 | chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2805 | |
| 2806 | switch (chantype) { |
| 2807 | case NL80211_CHAN_NO_HT: |
| 2808 | case NL80211_CHAN_HT20: |
| 2809 | case NL80211_CHAN_HT40PLUS: |
| 2810 | case NL80211_CHAN_HT40MINUS: |
| 2811 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2812 | chantype); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2813 | /* user input for center_freq is incorrect */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2814 | if (attrs[NL80211_ATTR_CENTER_FREQ1] && |
| 2815 | chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { |
| 2816 | NL_SET_ERR_MSG_ATTR(extack, |
| 2817 | attrs[NL80211_ATTR_CENTER_FREQ1], |
| 2818 | "bad center frequency 1"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2819 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2820 | } |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2821 | /* center_freq2 must be zero */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2822 | if (attrs[NL80211_ATTR_CENTER_FREQ2] && |
| 2823 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { |
| 2824 | NL_SET_ERR_MSG_ATTR(extack, |
| 2825 | attrs[NL80211_ATTR_CENTER_FREQ2], |
| 2826 | "center frequency 2 can't be used"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2827 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2828 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2829 | break; |
| 2830 | default: |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2831 | NL_SET_ERR_MSG_ATTR(extack, |
| 2832 | attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], |
| 2833 | "invalid channel type"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2834 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2835 | } |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2836 | } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2837 | chandef->width = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2838 | nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2839 | if (attrs[NL80211_ATTR_CENTER_FREQ1]) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2840 | chandef->center_freq1 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2841 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2842 | if (attrs[NL80211_ATTR_CENTER_FREQ2]) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2843 | chandef->center_freq2 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2844 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2845 | } |
| 2846 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 2847 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 2848 | chandef->edmg.channels = |
| 2849 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 2850 | |
| 2851 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 2852 | chandef->edmg.bw_config = |
| 2853 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 2854 | } else { |
| 2855 | chandef->edmg.bw_config = 0; |
| 2856 | chandef->edmg.channels = 0; |
| 2857 | } |
| 2858 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2859 | if (!cfg80211_chandef_valid(chandef)) { |
| 2860 | NL_SET_ERR_MSG(extack, "invalid channel definition"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2861 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2862 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2863 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2864 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2865 | IEEE80211_CHAN_DISABLED)) { |
| 2866 | NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2867 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2868 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2869 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2870 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2871 | chandef->width == NL80211_CHAN_WIDTH_10) && |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2872 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { |
| 2873 | NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2874 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2875 | } |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2876 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2877 | return 0; |
| 2878 | } |
| 2879 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2880 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2881 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2882 | struct genl_info *info) |
| 2883 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2884 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2885 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2886 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2887 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2888 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2889 | if (dev) |
| 2890 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2891 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2892 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2893 | if (wdev) |
| 2894 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2895 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2896 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2897 | if (result) |
| 2898 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2899 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2900 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2901 | case NL80211_IFTYPE_AP: |
| 2902 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2903 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2904 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2905 | result = -EINVAL; |
| 2906 | break; |
| 2907 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2908 | if (wdev->beacon_interval) { |
| 2909 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2910 | !(rdev->wiphy.features & |
| 2911 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2912 | result = -EBUSY; |
| 2913 | break; |
| 2914 | } |
| 2915 | |
| 2916 | /* Only allow dynamic channel width changes */ |
| 2917 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2918 | result = -EBUSY; |
| 2919 | break; |
| 2920 | } |
| 2921 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2922 | if (result) |
| 2923 | break; |
| 2924 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2925 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2926 | result = 0; |
| 2927 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2928 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2929 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2930 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2931 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2932 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2933 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2934 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2935 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2936 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2937 | |
| 2938 | return result; |
| 2939 | } |
| 2940 | |
| 2941 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2942 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2943 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2944 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2945 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2946 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2947 | } |
| 2948 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2949 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2950 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2952 | struct net_device *dev = info->user_ptr[1]; |
| 2953 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2954 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2955 | |
| 2956 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2957 | return -EINVAL; |
| 2958 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2959 | if (netif_running(dev)) |
| 2960 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2961 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2962 | if (!rdev->ops->set_wds_peer) |
| 2963 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2964 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2965 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2966 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2967 | |
| 2968 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2969 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2970 | } |
| 2971 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2972 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2973 | { |
| 2974 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2975 | struct net_device *netdev = NULL; |
| 2976 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2977 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2978 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2979 | u32 changed; |
| 2980 | u8 retry_short = 0, retry_long = 0; |
| 2981 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2982 | u8 coverage_class = 0; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2983 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2984 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2985 | ASSERT_RTNL(); |
| 2986 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2987 | /* |
| 2988 | * Try to find the wiphy and netdev. Normally this |
| 2989 | * function shouldn't need the netdev, but this is |
| 2990 | * done for backward compatibility -- previously |
| 2991 | * setting the channel was done per wiphy, but now |
| 2992 | * it is per netdev. Previous userland like hostapd |
| 2993 | * also passed a netdev to set_wiphy, so that it is |
| 2994 | * possible to let that go to the right netdev! |
| 2995 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2996 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2997 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2998 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2999 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3000 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3001 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 3002 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3003 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3004 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3005 | } |
| 3006 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3007 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 3008 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 3009 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3010 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3011 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3012 | wdev = NULL; |
| 3013 | netdev = NULL; |
| 3014 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 3015 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3016 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3017 | |
| 3018 | /* |
| 3019 | * end workaround code, by now the rdev is available |
| 3020 | * and locked, and wdev may or may not be NULL. |
| 3021 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3022 | |
| 3023 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3024 | result = cfg80211_dev_rename( |
| 3025 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3026 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3027 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3028 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3029 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3030 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 3031 | struct ieee80211_txq_params txq_params; |
| 3032 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 3033 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3034 | if (!rdev->ops->set_txq_params) |
| 3035 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3036 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3037 | if (!netdev) |
| 3038 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 3039 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 3040 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3041 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3042 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 3043 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3044 | if (!netif_running(netdev)) |
| 3045 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 3046 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3047 | nla_for_each_nested(nl_txq_params, |
| 3048 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 3049 | rem_txq_params) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 3050 | result = nla_parse_nested_deprecated(tb, |
| 3051 | NL80211_TXQ_ATTR_MAX, |
| 3052 | nl_txq_params, |
| 3053 | txq_params_policy, |
| 3054 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 3055 | if (result) |
| 3056 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3057 | result = parse_txq_params(tb, &txq_params); |
| 3058 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3059 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3060 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3061 | result = rdev_set_txq_params(rdev, netdev, |
| 3062 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3063 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3064 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3065 | } |
| 3066 | } |
| 3067 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3068 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3069 | result = __nl80211_set_channel( |
| 3070 | rdev, |
| 3071 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 3072 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3073 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3074 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3075 | } |
| 3076 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3077 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3078 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3079 | enum nl80211_tx_power_setting type; |
| 3080 | int idx, mbm = 0; |
| 3081 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3082 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 3083 | txp_wdev = NULL; |
| 3084 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3085 | if (!rdev->ops->set_tx_power) |
| 3086 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3087 | |
| 3088 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 3089 | type = nla_get_u32(info->attrs[idx]); |
| 3090 | |
| 3091 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3092 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 3093 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3094 | |
| 3095 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 3096 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 3097 | mbm = nla_get_u32(info->attrs[idx]); |
| 3098 | } |
| 3099 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3100 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3101 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3102 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3103 | } |
| 3104 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3105 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 3106 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 3107 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3108 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3109 | if ((!rdev->wiphy.available_antennas_tx && |
| 3110 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3111 | !rdev->ops->set_antenna) |
| 3112 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3113 | |
| 3114 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 3115 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 3116 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3117 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3118 | * available antenna masks, except for the "all" mask */ |
| 3119 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3120 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 3121 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3122 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3123 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 3124 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3125 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3126 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3127 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3128 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3129 | } |
| 3130 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3131 | changed = 0; |
| 3132 | |
| 3133 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 3134 | retry_short = nla_get_u8( |
| 3135 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3136 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3137 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 3138 | } |
| 3139 | |
| 3140 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 3141 | retry_long = nla_get_u8( |
| 3142 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3143 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3144 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 3145 | } |
| 3146 | |
| 3147 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 3148 | frag_threshold = nla_get_u32( |
| 3149 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3150 | if (frag_threshold < 256) |
| 3151 | return -EINVAL; |
| 3152 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3153 | if (frag_threshold != (u32) -1) { |
| 3154 | /* |
| 3155 | * Fragments (apart from the last one) are required to |
| 3156 | * have even length. Make the fragmentation code |
| 3157 | * simpler by stripping LSB should someone try to use |
| 3158 | * odd threshold value. |
| 3159 | */ |
| 3160 | frag_threshold &= ~0x1; |
| 3161 | } |
| 3162 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 3163 | } |
| 3164 | |
| 3165 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 3166 | rts_threshold = nla_get_u32( |
| 3167 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 3168 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 3169 | } |
| 3170 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3171 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3172 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 3173 | return -EINVAL; |
| 3174 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3175 | coverage_class = nla_get_u8( |
| 3176 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 3177 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 3178 | } |
| 3179 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3180 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 3181 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 3182 | return -EOPNOTSUPP; |
| 3183 | |
| 3184 | changed |= WIPHY_PARAM_DYN_ACK; |
| 3185 | } |
| 3186 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3187 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { |
| 3188 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3189 | NL80211_EXT_FEATURE_TXQS)) |
| 3190 | return -EOPNOTSUPP; |
| 3191 | txq_limit = nla_get_u32( |
| 3192 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); |
| 3193 | changed |= WIPHY_PARAM_TXQ_LIMIT; |
| 3194 | } |
| 3195 | |
| 3196 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { |
| 3197 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3198 | NL80211_EXT_FEATURE_TXQS)) |
| 3199 | return -EOPNOTSUPP; |
| 3200 | txq_memory_limit = nla_get_u32( |
| 3201 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); |
| 3202 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; |
| 3203 | } |
| 3204 | |
| 3205 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { |
| 3206 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3207 | NL80211_EXT_FEATURE_TXQS)) |
| 3208 | return -EOPNOTSUPP; |
| 3209 | txq_quantum = nla_get_u32( |
| 3210 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); |
| 3211 | changed |= WIPHY_PARAM_TXQ_QUANTUM; |
| 3212 | } |
| 3213 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3214 | if (changed) { |
| 3215 | u8 old_retry_short, old_retry_long; |
| 3216 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3217 | u8 old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3218 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3219 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3220 | if (!rdev->ops->set_wiphy_params) |
| 3221 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3222 | |
| 3223 | old_retry_short = rdev->wiphy.retry_short; |
| 3224 | old_retry_long = rdev->wiphy.retry_long; |
| 3225 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 3226 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3227 | old_coverage_class = rdev->wiphy.coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3228 | old_txq_limit = rdev->wiphy.txq_limit; |
| 3229 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; |
| 3230 | old_txq_quantum = rdev->wiphy.txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3231 | |
| 3232 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 3233 | rdev->wiphy.retry_short = retry_short; |
| 3234 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 3235 | rdev->wiphy.retry_long = retry_long; |
| 3236 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 3237 | rdev->wiphy.frag_threshold = frag_threshold; |
| 3238 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 3239 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3240 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 3241 | rdev->wiphy.coverage_class = coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3242 | if (changed & WIPHY_PARAM_TXQ_LIMIT) |
| 3243 | rdev->wiphy.txq_limit = txq_limit; |
| 3244 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) |
| 3245 | rdev->wiphy.txq_memory_limit = txq_memory_limit; |
| 3246 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) |
| 3247 | rdev->wiphy.txq_quantum = txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3248 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3249 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3250 | if (result) { |
| 3251 | rdev->wiphy.retry_short = old_retry_short; |
| 3252 | rdev->wiphy.retry_long = old_retry_long; |
| 3253 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 3254 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3255 | rdev->wiphy.coverage_class = old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3256 | rdev->wiphy.txq_limit = old_txq_limit; |
| 3257 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; |
| 3258 | rdev->wiphy.txq_quantum = old_txq_quantum; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 3259 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3260 | } |
| 3261 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3262 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3263 | } |
| 3264 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3265 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 3266 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3267 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 3268 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 3269 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3270 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3271 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 3272 | chandef->chan->center_freq)) |
| 3273 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3274 | switch (chandef->width) { |
| 3275 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3276 | case NL80211_CHAN_WIDTH_20: |
| 3277 | case NL80211_CHAN_WIDTH_40: |
| 3278 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 3279 | cfg80211_get_chandef_type(chandef))) |
| 3280 | return -ENOBUFS; |
| 3281 | break; |
| 3282 | default: |
| 3283 | break; |
| 3284 | } |
| 3285 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 3286 | return -ENOBUFS; |
| 3287 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 3288 | return -ENOBUFS; |
| 3289 | if (chandef->center_freq2 && |
| 3290 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3291 | return -ENOBUFS; |
| 3292 | return 0; |
| 3293 | } |
| 3294 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3295 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 3296 | struct cfg80211_registered_device *rdev, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3297 | struct wireless_dev *wdev, |
| 3298 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3299 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3300 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3301 | void *hdr; |
| 3302 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3303 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 3304 | cmd != NL80211_CMD_DEL_INTERFACE && |
| 3305 | cmd != NL80211_CMD_SET_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3306 | |
| 3307 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3308 | if (!hdr) |
| 3309 | return -1; |
| 3310 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3311 | if (dev && |
| 3312 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3313 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3314 | goto nla_put_failure; |
| 3315 | |
| 3316 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 3317 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 3318 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 3319 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3320 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3321 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 3322 | rdev->devlist_generation ^ |
Antonio Quartulli | 446faa1 | 2018-06-14 09:43:06 +0800 | [diff] [blame] | 3323 | (cfg80211_rdev_list_generation << 2)) || |
| 3324 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3325 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3326 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3327 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3328 | int ret; |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 3329 | struct cfg80211_chan_def chandef = {}; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3330 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3331 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 3332 | if (ret == 0) { |
| 3333 | if (nl80211_send_chandef(msg, &chandef)) |
| 3334 | goto nla_put_failure; |
| 3335 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 3336 | } |
| 3337 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 3338 | if (rdev->ops->get_tx_power) { |
| 3339 | int dbm, ret; |
| 3340 | |
| 3341 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 3342 | if (ret == 0 && |
| 3343 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 3344 | DBM_TO_MBM(dbm))) |
| 3345 | goto nla_put_failure; |
| 3346 | } |
| 3347 | |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3348 | wdev_lock(wdev); |
| 3349 | switch (wdev->iftype) { |
| 3350 | case NL80211_IFTYPE_AP: |
| 3351 | if (wdev->ssid_len && |
| 3352 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3353 | goto nla_put_failure_locked; |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3354 | break; |
| 3355 | case NL80211_IFTYPE_STATION: |
| 3356 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3357 | case NL80211_IFTYPE_ADHOC: { |
| 3358 | const u8 *ssid_ie; |
| 3359 | if (!wdev->current_bss) |
| 3360 | break; |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3361 | rcu_read_lock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3362 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 3363 | WLAN_EID_SSID); |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3364 | if (ssid_ie && |
| 3365 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) |
| 3366 | goto nla_put_failure_rcu_locked; |
| 3367 | rcu_read_unlock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3368 | break; |
| 3369 | } |
| 3370 | default: |
| 3371 | /* nothing */ |
| 3372 | break; |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3373 | } |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3374 | wdev_unlock(wdev); |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3375 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3376 | if (rdev->ops->get_txq_stats) { |
| 3377 | struct cfg80211_txq_stats txqstats = {}; |
| 3378 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); |
| 3379 | |
| 3380 | if (ret == 0 && |
| 3381 | !nl80211_put_txq_stats(msg, &txqstats, |
| 3382 | NL80211_ATTR_TXQ_STATS)) |
| 3383 | goto nla_put_failure; |
| 3384 | } |
| 3385 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3386 | genlmsg_end(msg, hdr); |
| 3387 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3388 | |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3389 | nla_put_failure_rcu_locked: |
| 3390 | rcu_read_unlock(); |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3391 | nla_put_failure_locked: |
| 3392 | wdev_unlock(wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3393 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3394 | genlmsg_cancel(msg, hdr); |
| 3395 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 3399 | { |
| 3400 | int wp_idx = 0; |
| 3401 | int if_idx = 0; |
| 3402 | int wp_start = cb->args[0]; |
| 3403 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3404 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3405 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3406 | struct wireless_dev *wdev; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3407 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3408 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3409 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3410 | if (!cb->args[2]) { |
| 3411 | struct nl80211_dump_wiphy_state state = { |
| 3412 | .filter_wiphy = -1, |
| 3413 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3414 | |
| 3415 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 3416 | if (ret) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3417 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3418 | |
| 3419 | filter_wiphy = state.filter_wiphy; |
| 3420 | |
| 3421 | /* |
| 3422 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 3423 | * value needed to determine that parsing is necessary. |
| 3424 | */ |
| 3425 | if (filter_wiphy >= 0) |
| 3426 | cb->args[2] = filter_wiphy + 1; |
| 3427 | else |
| 3428 | cb->args[2] = -1; |
| 3429 | } else if (cb->args[2] > 0) { |
| 3430 | filter_wiphy = cb->args[2] - 1; |
| 3431 | } |
| 3432 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3433 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 3434 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3435 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3436 | if (wp_idx < wp_start) { |
| 3437 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3438 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3439 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3440 | |
| 3441 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 3442 | continue; |
| 3443 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3444 | if_idx = 0; |
| 3445 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3446 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3447 | if (if_idx < if_start) { |
| 3448 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3449 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3450 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3451 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3452 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3453 | rdev, wdev, |
| 3454 | NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3455 | goto out; |
| 3456 | } |
| 3457 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3458 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3459 | |
| 3460 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3461 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3462 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3463 | cb->args[0] = wp_idx; |
| 3464 | cb->args[1] = if_idx; |
| 3465 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3466 | ret = skb->len; |
| 3467 | out_unlock: |
| 3468 | rtnl_unlock(); |
| 3469 | |
| 3470 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3471 | } |
| 3472 | |
| 3473 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 3474 | { |
| 3475 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3477 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3478 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3479 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3480 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3481 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3482 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3483 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3484 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3485 | nlmsg_free(msg); |
| 3486 | return -ENOBUFS; |
| 3487 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3488 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3489 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3490 | } |
| 3491 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3492 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 3493 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 3494 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 3495 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 3496 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 3497 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3498 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3499 | }; |
| 3500 | |
| 3501 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 3502 | { |
| 3503 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 3504 | int flag; |
| 3505 | |
| 3506 | *mntrflags = 0; |
| 3507 | |
| 3508 | if (!nla) |
| 3509 | return -EINVAL; |
| 3510 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 3511 | if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3512 | return -EINVAL; |
| 3513 | |
| 3514 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 3515 | if (flags[flag]) |
| 3516 | *mntrflags |= (1<<flag); |
| 3517 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3518 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 3519 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3520 | return 0; |
| 3521 | } |
| 3522 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3523 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 3524 | enum nl80211_iftype type, |
| 3525 | struct genl_info *info, |
| 3526 | struct vif_params *params) |
| 3527 | { |
| 3528 | bool change = false; |
| 3529 | int err; |
| 3530 | |
| 3531 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 3532 | if (type != NL80211_IFTYPE_MONITOR) |
| 3533 | return -EINVAL; |
| 3534 | |
| 3535 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 3536 | ¶ms->flags); |
| 3537 | if (err) |
| 3538 | return err; |
| 3539 | |
| 3540 | change = true; |
| 3541 | } |
| 3542 | |
| 3543 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 3544 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 3545 | return -EOPNOTSUPP; |
| 3546 | |
| 3547 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 3548 | const u8 *mumimo_groups; |
| 3549 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3550 | |
| 3551 | if (type != NL80211_IFTYPE_MONITOR) |
| 3552 | return -EINVAL; |
| 3553 | |
| 3554 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3555 | return -EOPNOTSUPP; |
| 3556 | |
| 3557 | mumimo_groups = |
| 3558 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 3559 | |
| 3560 | /* bits 0 and 63 are reserved and must be zero */ |
Johannes Berg | 4954601 | 2017-04-27 09:13:38 +0200 | [diff] [blame] | 3561 | if ((mumimo_groups[0] & BIT(0)) || |
| 3562 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3563 | return -EINVAL; |
| 3564 | |
| 3565 | params->vht_mumimo_groups = mumimo_groups; |
| 3566 | change = true; |
| 3567 | } |
| 3568 | |
| 3569 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 3570 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3571 | |
| 3572 | if (type != NL80211_IFTYPE_MONITOR) |
| 3573 | return -EINVAL; |
| 3574 | |
| 3575 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3576 | return -EOPNOTSUPP; |
| 3577 | |
| 3578 | params->vht_mumimo_follow_addr = |
| 3579 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 3580 | change = true; |
| 3581 | } |
| 3582 | |
| 3583 | return change ? 1 : 0; |
| 3584 | } |
| 3585 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3586 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3587 | struct net_device *netdev, u8 use_4addr, |
| 3588 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3589 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3590 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 3591 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3592 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3593 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3594 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3595 | |
| 3596 | switch (iftype) { |
| 3597 | case NL80211_IFTYPE_AP_VLAN: |
| 3598 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 3599 | return 0; |
| 3600 | break; |
| 3601 | case NL80211_IFTYPE_STATION: |
| 3602 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 3603 | return 0; |
| 3604 | break; |
| 3605 | default: |
| 3606 | break; |
| 3607 | } |
| 3608 | |
| 3609 | return -EOPNOTSUPP; |
| 3610 | } |
| 3611 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3612 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 3613 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3615 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 3616 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3617 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3618 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3619 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3620 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3621 | memset(¶ms, 0, sizeof(params)); |
| 3622 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3623 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3624 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3625 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3626 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3627 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3628 | change = true; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3629 | } |
| 3630 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 3631 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3632 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3633 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3634 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 3635 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3636 | if (netif_running(dev)) |
| 3637 | return -EBUSY; |
| 3638 | |
| 3639 | wdev_lock(wdev); |
| 3640 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3641 | IEEE80211_MAX_MESH_ID_LEN); |
| 3642 | wdev->mesh_id_up_len = |
| 3643 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3644 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3645 | wdev->mesh_id_up_len); |
| 3646 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3647 | } |
| 3648 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3649 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 3650 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 3651 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3652 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3653 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3654 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3655 | } else { |
| 3656 | params.use_4addr = -1; |
| 3657 | } |
| 3658 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3659 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 3660 | if (err < 0) |
| 3661 | return err; |
| 3662 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3663 | change = true; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3664 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3665 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3666 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3667 | else |
| 3668 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 3669 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3670 | if (!err && params.use_4addr != -1) |
| 3671 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 3672 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3673 | if (change && !err) { |
| 3674 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3675 | |
| 3676 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); |
| 3677 | } |
| 3678 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3679 | return err; |
| 3680 | } |
| 3681 | |
| 3682 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 3683 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3684 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3685 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3686 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 3687 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3688 | int err; |
| 3689 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 3690 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3691 | /* to avoid failing a new interface creation due to pending removal */ |
| 3692 | cfg80211_destroy_ifaces(rdev); |
| 3693 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3694 | memset(¶ms, 0, sizeof(params)); |
| 3695 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3696 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 3697 | return -EINVAL; |
| 3698 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 3699 | if (info->attrs[NL80211_ATTR_IFTYPE]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3700 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3701 | |
Manikanta Pubbisetty | 33d915d | 2019-05-08 14:55:33 +0530 | [diff] [blame] | 3702 | if (!rdev->ops->add_virtual_intf) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3703 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3704 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3705 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 3706 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 3707 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 3708 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 3709 | ETH_ALEN); |
| 3710 | if (!is_valid_ether_addr(params.macaddr)) |
| 3711 | return -EADDRNOTAVAIL; |
| 3712 | } |
| 3713 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3714 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3715 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3716 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3717 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3718 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3719 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3720 | |
Manikanta Pubbisetty | e6f4051 | 2019-07-22 12:44:50 +0530 | [diff] [blame] | 3721 | if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) |
Manikanta Pubbisetty | 33d915d | 2019-05-08 14:55:33 +0530 | [diff] [blame] | 3722 | return -EOPNOTSUPP; |
| 3723 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3724 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 3725 | if (err < 0) |
| 3726 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3727 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 3728 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 3729 | if (!msg) |
| 3730 | return -ENOMEM; |
| 3731 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3732 | wdev = rdev_add_virtual_intf(rdev, |
| 3733 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3734 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 3735 | if (WARN_ON(!wdev)) { |
| 3736 | nlmsg_free(msg); |
| 3737 | return -EPROTO; |
| 3738 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3739 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3740 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3741 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3742 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 3743 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3744 | wdev->owner_nlportid = info->snd_portid; |
| 3745 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3746 | switch (type) { |
| 3747 | case NL80211_IFTYPE_MESH_POINT: |
| 3748 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 3749 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3750 | wdev_lock(wdev); |
| 3751 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3752 | IEEE80211_MAX_MESH_ID_LEN); |
| 3753 | wdev->mesh_id_up_len = |
| 3754 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3755 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3756 | wdev->mesh_id_up_len); |
| 3757 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3758 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3759 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3760 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3761 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3762 | * P2P Device and NAN do not have a netdev, so don't go |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3763 | * through the netdev notifier and must be added here |
| 3764 | */ |
Johannes Berg | e4d4216 | 2018-09-13 14:12:03 +0200 | [diff] [blame] | 3765 | cfg80211_init_wdev(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3766 | break; |
| 3767 | default: |
| 3768 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3769 | } |
| 3770 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3771 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3772 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3773 | nlmsg_free(msg); |
| 3774 | return -ENOBUFS; |
| 3775 | } |
| 3776 | |
| 3777 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3781 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3782 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3783 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3784 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3785 | if (!rdev->ops->del_virtual_intf) |
| 3786 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3787 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3788 | /* |
| 3789 | * If we remove a wireless device without a netdev then clear |
| 3790 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3791 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3792 | * since the wdev has been freed, unlike with a netdev where |
| 3793 | * we need the dev_put() for the netdev to really be freed. |
| 3794 | */ |
| 3795 | if (!wdev->netdev) |
| 3796 | info->user_ptr[1] = NULL; |
| 3797 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 3798 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3799 | } |
| 3800 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3801 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3802 | { |
| 3803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3804 | struct net_device *dev = info->user_ptr[1]; |
| 3805 | u16 noack_map; |
| 3806 | |
| 3807 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3808 | return -EINVAL; |
| 3809 | |
| 3810 | if (!rdev->ops->set_noack_map) |
| 3811 | return -EOPNOTSUPP; |
| 3812 | |
| 3813 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3814 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3815 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3816 | } |
| 3817 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3818 | struct get_key_cookie { |
| 3819 | struct sk_buff *msg; |
| 3820 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3821 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3822 | }; |
| 3823 | |
| 3824 | static void get_key_callback(void *c, struct key_params *params) |
| 3825 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3826 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3827 | struct get_key_cookie *cookie = c; |
| 3828 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3829 | if ((params->key && |
| 3830 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3831 | params->key_len, params->key)) || |
| 3832 | (params->seq && |
| 3833 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3834 | params->seq_len, params->seq)) || |
| 3835 | (params->cipher && |
| 3836 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3837 | params->cipher))) |
| 3838 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3839 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 3840 | key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3841 | if (!key) |
| 3842 | goto nla_put_failure; |
| 3843 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3844 | if ((params->key && |
| 3845 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3846 | params->key_len, params->key)) || |
| 3847 | (params->seq && |
| 3848 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3849 | params->seq_len, params->seq)) || |
| 3850 | (params->cipher && |
| 3851 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3852 | params->cipher))) |
| 3853 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3854 | |
Andrew Zaborowski | efdfce7 | 2018-09-24 18:10:22 +0200 | [diff] [blame] | 3855 | if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3856 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3857 | |
| 3858 | nla_nest_end(cookie->msg, key); |
| 3859 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3860 | return; |
| 3861 | nla_put_failure: |
| 3862 | cookie->error = 1; |
| 3863 | } |
| 3864 | |
| 3865 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3866 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3868 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3869 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3870 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3871 | const u8 *mac_addr = NULL; |
| 3872 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3873 | struct get_key_cookie cookie = { |
| 3874 | .error = 0, |
| 3875 | }; |
| 3876 | void *hdr; |
| 3877 | struct sk_buff *msg; |
| 3878 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 3879 | if (info->attrs[NL80211_ATTR_KEY_IDX]) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3880 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 3881 | if (key_idx > 5 && |
| 3882 | !wiphy_ext_feature_isset( |
| 3883 | &rdev->wiphy, |
| 3884 | NL80211_EXT_FEATURE_BEACON_PROTECTION)) |
| 3885 | return -EINVAL; |
| 3886 | } |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3887 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3888 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3889 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3890 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3891 | pairwise = !!mac_addr; |
| 3892 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3893 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3894 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3895 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3896 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3897 | return -EINVAL; |
| 3898 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3899 | } |
| 3900 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3901 | if (!rdev->ops->get_key) |
| 3902 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3903 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3904 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3905 | return -ENOENT; |
| 3906 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3907 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3908 | if (!msg) |
| 3909 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3910 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3911 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3912 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3913 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3914 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3915 | |
| 3916 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3917 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3918 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3919 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3920 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3921 | goto nla_put_failure; |
| 3922 | if (mac_addr && |
| 3923 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3924 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3925 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3926 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3927 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3928 | |
| 3929 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3930 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3931 | |
| 3932 | if (cookie.error) |
| 3933 | goto nla_put_failure; |
| 3934 | |
| 3935 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3936 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3937 | |
| 3938 | nla_put_failure: |
| 3939 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3940 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3941 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3942 | return err; |
| 3943 | } |
| 3944 | |
| 3945 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3946 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3947 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3948 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3949 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3950 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3951 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3952 | err = nl80211_parse_key(info, &key); |
| 3953 | if (err) |
| 3954 | return err; |
| 3955 | |
| 3956 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3957 | return -EINVAL; |
| 3958 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 3959 | /* Only support setting default key and |
| 3960 | * Extended Key ID action NL80211_KEY_SET_TX. |
| 3961 | */ |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 3962 | if (!key.def && !key.defmgmt && !key.defbeacon && |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 3963 | !(key.p.mode == NL80211_KEY_SET_TX)) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3964 | return -EINVAL; |
| 3965 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3966 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3967 | |
| 3968 | if (key.def) { |
| 3969 | if (!rdev->ops->set_default_key) { |
| 3970 | err = -EOPNOTSUPP; |
| 3971 | goto out; |
| 3972 | } |
| 3973 | |
| 3974 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3975 | if (err) |
| 3976 | goto out; |
| 3977 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3978 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3979 | key.def_uni, key.def_multi); |
| 3980 | |
| 3981 | if (err) |
| 3982 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3983 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3984 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3985 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3986 | #endif |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 3987 | } else if (key.defmgmt) { |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3988 | if (key.def_uni || !key.def_multi) { |
| 3989 | err = -EINVAL; |
| 3990 | goto out; |
| 3991 | } |
| 3992 | |
| 3993 | if (!rdev->ops->set_default_mgmt_key) { |
| 3994 | err = -EOPNOTSUPP; |
| 3995 | goto out; |
| 3996 | } |
| 3997 | |
| 3998 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3999 | if (err) |
| 4000 | goto out; |
| 4001 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4002 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4003 | if (err) |
| 4004 | goto out; |
| 4005 | |
| 4006 | #ifdef CONFIG_CFG80211_WEXT |
| 4007 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 4008 | #endif |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4009 | } else if (key.defbeacon) { |
| 4010 | if (key.def_uni || !key.def_multi) { |
| 4011 | err = -EINVAL; |
| 4012 | goto out; |
| 4013 | } |
| 4014 | |
| 4015 | if (!rdev->ops->set_default_beacon_key) { |
| 4016 | err = -EOPNOTSUPP; |
| 4017 | goto out; |
| 4018 | } |
| 4019 | |
| 4020 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4021 | if (err) |
| 4022 | goto out; |
| 4023 | |
| 4024 | err = rdev_set_default_beacon_key(rdev, dev, key.idx); |
| 4025 | if (err) |
| 4026 | goto out; |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4027 | } else if (key.p.mode == NL80211_KEY_SET_TX && |
| 4028 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4029 | NL80211_EXT_FEATURE_EXT_KEY_ID)) { |
| 4030 | u8 *mac_addr = NULL; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4031 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4032 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4033 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4034 | |
| 4035 | if (!mac_addr || key.idx < 0 || key.idx > 1) { |
| 4036 | err = -EINVAL; |
| 4037 | goto out; |
| 4038 | } |
| 4039 | |
| 4040 | err = rdev_add_key(rdev, dev, key.idx, |
| 4041 | NL80211_KEYTYPE_PAIRWISE, |
| 4042 | mac_addr, &key.p); |
| 4043 | } else { |
| 4044 | err = -EINVAL; |
| 4045 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4046 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4047 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4048 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4049 | return err; |
| 4050 | } |
| 4051 | |
| 4052 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 4053 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4054 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4055 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4056 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4057 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4058 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4059 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4060 | err = nl80211_parse_key(info, &key); |
| 4061 | if (err) |
| 4062 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4063 | |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4064 | if (!key.p.key) { |
| 4065 | GENL_SET_ERR_MSG(info, "no key"); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4066 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4067 | } |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4068 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4069 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4070 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4071 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4072 | if (key.type == -1) { |
| 4073 | if (mac_addr) |
| 4074 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4075 | else |
| 4076 | key.type = NL80211_KEYTYPE_GROUP; |
| 4077 | } |
| 4078 | |
| 4079 | /* for now */ |
| 4080 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4081 | key.type != NL80211_KEYTYPE_GROUP) { |
| 4082 | GENL_SET_ERR_MSG(info, "key type not pairwise or group"); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4083 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4084 | } |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4085 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 4086 | if (key.type == NL80211_KEYTYPE_GROUP && |
| 4087 | info->attrs[NL80211_ATTR_VLAN_ID]) |
| 4088 | key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 4089 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4090 | if (!rdev->ops->add_key) |
| 4091 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4092 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4093 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 4094 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4095 | mac_addr)) { |
| 4096 | GENL_SET_ERR_MSG(info, "key setting validation failed"); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4097 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4098 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4099 | |
| 4100 | wdev_lock(dev->ieee80211_ptr); |
| 4101 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4102 | if (err) |
| 4103 | GENL_SET_ERR_MSG(info, "key not allowed"); |
| 4104 | if (!err) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4105 | err = rdev_add_key(rdev, dev, key.idx, |
| 4106 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4107 | mac_addr, &key.p); |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4108 | if (err) |
| 4109 | GENL_SET_ERR_MSG(info, "key addition failed"); |
| 4110 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4111 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4112 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4113 | return err; |
| 4114 | } |
| 4115 | |
| 4116 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 4117 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4118 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4119 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4120 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4121 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4122 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4123 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4124 | err = nl80211_parse_key(info, &key); |
| 4125 | if (err) |
| 4126 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4127 | |
| 4128 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4129 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4130 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4131 | if (key.type == -1) { |
| 4132 | if (mac_addr) |
| 4133 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4134 | else |
| 4135 | key.type = NL80211_KEYTYPE_GROUP; |
| 4136 | } |
| 4137 | |
| 4138 | /* for now */ |
| 4139 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 4140 | key.type != NL80211_KEYTYPE_GROUP) |
| 4141 | return -EINVAL; |
| 4142 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4143 | if (!rdev->ops->del_key) |
| 4144 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4145 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4146 | wdev_lock(dev->ieee80211_ptr); |
| 4147 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4148 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 4149 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4150 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 4151 | err = -ENOENT; |
| 4152 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4153 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4154 | err = rdev_del_key(rdev, dev, key.idx, |
| 4155 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4156 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4157 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 4158 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4159 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4160 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4161 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4162 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4163 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 4164 | } |
| 4165 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4166 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4167 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4168 | return err; |
| 4169 | } |
| 4170 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4171 | /* This function returns an error or the number of nested attributes */ |
| 4172 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 4173 | { |
| 4174 | struct nlattr *attr; |
| 4175 | int n_entries = 0, tmp; |
| 4176 | |
| 4177 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 4178 | if (nla_len(attr) != ETH_ALEN) |
| 4179 | return -EINVAL; |
| 4180 | |
| 4181 | n_entries++; |
| 4182 | } |
| 4183 | |
| 4184 | return n_entries; |
| 4185 | } |
| 4186 | |
| 4187 | /* |
| 4188 | * This function parses ACL information and allocates memory for ACL data. |
| 4189 | * On successful return, the calling function is responsible to free the |
| 4190 | * ACL buffer returned by this function. |
| 4191 | */ |
| 4192 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 4193 | struct genl_info *info) |
| 4194 | { |
| 4195 | enum nl80211_acl_policy acl_policy; |
| 4196 | struct nlattr *attr; |
| 4197 | struct cfg80211_acl_data *acl; |
| 4198 | int i = 0, n_entries, tmp; |
| 4199 | |
| 4200 | if (!wiphy->max_acl_mac_addrs) |
| 4201 | return ERR_PTR(-EOPNOTSUPP); |
| 4202 | |
| 4203 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 4204 | return ERR_PTR(-EINVAL); |
| 4205 | |
| 4206 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 4207 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 4208 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 4209 | return ERR_PTR(-EINVAL); |
| 4210 | |
| 4211 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 4212 | return ERR_PTR(-EINVAL); |
| 4213 | |
| 4214 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 4215 | if (n_entries < 0) |
| 4216 | return ERR_PTR(n_entries); |
| 4217 | |
| 4218 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 4219 | return ERR_PTR(-ENOTSUPP); |
| 4220 | |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 4221 | acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4222 | if (!acl) |
| 4223 | return ERR_PTR(-ENOMEM); |
| 4224 | |
| 4225 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 4226 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 4227 | i++; |
| 4228 | } |
| 4229 | |
| 4230 | acl->n_acl_entries = n_entries; |
| 4231 | acl->acl_policy = acl_policy; |
| 4232 | |
| 4233 | return acl; |
| 4234 | } |
| 4235 | |
| 4236 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 4237 | { |
| 4238 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4239 | struct net_device *dev = info->user_ptr[1]; |
| 4240 | struct cfg80211_acl_data *acl; |
| 4241 | int err; |
| 4242 | |
| 4243 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4244 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4245 | return -EOPNOTSUPP; |
| 4246 | |
| 4247 | if (!dev->ieee80211_ptr->beacon_interval) |
| 4248 | return -EINVAL; |
| 4249 | |
| 4250 | acl = parse_acl_data(&rdev->wiphy, info); |
| 4251 | if (IS_ERR(acl)) |
| 4252 | return PTR_ERR(acl); |
| 4253 | |
| 4254 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 4255 | |
| 4256 | kfree(acl); |
| 4257 | |
| 4258 | return err; |
| 4259 | } |
| 4260 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4261 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4262 | u8 *rates, u8 rates_len) |
| 4263 | { |
| 4264 | u8 i; |
| 4265 | u32 mask = 0; |
| 4266 | |
| 4267 | for (i = 0; i < rates_len; i++) { |
| 4268 | int rate = (rates[i] & 0x7f) * 5; |
| 4269 | int ridx; |
| 4270 | |
| 4271 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4272 | struct ieee80211_rate *srate = |
| 4273 | &sband->bitrates[ridx]; |
| 4274 | if (rate == srate->bitrate) { |
| 4275 | mask |= 1 << ridx; |
| 4276 | break; |
| 4277 | } |
| 4278 | } |
| 4279 | if (ridx == sband->n_bitrates) |
| 4280 | return 0; /* rate not found */ |
| 4281 | } |
| 4282 | |
| 4283 | return mask; |
| 4284 | } |
| 4285 | |
| 4286 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4287 | u8 *rates, u8 rates_len, |
| 4288 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 4289 | { |
| 4290 | u8 i; |
| 4291 | |
| 4292 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 4293 | |
| 4294 | for (i = 0; i < rates_len; i++) { |
| 4295 | int ridx, rbit; |
| 4296 | |
| 4297 | ridx = rates[i] / 8; |
| 4298 | rbit = BIT(rates[i] % 8); |
| 4299 | |
| 4300 | /* check validity */ |
| 4301 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 4302 | return false; |
| 4303 | |
| 4304 | /* check availability */ |
Masashi Honma | 30fe6d5 | 2018-09-25 11:15:00 +0900 | [diff] [blame] | 4305 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4306 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 4307 | mcs[ridx] |= rbit; |
| 4308 | else |
| 4309 | return false; |
| 4310 | } |
| 4311 | |
| 4312 | return true; |
| 4313 | } |
| 4314 | |
| 4315 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 4316 | { |
| 4317 | u16 mcs_mask = 0; |
| 4318 | |
| 4319 | switch (vht_mcs_map) { |
| 4320 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 4321 | break; |
| 4322 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 4323 | mcs_mask = 0x00FF; |
| 4324 | break; |
| 4325 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 4326 | mcs_mask = 0x01FF; |
| 4327 | break; |
| 4328 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 4329 | mcs_mask = 0x03FF; |
| 4330 | break; |
| 4331 | default: |
| 4332 | break; |
| 4333 | } |
| 4334 | |
| 4335 | return mcs_mask; |
| 4336 | } |
| 4337 | |
| 4338 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 4339 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 4340 | { |
| 4341 | u8 nss; |
| 4342 | |
| 4343 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 4344 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 4345 | vht_mcs_map >>= 2; |
| 4346 | } |
| 4347 | } |
| 4348 | |
| 4349 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 4350 | struct nl80211_txrate_vht *txrate, |
| 4351 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 4352 | { |
| 4353 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4354 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 4355 | u8 i; |
| 4356 | |
| 4357 | if (!sband->vht_cap.vht_supported) |
| 4358 | return false; |
| 4359 | |
| 4360 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 4361 | |
| 4362 | /* Build vht_mcs_mask from VHT capabilities */ |
| 4363 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4364 | |
| 4365 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 4366 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4367 | mcs[i] = txrate->mcs[i]; |
| 4368 | else |
| 4369 | return false; |
| 4370 | } |
| 4371 | |
| 4372 | return true; |
| 4373 | } |
| 4374 | |
| 4375 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 4376 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4377 | .len = NL80211_MAX_SUPP_RATES }, |
| 4378 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 4379 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Johannes Berg | 180aa42 | 2019-05-28 14:19:07 +0200 | [diff] [blame] | 4380 | [NL80211_TXRATE_VHT] = { |
| 4381 | .type = NLA_EXACT_LEN_WARN, |
| 4382 | .len = sizeof(struct nl80211_txrate_vht), |
| 4383 | }, |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4384 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 4385 | }; |
| 4386 | |
| 4387 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| 4388 | struct cfg80211_bitrate_mask *mask) |
| 4389 | { |
| 4390 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 4391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4392 | int rem, i; |
| 4393 | struct nlattr *tx_rates; |
| 4394 | struct ieee80211_supported_band *sband; |
| 4395 | u16 vht_tx_mcs_map; |
| 4396 | |
| 4397 | memset(mask, 0, sizeof(*mask)); |
| 4398 | /* Default to all rates enabled */ |
| 4399 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 4400 | sband = rdev->wiphy.bands[i]; |
| 4401 | |
| 4402 | if (!sband) |
| 4403 | continue; |
| 4404 | |
| 4405 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 4406 | memcpy(mask->control[i].ht_mcs, |
| 4407 | sband->ht_cap.mcs.rx_mask, |
| 4408 | sizeof(mask->control[i].ht_mcs)); |
| 4409 | |
| 4410 | if (!sband->vht_cap.vht_supported) |
| 4411 | continue; |
| 4412 | |
| 4413 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4414 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 4415 | } |
| 4416 | |
| 4417 | /* if no rates are given set it back to the defaults */ |
| 4418 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 4419 | goto out; |
| 4420 | |
| 4421 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 4422 | * directly to the enum nl80211_band values used in cfg80211. |
| 4423 | */ |
| 4424 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| 4425 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
| 4426 | enum nl80211_band band = nla_type(tx_rates); |
| 4427 | int err; |
| 4428 | |
| 4429 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 4430 | return -EINVAL; |
| 4431 | sband = rdev->wiphy.bands[band]; |
| 4432 | if (sband == NULL) |
| 4433 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 4434 | err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, |
| 4435 | tx_rates, |
| 4436 | nl80211_txattr_policy, |
| 4437 | info->extack); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4438 | if (err) |
| 4439 | return err; |
| 4440 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4441 | mask->control[band].legacy = rateset_to_mask( |
| 4442 | sband, |
| 4443 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4444 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 4445 | if ((mask->control[band].legacy == 0) && |
| 4446 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 4447 | return -EINVAL; |
| 4448 | } |
| 4449 | if (tb[NL80211_TXRATE_HT]) { |
| 4450 | if (!ht_rateset_to_mask( |
| 4451 | sband, |
| 4452 | nla_data(tb[NL80211_TXRATE_HT]), |
| 4453 | nla_len(tb[NL80211_TXRATE_HT]), |
| 4454 | mask->control[band].ht_mcs)) |
| 4455 | return -EINVAL; |
| 4456 | } |
| 4457 | if (tb[NL80211_TXRATE_VHT]) { |
| 4458 | if (!vht_set_mcs_mask( |
| 4459 | sband, |
| 4460 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 4461 | mask->control[band].vht_mcs)) |
| 4462 | return -EINVAL; |
| 4463 | } |
| 4464 | if (tb[NL80211_TXRATE_GI]) { |
| 4465 | mask->control[band].gi = |
| 4466 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 4467 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 4468 | return -EINVAL; |
| 4469 | } |
| 4470 | |
| 4471 | if (mask->control[band].legacy == 0) { |
| 4472 | /* don't allow empty legacy rates if HT or VHT |
| 4473 | * are not even supported. |
| 4474 | */ |
| 4475 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 4476 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 4477 | return -EINVAL; |
| 4478 | |
| 4479 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 4480 | if (mask->control[band].ht_mcs[i]) |
| 4481 | goto out; |
| 4482 | |
| 4483 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 4484 | if (mask->control[band].vht_mcs[i]) |
| 4485 | goto out; |
| 4486 | |
| 4487 | /* legacy and mcs rates may not be both empty */ |
| 4488 | return -EINVAL; |
| 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | out: |
| 4493 | return 0; |
| 4494 | } |
| 4495 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4496 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 4497 | enum nl80211_band band, |
| 4498 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4499 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4500 | u32 count_ht, count_vht, i; |
| 4501 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4502 | |
| 4503 | /* Allow only one rate */ |
| 4504 | if (hweight32(rate) > 1) |
| 4505 | return -EINVAL; |
| 4506 | |
| 4507 | count_ht = 0; |
| 4508 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4509 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4510 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4511 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4512 | count_ht++; |
| 4513 | if (count_ht > 1) |
| 4514 | return -EINVAL; |
| 4515 | } |
| 4516 | if (count_ht && rate) |
| 4517 | return -EINVAL; |
| 4518 | } |
| 4519 | |
| 4520 | count_vht = 0; |
| 4521 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4522 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4523 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4524 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4525 | count_vht++; |
| 4526 | if (count_vht > 1) |
| 4527 | return -EINVAL; |
| 4528 | } |
| 4529 | if (count_vht && rate) |
| 4530 | return -EINVAL; |
| 4531 | } |
| 4532 | |
| 4533 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 4534 | return -EINVAL; |
| 4535 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4536 | if (rate && |
| 4537 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4538 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 4539 | return -EINVAL; |
| 4540 | if (count_ht && |
| 4541 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4542 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 4543 | return -EINVAL; |
| 4544 | if (count_vht && |
| 4545 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4546 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 4547 | return -EINVAL; |
| 4548 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4549 | return 0; |
| 4550 | } |
| 4551 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4552 | static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, |
| 4553 | struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4554 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4555 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4556 | bool haveinfo = false; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4557 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4558 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4559 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4560 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4561 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 4562 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 4563 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4564 | if (!bcn->head_len) |
| 4565 | return -EINVAL; |
| 4566 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4567 | } |
| 4568 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4569 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 4570 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 4571 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4572 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4573 | } |
| 4574 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4575 | if (!haveinfo) |
| 4576 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4577 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4578 | if (attrs[NL80211_ATTR_IE]) { |
| 4579 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 4580 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4581 | } |
| 4582 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4583 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4584 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4585 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4586 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4587 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4588 | } |
| 4589 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4590 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4591 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4592 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4593 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4594 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4595 | } |
| 4596 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4597 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 4598 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 4599 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 4600 | } |
| 4601 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4602 | if (attrs[NL80211_ATTR_FTM_RESPONDER]) { |
| 4603 | struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; |
| 4604 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 4605 | err = nla_parse_nested_deprecated(tb, |
| 4606 | NL80211_FTM_RESP_ATTR_MAX, |
| 4607 | attrs[NL80211_ATTR_FTM_RESPONDER], |
| 4608 | NULL, NULL); |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4609 | if (err) |
| 4610 | return err; |
| 4611 | |
| 4612 | if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && |
| 4613 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4614 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) |
| 4615 | bcn->ftm_responder = 1; |
| 4616 | else |
| 4617 | return -EOPNOTSUPP; |
| 4618 | |
| 4619 | if (tb[NL80211_FTM_RESP_ATTR_LCI]) { |
| 4620 | bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4621 | bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4622 | } |
| 4623 | |
| 4624 | if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { |
| 4625 | bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4626 | bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4627 | } |
| 4628 | } else { |
| 4629 | bcn->ftm_responder = -1; |
| 4630 | } |
| 4631 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4632 | return 0; |
| 4633 | } |
| 4634 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 4635 | static int nl80211_parse_he_obss_pd(struct nlattr *attrs, |
| 4636 | struct ieee80211_he_obss_pd *he_obss_pd) |
| 4637 | { |
| 4638 | struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; |
| 4639 | int err; |
| 4640 | |
| 4641 | err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, |
| 4642 | he_obss_pd_policy, NULL); |
| 4643 | if (err) |
| 4644 | return err; |
| 4645 | |
| 4646 | if (!tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] || |
| 4647 | !tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) |
| 4648 | return -EINVAL; |
| 4649 | |
| 4650 | he_obss_pd->min_offset = |
| 4651 | nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); |
| 4652 | he_obss_pd->max_offset = |
| 4653 | nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); |
| 4654 | |
| 4655 | if (he_obss_pd->min_offset >= he_obss_pd->max_offset) |
| 4656 | return -EINVAL; |
| 4657 | |
| 4658 | he_obss_pd->enable = true; |
| 4659 | |
| 4660 | return 0; |
| 4661 | } |
| 4662 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 4663 | static int nl80211_parse_he_bss_color(struct nlattr *attrs, |
| 4664 | struct cfg80211_he_bss_color *he_bss_color) |
| 4665 | { |
| 4666 | struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; |
| 4667 | int err; |
| 4668 | |
| 4669 | err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, |
| 4670 | he_bss_color_policy, NULL); |
| 4671 | if (err) |
| 4672 | return err; |
| 4673 | |
| 4674 | if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) |
| 4675 | return -EINVAL; |
| 4676 | |
| 4677 | he_bss_color->color = |
| 4678 | nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); |
| 4679 | he_bss_color->disabled = |
| 4680 | nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); |
| 4681 | he_bss_color->partial = |
| 4682 | nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); |
| 4683 | |
| 4684 | return 0; |
| 4685 | } |
| 4686 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4687 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 4688 | const u8 *rates) |
| 4689 | { |
| 4690 | int i; |
| 4691 | |
| 4692 | if (!rates) |
| 4693 | return; |
| 4694 | |
| 4695 | for (i = 0; i < rates[1]; i++) { |
| 4696 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 4697 | params->ht_required = true; |
| 4698 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 4699 | params->vht_required = true; |
| 4700 | } |
| 4701 | } |
| 4702 | |
| 4703 | /* |
| 4704 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 4705 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 4706 | * benefit of drivers that rebuild IEs in the firmware. |
| 4707 | */ |
| 4708 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 4709 | { |
| 4710 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
Igor Mitsyanko | ba83bfb | 2017-08-30 13:52:25 -0700 | [diff] [blame] | 4711 | size_t ies_len = bcn->tail_len; |
| 4712 | const u8 *ies = bcn->tail; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4713 | const u8 *rates; |
| 4714 | const u8 *cap; |
| 4715 | |
| 4716 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 4717 | nl80211_check_ap_rate_selectors(params, rates); |
| 4718 | |
| 4719 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 4720 | nl80211_check_ap_rate_selectors(params, rates); |
| 4721 | |
| 4722 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 4723 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 4724 | params->ht_cap = (void *)(cap + 2); |
| 4725 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 4726 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 4727 | params->vht_cap = (void *)(cap + 2); |
Shaul Triebitz | 244eb9a | 2018-08-31 11:31:14 +0300 | [diff] [blame] | 4728 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); |
| 4729 | if (cap && cap[1] >= sizeof(*params->he_cap) + 1) |
| 4730 | params->he_cap = (void *)(cap + 3); |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4731 | } |
| 4732 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4733 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 4734 | struct cfg80211_ap_settings *params) |
| 4735 | { |
| 4736 | struct wireless_dev *wdev; |
| 4737 | bool ret = false; |
| 4738 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 4739 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4740 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 4741 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 4742 | continue; |
| 4743 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4744 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4745 | continue; |
| 4746 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4747 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4748 | ret = true; |
| 4749 | break; |
| 4750 | } |
| 4751 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4752 | return ret; |
| 4753 | } |
| 4754 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4755 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 4756 | enum nl80211_auth_type auth_type, |
| 4757 | enum nl80211_commands cmd) |
| 4758 | { |
| 4759 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 4760 | return false; |
| 4761 | |
| 4762 | switch (cmd) { |
| 4763 | case NL80211_CMD_AUTHENTICATE: |
| 4764 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 4765 | auth_type == NL80211_AUTHTYPE_SAE) |
| 4766 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 4767 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 4768 | NL80211_EXT_FEATURE_FILS_STA) && |
| 4769 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 4770 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4771 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 4772 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4773 | return true; |
| 4774 | case NL80211_CMD_CONNECT: |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 4775 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 4776 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4777 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 4778 | auth_type == NL80211_AUTHTYPE_SAE) |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 4779 | return false; |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 4780 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 4781 | /* FILS with SK PFS or PK not supported yet */ |
| 4782 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4783 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 4784 | return false; |
| 4785 | if (!wiphy_ext_feature_isset( |
| 4786 | &rdev->wiphy, |
| 4787 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 4788 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 4789 | return false; |
| 4790 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4791 | case NL80211_CMD_START_AP: |
| 4792 | /* SAE not supported yet */ |
| 4793 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 4794 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 4795 | /* FILS not supported yet */ |
| 4796 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 4797 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4798 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 4799 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4800 | return true; |
| 4801 | default: |
| 4802 | return false; |
| 4803 | } |
| 4804 | } |
| 4805 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4806 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 4807 | { |
| 4808 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4809 | struct net_device *dev = info->user_ptr[1]; |
| 4810 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4811 | struct cfg80211_ap_settings params; |
| 4812 | int err; |
| 4813 | |
| 4814 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4815 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4816 | return -EOPNOTSUPP; |
| 4817 | |
| 4818 | if (!rdev->ops->start_ap) |
| 4819 | return -EOPNOTSUPP; |
| 4820 | |
| 4821 | if (wdev->beacon_interval) |
| 4822 | return -EALREADY; |
| 4823 | |
| 4824 | memset(¶ms, 0, sizeof(params)); |
| 4825 | |
| 4826 | /* these are required for START_AP */ |
| 4827 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 4828 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 4829 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 4830 | return -EINVAL; |
| 4831 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4832 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4833 | if (err) |
| 4834 | return err; |
| 4835 | |
| 4836 | params.beacon_interval = |
| 4837 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4838 | params.dtim_period = |
| 4839 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 4840 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 4841 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 4842 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4843 | if (err) |
| 4844 | return err; |
| 4845 | |
| 4846 | /* |
| 4847 | * In theory, some of these attributes should be required here |
| 4848 | * but since they were not used when the command was originally |
| 4849 | * added, keep them optional for old user space programs to let |
| 4850 | * them continue to work with drivers that do not need the |
| 4851 | * additional information -- drivers must check! |
| 4852 | */ |
| 4853 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 4854 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4855 | params.ssid_len = |
| 4856 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4857 | if (params.ssid_len == 0 || |
| 4858 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 4859 | return -EINVAL; |
| 4860 | } |
| 4861 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 4862 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4863 | params.hidden_ssid = nla_get_u32( |
| 4864 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4865 | |
| 4866 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 4867 | |
| 4868 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4869 | params.auth_type = nla_get_u32( |
| 4870 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4871 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 4872 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4873 | return -EINVAL; |
| 4874 | } else |
| 4875 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4876 | |
| 4877 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 4878 | NL80211_MAX_NR_CIPHER_SUITES); |
| 4879 | if (err) |
| 4880 | return err; |
| 4881 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 4882 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 4883 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 4884 | return -EOPNOTSUPP; |
| 4885 | params.inactivity_timeout = nla_get_u16( |
| 4886 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 4887 | } |
| 4888 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4889 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4890 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4891 | return -EINVAL; |
| 4892 | params.p2p_ctwindow = |
| 4893 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4894 | if (params.p2p_ctwindow != 0 && |
| 4895 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4896 | return -EINVAL; |
| 4897 | } |
| 4898 | |
| 4899 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4900 | u8 tmp; |
| 4901 | |
| 4902 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4903 | return -EINVAL; |
| 4904 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4905 | params.p2p_opp_ps = tmp; |
| 4906 | if (params.p2p_opp_ps != 0 && |
| 4907 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4908 | return -EINVAL; |
| 4909 | } |
| 4910 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4911 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4912 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 4913 | if (err) |
| 4914 | return err; |
| 4915 | } else if (wdev->preset_chandef.chan) { |
| 4916 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4917 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4918 | return -EINVAL; |
| 4919 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 4920 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 4921 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4922 | return -EINVAL; |
| 4923 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4924 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 4925 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); |
| 4926 | if (err) |
| 4927 | return err; |
| 4928 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4929 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 4930 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4931 | if (err) |
| 4932 | return err; |
| 4933 | } |
| 4934 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 4935 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 4936 | params.smps_mode = |
| 4937 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 4938 | switch (params.smps_mode) { |
| 4939 | case NL80211_SMPS_OFF: |
| 4940 | break; |
| 4941 | case NL80211_SMPS_STATIC: |
| 4942 | if (!(rdev->wiphy.features & |
| 4943 | NL80211_FEATURE_STATIC_SMPS)) |
| 4944 | return -EINVAL; |
| 4945 | break; |
| 4946 | case NL80211_SMPS_DYNAMIC: |
| 4947 | if (!(rdev->wiphy.features & |
| 4948 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 4949 | return -EINVAL; |
| 4950 | break; |
| 4951 | default: |
| 4952 | return -EINVAL; |
| 4953 | } |
| 4954 | } else { |
| 4955 | params.smps_mode = NL80211_SMPS_OFF; |
| 4956 | } |
| 4957 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 4958 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 4959 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 4960 | return -EOPNOTSUPP; |
| 4961 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 4962 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 4963 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 4964 | if (IS_ERR(params.acl)) |
| 4965 | return PTR_ERR(params.acl); |
| 4966 | } |
| 4967 | |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 4968 | params.twt_responder = |
| 4969 | nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); |
| 4970 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 4971 | if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { |
| 4972 | err = nl80211_parse_he_obss_pd( |
| 4973 | info->attrs[NL80211_ATTR_HE_OBSS_PD], |
| 4974 | ¶ms.he_obss_pd); |
| 4975 | if (err) |
| 4976 | return err; |
| 4977 | } |
| 4978 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 4979 | if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) { |
| 4980 | err = nl80211_parse_he_bss_color( |
| 4981 | info->attrs[NL80211_ATTR_HE_BSS_COLOR], |
| 4982 | ¶ms.he_bss_color); |
| 4983 | if (err) |
| 4984 | return err; |
| 4985 | } |
| 4986 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4987 | nl80211_calculate_ap_params(¶ms); |
| 4988 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 4989 | if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) |
| 4990 | params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; |
| 4991 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4992 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4993 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4994 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4995 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4996 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 4997 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 4998 | wdev->ssid_len = params.ssid_len; |
| 4999 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Denis Kenzior | 466a306 | 2018-03-26 12:52:47 -0500 | [diff] [blame] | 5000 | |
| 5001 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 5002 | wdev->conn_owner_nlportid = info->snd_portid; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5003 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5004 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 5005 | |
| 5006 | kfree(params.acl); |
| 5007 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 5008 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5009 | } |
| 5010 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5011 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 5012 | { |
| 5013 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5014 | struct net_device *dev = info->user_ptr[1]; |
| 5015 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5016 | struct cfg80211_beacon_data params; |
| 5017 | int err; |
| 5018 | |
| 5019 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5020 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5021 | return -EOPNOTSUPP; |
| 5022 | |
| 5023 | if (!rdev->ops->change_beacon) |
| 5024 | return -EOPNOTSUPP; |
| 5025 | |
| 5026 | if (!wdev->beacon_interval) |
| 5027 | return -EINVAL; |
| 5028 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5029 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5030 | if (err) |
| 5031 | return err; |
| 5032 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5033 | wdev_lock(wdev); |
| 5034 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 5035 | wdev_unlock(wdev); |
| 5036 | |
| 5037 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5041 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5042 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5043 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5044 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 5045 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5046 | } |
| 5047 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5048 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 5049 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 5050 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 5051 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 5052 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 5053 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 5054 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5055 | }; |
| 5056 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5057 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5058 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5059 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5060 | { |
| 5061 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5062 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5063 | int flag; |
| 5064 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5065 | /* |
| 5066 | * Try parsing the new attribute first so userspace |
| 5067 | * can specify both for older kernels. |
| 5068 | */ |
| 5069 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 5070 | if (nla) { |
| 5071 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5072 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5073 | sta_flags = nla_data(nla); |
| 5074 | params->sta_flags_mask = sta_flags->mask; |
| 5075 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5076 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5077 | if ((params->sta_flags_mask | |
| 5078 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 5079 | return -EINVAL; |
| 5080 | return 0; |
| 5081 | } |
| 5082 | |
| 5083 | /* if present, parse the old attribute */ |
| 5084 | |
| 5085 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5086 | if (!nla) |
| 5087 | return 0; |
| 5088 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 5089 | if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5090 | return -EINVAL; |
| 5091 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5092 | /* |
| 5093 | * Only allow certain flags for interface types so that |
| 5094 | * other attributes are silently ignored. Remember that |
| 5095 | * this is backward compatibility code with old userspace |
| 5096 | * and shouldn't be hit in other cases anyway. |
| 5097 | */ |
| 5098 | switch (iftype) { |
| 5099 | case NL80211_IFTYPE_AP: |
| 5100 | case NL80211_IFTYPE_AP_VLAN: |
| 5101 | case NL80211_IFTYPE_P2P_GO: |
| 5102 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5103 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5104 | BIT(NL80211_STA_FLAG_WME) | |
| 5105 | BIT(NL80211_STA_FLAG_MFP); |
| 5106 | break; |
| 5107 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5108 | case NL80211_IFTYPE_STATION: |
| 5109 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5110 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5111 | break; |
| 5112 | case NL80211_IFTYPE_MESH_POINT: |
| 5113 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5114 | BIT(NL80211_STA_FLAG_MFP) | |
| 5115 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
Bernd Edlinger | 5cf3006 | 2018-07-08 09:57:22 +0000 | [diff] [blame] | 5116 | break; |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5117 | default: |
| 5118 | return -EINVAL; |
| 5119 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5120 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 5121 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 5122 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5123 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5124 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 5125 | /* no longer support new API additions in old API */ |
| 5126 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 5127 | return -EINVAL; |
| 5128 | } |
| 5129 | } |
| 5130 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5131 | return 0; |
| 5132 | } |
| 5133 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 5134 | bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5135 | { |
| 5136 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 5137 | u32 bitrate; |
| 5138 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 5139 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5140 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5141 | rate = nla_nest_start_noflag(msg, attr); |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5142 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5143 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5144 | |
| 5145 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 5146 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 5147 | /* report 16-bit bitrate only if we can */ |
| 5148 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5149 | if (bitrate > 0 && |
| 5150 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 5151 | return false; |
| 5152 | if (bitrate_compat > 0 && |
| 5153 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 5154 | return false; |
| 5155 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5156 | switch (info->bw) { |
| 5157 | case RATE_INFO_BW_5: |
| 5158 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 5159 | break; |
| 5160 | case RATE_INFO_BW_10: |
| 5161 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 5162 | break; |
| 5163 | default: |
| 5164 | WARN_ON(1); |
| 5165 | /* fall through */ |
| 5166 | case RATE_INFO_BW_20: |
| 5167 | rate_flg = 0; |
| 5168 | break; |
| 5169 | case RATE_INFO_BW_40: |
| 5170 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 5171 | break; |
| 5172 | case RATE_INFO_BW_80: |
| 5173 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 5174 | break; |
| 5175 | case RATE_INFO_BW_160: |
| 5176 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 5177 | break; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5178 | case RATE_INFO_BW_HE_RU: |
| 5179 | rate_flg = 0; |
| 5180 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 5184 | return false; |
| 5185 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5186 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 5187 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 5188 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5189 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5190 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5191 | return false; |
| 5192 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 5193 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 5194 | return false; |
| 5195 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 5196 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5197 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5198 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5199 | return false; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5200 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { |
| 5201 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) |
| 5202 | return false; |
| 5203 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) |
| 5204 | return false; |
| 5205 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) |
| 5206 | return false; |
| 5207 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) |
| 5208 | return false; |
| 5209 | if (info->bw == RATE_INFO_BW_HE_RU && |
| 5210 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, |
| 5211 | info->he_ru_alloc)) |
| 5212 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5213 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5214 | |
| 5215 | nla_nest_end(msg, rate); |
| 5216 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5217 | } |
| 5218 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5219 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 5220 | int id) |
| 5221 | { |
| 5222 | void *attr; |
| 5223 | int i = 0; |
| 5224 | |
| 5225 | if (!mask) |
| 5226 | return true; |
| 5227 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5228 | attr = nla_nest_start_noflag(msg, id); |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5229 | if (!attr) |
| 5230 | return false; |
| 5231 | |
| 5232 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 5233 | if (!(mask & BIT(i))) |
| 5234 | continue; |
| 5235 | |
| 5236 | if (nla_put_u8(msg, i, signal[i])) |
| 5237 | return false; |
| 5238 | } |
| 5239 | |
| 5240 | nla_nest_end(msg, attr); |
| 5241 | |
| 5242 | return true; |
| 5243 | } |
| 5244 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5245 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 5246 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5247 | struct cfg80211_registered_device *rdev, |
| 5248 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 5249 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5250 | { |
| 5251 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5252 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5253 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5254 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Andy Strohman | f77bf48 | 2019-05-24 23:27:29 -0700 | [diff] [blame] | 5255 | if (!hdr) { |
| 5256 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5257 | return -1; |
Andy Strohman | f77bf48 | 2019-05-24 23:27:29 -0700 | [diff] [blame] | 5258 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5259 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5260 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5261 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 5262 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 5263 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5264 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5265 | sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5266 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5267 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5268 | |
| 5269 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5270 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5271 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5272 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 5273 | sinfo->memb)) \ |
| 5274 | goto nla_put_failure; \ |
| 5275 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5276 | #define PUT_SINFO_U64(attr, memb) do { \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5277 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5278 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 5279 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 5280 | goto nla_put_failure; \ |
| 5281 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5282 | |
| 5283 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 5284 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
Ben Greear | 6c7a003 | 2019-08-09 11:00:00 -0700 | [diff] [blame] | 5285 | PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5286 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5287 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | |
| 5288 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5289 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 5290 | (u32)sinfo->rx_bytes)) |
| 5291 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5292 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5293 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | |
| 5294 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 5295 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 5296 | (u32)sinfo->tx_bytes)) |
| 5297 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5298 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5299 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 5300 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5301 | PUT_SINFO(LLID, llid, u16); |
| 5302 | PUT_SINFO(PLID, plid, u16); |
| 5303 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5304 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 5305 | PUT_SINFO_U64(TX_DURATION, tx_duration); |
| 5306 | |
| 5307 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 5308 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 5309 | PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5310 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5311 | switch (rdev->wiphy.signal_type) { |
| 5312 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5313 | PUT_SINFO(SIGNAL, signal, u8); |
| 5314 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5315 | break; |
| 5316 | default: |
| 5317 | break; |
| 5318 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5319 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5320 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 5321 | sinfo->chain_signal, |
| 5322 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 5323 | goto nla_put_failure; |
| 5324 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5325 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5326 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 5327 | sinfo->chain_signal_avg, |
| 5328 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 5329 | goto nla_put_failure; |
| 5330 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5331 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5332 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 5333 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 5334 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5335 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5336 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5337 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 5338 | NL80211_STA_INFO_RX_BITRATE)) |
| 5339 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 5340 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5341 | |
| 5342 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 5343 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 5344 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 5345 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 5346 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
Narayanraddi Masti | ab60633 | 2019-02-07 12:16:05 -0800 | [diff] [blame] | 5347 | PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5348 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 5349 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 5350 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 5351 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
Bob Copeland | dbdaee7 | 2018-10-25 15:48:53 -0400 | [diff] [blame] | 5352 | PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5353 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5354 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5355 | bss_param = nla_nest_start_noflag(msg, |
| 5356 | NL80211_STA_INFO_BSS_PARAM); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5357 | if (!bss_param) |
| 5358 | goto nla_put_failure; |
| 5359 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5360 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 5361 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 5362 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 5363 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 5364 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 5365 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 5366 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 5367 | sinfo->bss_param.dtim_period) || |
| 5368 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 5369 | sinfo->bss_param.beacon_interval)) |
| 5370 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5371 | |
| 5372 | nla_nest_end(msg, bss_param); |
| 5373 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5374 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5375 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 5376 | sizeof(struct nl80211_sta_flag_update), |
| 5377 | &sinfo->sta_flags)) |
| 5378 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5379 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5380 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 5381 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 5382 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 5383 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Ankita Bajaj | 0d4e14a | 2018-09-27 18:01:57 +0300 | [diff] [blame] | 5384 | PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); |
| 5385 | PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); |
Balaji Pothunoori | 81d5439 | 2018-04-16 20:18:40 +0530 | [diff] [blame] | 5386 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
Balaji Pothunoori | 9c06602 | 2018-07-19 18:56:27 +0530 | [diff] [blame] | 5387 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { |
| 5388 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); |
| 5389 | PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); |
| 5390 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5391 | |
| 5392 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5393 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5394 | |
Arend van Spriel | 8689c05 | 2018-05-10 13:50:12 +0200 | [diff] [blame] | 5395 | if (sinfo->pertid) { |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5396 | struct nlattr *tidsattr; |
| 5397 | int tid; |
| 5398 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5399 | tidsattr = nla_nest_start_noflag(msg, |
| 5400 | NL80211_STA_INFO_TID_STATS); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5401 | if (!tidsattr) |
| 5402 | goto nla_put_failure; |
| 5403 | |
| 5404 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 5405 | struct cfg80211_tid_stats *tidstats; |
| 5406 | struct nlattr *tidattr; |
| 5407 | |
| 5408 | tidstats = &sinfo->pertid[tid]; |
| 5409 | |
| 5410 | if (!tidstats->filled) |
| 5411 | continue; |
| 5412 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5413 | tidattr = nla_nest_start_noflag(msg, tid + 1); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5414 | if (!tidattr) |
| 5415 | goto nla_put_failure; |
| 5416 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5417 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5418 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5419 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 5420 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5421 | goto nla_put_failure; \ |
| 5422 | } while (0) |
| 5423 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5424 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 5425 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 5426 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 5427 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5428 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5429 | #undef PUT_TIDVAL_U64 |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 5430 | if ((tidstats->filled & |
| 5431 | BIT(NL80211_TID_STATS_TXQ_STATS)) && |
| 5432 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, |
| 5433 | NL80211_TID_STATS_TXQ_STATS)) |
| 5434 | goto nla_put_failure; |
| 5435 | |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5436 | nla_nest_end(msg, tidattr); |
| 5437 | } |
| 5438 | |
| 5439 | nla_nest_end(msg, tidsattr); |
| 5440 | } |
| 5441 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5442 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5443 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5444 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5445 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 5446 | sinfo->assoc_req_ies)) |
| 5447 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 5448 | |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5449 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5450 | genlmsg_end(msg, hdr); |
| 5451 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5452 | |
| 5453 | nla_put_failure: |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5454 | cfg80211_sinfo_release_content(sinfo); |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5455 | genlmsg_cancel(msg, hdr); |
| 5456 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5457 | } |
| 5458 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5459 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5460 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5461 | { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5462 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5463 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5464 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5465 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5466 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5467 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5468 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5469 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 5470 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5471 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5472 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5473 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5474 | if (!wdev->netdev) { |
| 5475 | err = -EINVAL; |
| 5476 | goto out_err; |
| 5477 | } |
| 5478 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5479 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5480 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5481 | goto out_err; |
| 5482 | } |
| 5483 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5484 | while (1) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5485 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5486 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5487 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5488 | if (err == -ENOENT) |
| 5489 | break; |
| 5490 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5491 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5492 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5493 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5494 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5495 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5496 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5497 | &sinfo) < 0) |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5498 | goto out; |
| 5499 | |
| 5500 | sta_idx++; |
| 5501 | } |
| 5502 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5503 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5504 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5505 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5506 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5507 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5508 | |
| 5509 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5510 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5511 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5512 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 5513 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5514 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5515 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5516 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5517 | struct sk_buff *msg; |
| 5518 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5519 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5520 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5521 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5522 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5523 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5524 | return -EINVAL; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5525 | |
| 5526 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5527 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5528 | if (!rdev->ops->get_station) |
| 5529 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5530 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5531 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5532 | if (err) |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5533 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5534 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5535 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5536 | if (!msg) { |
Denis Kenzior | ba8f566 | 2018-05-21 19:21:42 -0500 | [diff] [blame] | 5537 | cfg80211_sinfo_release_content(&sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5538 | return -ENOMEM; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5539 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5540 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5541 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 5542 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5543 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5544 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5545 | return -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5546 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5547 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5548 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5549 | } |
| 5550 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5551 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 5552 | struct station_parameters *params, |
| 5553 | enum cfg80211_station_type statype) |
| 5554 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5555 | if (params->listen_interval != -1 && |
| 5556 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5557 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5558 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5559 | if (params->support_p2p_ps != -1 && |
| 5560 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 5561 | return -EINVAL; |
| 5562 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 5563 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5564 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 5565 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5566 | return -EINVAL; |
| 5567 | |
| 5568 | /* When you run into this, adjust the code below for the new flag */ |
| 5569 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5570 | |
| 5571 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5572 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 5573 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5574 | /* |
| 5575 | * No ignoring the TDLS flag here -- the userspace mesh |
| 5576 | * code doesn't have the bug of including TDLS in the |
| 5577 | * mask everywhere. |
| 5578 | */ |
| 5579 | if (params->sta_flags_mask & |
| 5580 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5581 | BIT(NL80211_STA_FLAG_MFP) | |
| 5582 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5583 | return -EINVAL; |
| 5584 | break; |
| 5585 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5586 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5587 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5588 | return -EINVAL; |
| 5589 | /* ignore since it can't change */ |
| 5590 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5591 | break; |
| 5592 | default: |
| 5593 | /* disallow mesh-specific things */ |
| 5594 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 5595 | return -EINVAL; |
| 5596 | if (params->local_pm) |
| 5597 | return -EINVAL; |
| 5598 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5599 | return -EINVAL; |
| 5600 | } |
| 5601 | |
| 5602 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5603 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 5604 | /* TDLS can't be set, ... */ |
| 5605 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 5606 | return -EINVAL; |
| 5607 | /* |
| 5608 | * ... but don't bother the driver with it. This works around |
| 5609 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 5610 | * TLDS_PEER flag in the mask even for AP mode. |
| 5611 | */ |
| 5612 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5613 | } |
| 5614 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5615 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5616 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5617 | /* reject other things that can't change */ |
| 5618 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 5619 | return -EINVAL; |
| 5620 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 5621 | return -EINVAL; |
| 5622 | if (params->supported_rates) |
| 5623 | return -EINVAL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5624 | if (params->ext_capab || params->ht_capa || params->vht_capa || |
| 5625 | params->he_capa) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5626 | return -EINVAL; |
| 5627 | } |
| 5628 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5629 | if (statype != CFG80211_STA_AP_CLIENT && |
| 5630 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5631 | if (params->vlan) |
| 5632 | return -EINVAL; |
| 5633 | } |
| 5634 | |
| 5635 | switch (statype) { |
| 5636 | case CFG80211_STA_AP_MLME_CLIENT: |
| 5637 | /* Use this only for authorizing/unauthorizing a station */ |
| 5638 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5639 | return -EOPNOTSUPP; |
| 5640 | break; |
| 5641 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5642 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5643 | /* accept only the listed bits */ |
| 5644 | if (params->sta_flags_mask & |
| 5645 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5646 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5647 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5648 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5649 | BIT(NL80211_STA_FLAG_WME) | |
| 5650 | BIT(NL80211_STA_FLAG_MFP))) |
| 5651 | return -EINVAL; |
| 5652 | |
| 5653 | /* but authenticated/associated only if driver handles it */ |
| 5654 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 5655 | params->sta_flags_mask & |
| 5656 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5657 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 5658 | return -EINVAL; |
| 5659 | break; |
| 5660 | case CFG80211_STA_IBSS: |
| 5661 | case CFG80211_STA_AP_STA: |
| 5662 | /* reject any changes other than AUTHORIZED */ |
| 5663 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 5664 | return -EINVAL; |
| 5665 | break; |
| 5666 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5667 | /* reject any changes other than AUTHORIZED or WME */ |
| 5668 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5669 | BIT(NL80211_STA_FLAG_WME))) |
| 5670 | return -EINVAL; |
| 5671 | /* force (at least) rates when authorizing */ |
| 5672 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 5673 | !params->supported_rates) |
| 5674 | return -EINVAL; |
| 5675 | break; |
| 5676 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5677 | /* reject any changes */ |
| 5678 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5679 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5680 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5681 | return -EINVAL; |
| 5682 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5683 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 5684 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 5685 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5686 | return -EINVAL; |
| 5687 | break; |
| 5688 | } |
| 5689 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 5690 | /* |
| 5691 | * Older kernel versions ignored this attribute entirely, so don't |
| 5692 | * reject attempts to update it but mark it as unused instead so the |
| 5693 | * driver won't look at the data. |
| 5694 | */ |
| 5695 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 5696 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 5697 | params->opmode_notif_used = false; |
| 5698 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5699 | return 0; |
| 5700 | } |
| 5701 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 5702 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5703 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 5704 | * Get vlan interface making sure it is running and on the right wiphy. |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5705 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5706 | static struct net_device *get_vlan(struct genl_info *info, |
| 5707 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5708 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5709 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5710 | struct net_device *v; |
| 5711 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5712 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5713 | if (!vlanattr) |
| 5714 | return NULL; |
| 5715 | |
| 5716 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 5717 | if (!v) |
| 5718 | return ERR_PTR(-ENODEV); |
| 5719 | |
| 5720 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 5721 | ret = -EINVAL; |
| 5722 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5723 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5724 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5725 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5726 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5727 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 5728 | ret = -EINVAL; |
| 5729 | goto error; |
| 5730 | } |
| 5731 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5732 | if (!netif_running(v)) { |
| 5733 | ret = -ENETDOWN; |
| 5734 | goto error; |
| 5735 | } |
| 5736 | |
| 5737 | return v; |
| 5738 | error: |
| 5739 | dev_put(v); |
| 5740 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5741 | } |
| 5742 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 5743 | static const struct nla_policy |
| 5744 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5745 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 5746 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 5747 | }; |
| 5748 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5749 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 5750 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5751 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5752 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 5753 | struct nlattr *nla; |
| 5754 | int err; |
| 5755 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5756 | /* parse WME attributes if present */ |
| 5757 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 5758 | return 0; |
| 5759 | |
| 5760 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 5761 | err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, |
| 5762 | nl80211_sta_wme_policy, |
| 5763 | info->extack); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5764 | if (err) |
| 5765 | return err; |
| 5766 | |
| 5767 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 5768 | params->uapsd_queues = nla_get_u8( |
| 5769 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 5770 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 5771 | return -EINVAL; |
| 5772 | |
| 5773 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 5774 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 5775 | |
| 5776 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 5777 | return -EINVAL; |
| 5778 | |
| 5779 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 5780 | |
| 5781 | return 0; |
| 5782 | } |
| 5783 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5784 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 5785 | struct station_parameters *params) |
| 5786 | { |
| 5787 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 5788 | params->supported_channels = |
| 5789 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 5790 | params->supported_channels_len = |
| 5791 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 5792 | /* |
| 5793 | * Need to include at least one (first channel, number of |
| 5794 | * channels) tuple for each subband, and must have proper |
| 5795 | * tuples for the rest of the data as well. |
| 5796 | */ |
| 5797 | if (params->supported_channels_len < 2) |
| 5798 | return -EINVAL; |
| 5799 | if (params->supported_channels_len % 2) |
| 5800 | return -EINVAL; |
| 5801 | } |
| 5802 | |
| 5803 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 5804 | params->supported_oper_classes = |
| 5805 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 5806 | params->supported_oper_classes_len = |
| 5807 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 5808 | /* |
| 5809 | * The value of the Length field of the Supported Operating |
| 5810 | * Classes element is between 2 and 253. |
| 5811 | */ |
| 5812 | if (params->supported_oper_classes_len < 2 || |
| 5813 | params->supported_oper_classes_len > 253) |
| 5814 | return -EINVAL; |
| 5815 | } |
| 5816 | return 0; |
| 5817 | } |
| 5818 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5819 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 5820 | struct station_parameters *params) |
| 5821 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5822 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5823 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5824 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 5825 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5826 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 5827 | params->ht_capa = |
| 5828 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5829 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 5830 | params->vht_capa = |
| 5831 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5832 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 5833 | params->he_capa = |
| 5834 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5835 | params->he_capa_len = |
| 5836 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5837 | |
| 5838 | if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) |
| 5839 | return -EINVAL; |
| 5840 | } |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5841 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5842 | err = nl80211_parse_sta_channel_info(info, params); |
| 5843 | if (err) |
| 5844 | return err; |
| 5845 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5846 | return nl80211_parse_sta_wme(info, params); |
| 5847 | } |
| 5848 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 5849 | static int nl80211_parse_sta_txpower_setting(struct genl_info *info, |
| 5850 | struct station_parameters *params) |
| 5851 | { |
| 5852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5853 | int idx; |
| 5854 | |
| 5855 | if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { |
| 5856 | if (!rdev->ops->set_tx_power || |
| 5857 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5858 | NL80211_EXT_FEATURE_STA_TX_PWR)) |
| 5859 | return -EOPNOTSUPP; |
| 5860 | |
| 5861 | idx = NL80211_ATTR_STA_TX_POWER_SETTING; |
| 5862 | params->txpwr.type = nla_get_u8(info->attrs[idx]); |
| 5863 | |
| 5864 | if (params->txpwr.type == NL80211_TX_POWER_LIMITED) { |
| 5865 | idx = NL80211_ATTR_STA_TX_POWER; |
| 5866 | |
| 5867 | if (info->attrs[idx]) |
| 5868 | params->txpwr.power = |
| 5869 | nla_get_s16(info->attrs[idx]); |
| 5870 | else |
| 5871 | return -EINVAL; |
| 5872 | } |
| 5873 | params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER; |
| 5874 | } |
| 5875 | |
| 5876 | return 0; |
| 5877 | } |
| 5878 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5879 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 5880 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5881 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5882 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5883 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5884 | u8 *mac_addr; |
| 5885 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5886 | |
| 5887 | memset(¶ms, 0, sizeof(params)); |
| 5888 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5889 | if (!rdev->ops->change_station) |
| 5890 | return -EOPNOTSUPP; |
| 5891 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5892 | /* |
| 5893 | * AID and listen_interval properties can be set only for unassociated |
| 5894 | * station. Include these parameters here and will check them in |
| 5895 | * cfg80211_check_station_change(). |
| 5896 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 5897 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 5898 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5899 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 5900 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 5901 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 5902 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5903 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 5904 | params.listen_interval = |
| 5905 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 5906 | else |
| 5907 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5908 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5909 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) |
| 5910 | params.support_p2p_ps = |
| 5911 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 5912 | else |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5913 | params.support_p2p_ps = -1; |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5914 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5915 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5916 | return -EINVAL; |
| 5917 | |
| 5918 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5919 | |
| 5920 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 5921 | params.supported_rates = |
| 5922 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5923 | params.supported_rates_len = |
| 5924 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5925 | } |
| 5926 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 5927 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 5928 | params.capability = |
| 5929 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 5930 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 5931 | } |
| 5932 | |
| 5933 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 5934 | params.ext_capab = |
| 5935 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5936 | params.ext_capab_len = |
| 5937 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5938 | } |
| 5939 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5940 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5941 | return -EINVAL; |
| 5942 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5943 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5944 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5945 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5946 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5947 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 5948 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5949 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5950 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 5951 | params.peer_aid = nla_get_u16( |
| 5952 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5953 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 5954 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 5955 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5956 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) |
| 5957 | params.local_pm = nla_get_u32( |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5958 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 5959 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 5960 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 5961 | params.opmode_notif_used = true; |
| 5962 | params.opmode_notif = |
| 5963 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 5964 | } |
| 5965 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 5966 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 5967 | params.airtime_weight = |
| 5968 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 5969 | |
| 5970 | if (params.airtime_weight && |
| 5971 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5972 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 5973 | return -EOPNOTSUPP; |
| 5974 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 5975 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 5976 | if (err) |
| 5977 | return err; |
| 5978 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5979 | /* Include parameters for TDLS peer (will check later) */ |
| 5980 | err = nl80211_set_station_tdls(info, ¶ms); |
| 5981 | if (err) |
| 5982 | return err; |
| 5983 | |
| 5984 | params.vlan = get_vlan(info, rdev); |
| 5985 | if (IS_ERR(params.vlan)) |
| 5986 | return PTR_ERR(params.vlan); |
| 5987 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5988 | switch (dev->ieee80211_ptr->iftype) { |
| 5989 | case NL80211_IFTYPE_AP: |
| 5990 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5991 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5992 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5993 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5994 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5995 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5996 | break; |
| 5997 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5998 | err = -EOPNOTSUPP; |
| 5999 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 6000 | } |
| 6001 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6002 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6003 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6004 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6005 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6006 | if (params.vlan) |
| 6007 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6008 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6009 | return err; |
| 6010 | } |
| 6011 | |
| 6012 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 6013 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6014 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6015 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6016 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6017 | struct station_parameters params; |
| 6018 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6019 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 6020 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6021 | |
| 6022 | memset(¶ms, 0, sizeof(params)); |
| 6023 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6024 | if (!rdev->ops->add_station) |
| 6025 | return -EOPNOTSUPP; |
| 6026 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6027 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6028 | return -EINVAL; |
| 6029 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6030 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 6031 | return -EINVAL; |
| 6032 | |
| 6033 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 6034 | return -EINVAL; |
| 6035 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6036 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 6037 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 6038 | return -EINVAL; |
| 6039 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6040 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6041 | params.supported_rates = |
| 6042 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6043 | params.supported_rates_len = |
| 6044 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6045 | params.listen_interval = |
| 6046 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 6047 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 6048 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 6049 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 6050 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6051 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6052 | params.support_p2p_ps = |
| 6053 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6054 | } else { |
| 6055 | /* |
| 6056 | * if not specified, assume it's supported for P2P GO interface, |
| 6057 | * and is NOT supported for AP interface |
| 6058 | */ |
| 6059 | params.support_p2p_ps = |
| 6060 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 6061 | } |
| 6062 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6063 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6064 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6065 | else |
| 6066 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 6067 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 6068 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 6069 | params.capability = |
| 6070 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 6071 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 6072 | } |
| 6073 | |
| 6074 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 6075 | params.ext_capab = |
| 6076 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6077 | params.ext_capab_len = |
| 6078 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6079 | } |
| 6080 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 6081 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 6082 | params.ht_capa = |
| 6083 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6084 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 6085 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 6086 | params.vht_capa = |
| 6087 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 6088 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6089 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 6090 | params.he_capa = |
| 6091 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6092 | params.he_capa_len = |
| 6093 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6094 | |
| 6095 | /* max len is validated in nla policy */ |
| 6096 | if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) |
| 6097 | return -EINVAL; |
| 6098 | } |
| 6099 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 6100 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6101 | params.opmode_notif_used = true; |
| 6102 | params.opmode_notif = |
| 6103 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6104 | } |
| 6105 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6106 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 6107 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6108 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 6109 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 6110 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6111 | params.airtime_weight = |
| 6112 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6113 | |
| 6114 | if (params.airtime_weight && |
| 6115 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6116 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6117 | return -EOPNOTSUPP; |
| 6118 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6119 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6120 | if (err) |
| 6121 | return err; |
| 6122 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6123 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 6124 | if (err) |
| 6125 | return err; |
| 6126 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6127 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 6128 | if (err) |
| 6129 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6130 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 6131 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6132 | return -EINVAL; |
| 6133 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 6134 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 6135 | * as userspace might just pass through the capabilities from the IEs |
| 6136 | * directly, rather than enforcing this restriction and returning an |
| 6137 | * error in this case. |
| 6138 | */ |
| 6139 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 6140 | params.ht_capa = NULL; |
| 6141 | params.vht_capa = NULL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6142 | |
| 6143 | /* HE requires WME */ |
| 6144 | if (params.he_capa_len) |
| 6145 | return -EINVAL; |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 6146 | } |
| 6147 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6148 | /* When you run into this, adjust the code below for the new flag */ |
| 6149 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 6150 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6151 | switch (dev->ieee80211_ptr->iftype) { |
| 6152 | case NL80211_IFTYPE_AP: |
| 6153 | case NL80211_IFTYPE_AP_VLAN: |
| 6154 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6155 | /* ignore WME attributes if iface/sta is not capable */ |
| 6156 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 6157 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 6158 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6159 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6160 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6161 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6162 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 6163 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6164 | /* but don't bother the driver with it */ |
| 6165 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6166 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6167 | /* allow authenticated/associated only if driver handles it */ |
| 6168 | if (!(rdev->wiphy.features & |
| 6169 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6170 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6171 | return -EINVAL; |
| 6172 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6173 | /* Older userspace, or userspace wanting to be compatible with |
| 6174 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 6175 | * and assoc flags in the mask, but assumes the station will be |
| 6176 | * added as associated anyway since this was the required driver |
| 6177 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 6178 | * introduced. |
| 6179 | * In order to not bother drivers with this quirk in the API |
| 6180 | * set the flags in both the mask and set for new stations in |
| 6181 | * this case. |
| 6182 | */ |
| 6183 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 6184 | params.sta_flags_mask |= auth_assoc; |
| 6185 | params.sta_flags_set |= auth_assoc; |
| 6186 | } |
| 6187 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6188 | /* must be last in here for error handling */ |
| 6189 | params.vlan = get_vlan(info, rdev); |
| 6190 | if (IS_ERR(params.vlan)) |
| 6191 | return PTR_ERR(params.vlan); |
| 6192 | break; |
| 6193 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6194 | /* ignore uAPSD data */ |
| 6195 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6196 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6197 | /* associated is disallowed */ |
| 6198 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 6199 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6200 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6201 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6202 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 6203 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6204 | break; |
| 6205 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 6206 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6207 | /* ignore uAPSD data */ |
| 6208 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6209 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6210 | /* these are disallowed */ |
| 6211 | if (params.sta_flags_mask & |
| 6212 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 6213 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6214 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6215 | /* Only TDLS peers can be added */ |
| 6216 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 6217 | return -EINVAL; |
| 6218 | /* Can only add if TDLS ... */ |
| 6219 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 6220 | return -EOPNOTSUPP; |
| 6221 | /* ... with external setup is supported */ |
| 6222 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 6223 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6224 | /* |
| 6225 | * Older wpa_supplicant versions always mark the TDLS peer |
| 6226 | * as authorized, but it shouldn't yet be. |
| 6227 | */ |
| 6228 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6229 | break; |
| 6230 | default: |
| 6231 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6232 | } |
| 6233 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6234 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6235 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6236 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6237 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6238 | if (params.vlan) |
| 6239 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6240 | return err; |
| 6241 | } |
| 6242 | |
| 6243 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 6244 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6245 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6246 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6247 | struct station_del_parameters params; |
| 6248 | |
| 6249 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6250 | |
| 6251 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6252 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6253 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 6254 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 6255 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6256 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6257 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6258 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 6259 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6260 | if (!rdev->ops->del_station) |
| 6261 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6262 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 6263 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 6264 | params.subtype = |
| 6265 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 6266 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 6267 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 6268 | return -EINVAL; |
| 6269 | } else { |
| 6270 | /* Default to Deauthentication frame */ |
| 6271 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 6272 | } |
| 6273 | |
| 6274 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 6275 | params.reason_code = |
| 6276 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6277 | if (params.reason_code == 0) |
| 6278 | return -EINVAL; /* 0 is reserved */ |
| 6279 | } else { |
| 6280 | /* Default to reason code 2 */ |
| 6281 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 6282 | } |
| 6283 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6284 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6285 | } |
| 6286 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6287 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6288 | int flags, struct net_device *dev, |
| 6289 | u8 *dst, u8 *next_hop, |
| 6290 | struct mpath_info *pinfo) |
| 6291 | { |
| 6292 | void *hdr; |
| 6293 | struct nlattr *pinfoattr; |
| 6294 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 6295 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6296 | if (!hdr) |
| 6297 | return -1; |
| 6298 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6299 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 6300 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 6301 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 6302 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 6303 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 6304 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 6305 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6306 | if (!pinfoattr) |
| 6307 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6308 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 6309 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 6310 | pinfo->frame_qlen)) |
| 6311 | goto nla_put_failure; |
| 6312 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 6313 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 6314 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 6315 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 6316 | pinfo->metric)) || |
| 6317 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 6318 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 6319 | pinfo->exptime)) || |
| 6320 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 6321 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 6322 | pinfo->flags)) || |
| 6323 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 6324 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 6325 | pinfo->discovery_timeout)) || |
| 6326 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 6327 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
Julan Hsu | cc24163 | 2019-01-15 15:28:42 -0800 | [diff] [blame] | 6328 | pinfo->discovery_retries)) || |
| 6329 | ((pinfo->filled & MPATH_INFO_HOP_COUNT) && |
| 6330 | nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, |
Julan Hsu | 540bbcb | 2019-01-15 15:28:43 -0800 | [diff] [blame] | 6331 | pinfo->hop_count)) || |
| 6332 | ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && |
| 6333 | nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, |
| 6334 | pinfo->path_change_count))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6335 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6336 | |
| 6337 | nla_nest_end(msg, pinfoattr); |
| 6338 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6339 | genlmsg_end(msg, hdr); |
| 6340 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6341 | |
| 6342 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 6343 | genlmsg_cancel(msg, hdr); |
| 6344 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6345 | } |
| 6346 | |
| 6347 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6348 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6349 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6350 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6351 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6352 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6353 | u8 dst[ETH_ALEN]; |
| 6354 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6355 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6356 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6357 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6358 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 6359 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6360 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6361 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6362 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6363 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6364 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6365 | goto out_err; |
| 6366 | } |
| 6367 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6368 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6369 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 6370 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6371 | } |
| 6372 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6373 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6374 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6375 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6376 | if (err == -ENOENT) |
| 6377 | break; |
| 6378 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6379 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6380 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6381 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6382 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6383 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6384 | &pinfo) < 0) |
| 6385 | goto out; |
| 6386 | |
| 6387 | path_idx++; |
| 6388 | } |
| 6389 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6390 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6391 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6392 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6393 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6394 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6395 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6396 | } |
| 6397 | |
| 6398 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6399 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6400 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6401 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6402 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6403 | struct mpath_info pinfo; |
| 6404 | struct sk_buff *msg; |
| 6405 | u8 *dst = NULL; |
| 6406 | u8 next_hop[ETH_ALEN]; |
| 6407 | |
| 6408 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6409 | |
| 6410 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6411 | return -EINVAL; |
| 6412 | |
| 6413 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6414 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6415 | if (!rdev->ops->get_mpath) |
| 6416 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6417 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6418 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6419 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6420 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6421 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6422 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6423 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6424 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6425 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6426 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6427 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6428 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6429 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6430 | dev, dst, next_hop, &pinfo) < 0) { |
| 6431 | nlmsg_free(msg); |
| 6432 | return -ENOBUFS; |
| 6433 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6434 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6435 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6439 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6440 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6441 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6442 | u8 *dst = NULL; |
| 6443 | u8 *next_hop = NULL; |
| 6444 | |
| 6445 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6446 | return -EINVAL; |
| 6447 | |
| 6448 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 6449 | return -EINVAL; |
| 6450 | |
| 6451 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6452 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 6453 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6454 | if (!rdev->ops->change_mpath) |
| 6455 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6456 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6457 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6458 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6459 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6460 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6461 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6462 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6463 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6464 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6466 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6467 | u8 *dst = NULL; |
| 6468 | u8 *next_hop = NULL; |
| 6469 | |
| 6470 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6471 | return -EINVAL; |
| 6472 | |
| 6473 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 6474 | return -EINVAL; |
| 6475 | |
| 6476 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6477 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 6478 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6479 | if (!rdev->ops->add_mpath) |
| 6480 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6481 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6482 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6483 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6484 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6485 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6486 | } |
| 6487 | |
| 6488 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6489 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6490 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6491 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6492 | u8 *dst = NULL; |
| 6493 | |
| 6494 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6495 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6496 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6497 | if (!rdev->ops->del_mpath) |
| 6498 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6499 | |
Miaoqing Pan | b501426 | 2019-09-26 16:16:50 +0800 | [diff] [blame] | 6500 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6501 | return -EOPNOTSUPP; |
| 6502 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6503 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6504 | } |
| 6505 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6506 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 6507 | { |
| 6508 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6509 | int err; |
| 6510 | struct net_device *dev = info->user_ptr[1]; |
| 6511 | struct mpath_info pinfo; |
| 6512 | struct sk_buff *msg; |
| 6513 | u8 *dst = NULL; |
| 6514 | u8 mpp[ETH_ALEN]; |
| 6515 | |
| 6516 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6517 | |
| 6518 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6519 | return -EINVAL; |
| 6520 | |
| 6521 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6522 | |
| 6523 | if (!rdev->ops->get_mpp) |
| 6524 | return -EOPNOTSUPP; |
| 6525 | |
| 6526 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6527 | return -EOPNOTSUPP; |
| 6528 | |
| 6529 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 6530 | if (err) |
| 6531 | return err; |
| 6532 | |
| 6533 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6534 | if (!msg) |
| 6535 | return -ENOMEM; |
| 6536 | |
| 6537 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 6538 | dev, dst, mpp, &pinfo) < 0) { |
| 6539 | nlmsg_free(msg); |
| 6540 | return -ENOBUFS; |
| 6541 | } |
| 6542 | |
| 6543 | return genlmsg_reply(msg, info); |
| 6544 | } |
| 6545 | |
| 6546 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 6547 | struct netlink_callback *cb) |
| 6548 | { |
| 6549 | struct mpath_info pinfo; |
| 6550 | struct cfg80211_registered_device *rdev; |
| 6551 | struct wireless_dev *wdev; |
| 6552 | u8 dst[ETH_ALEN]; |
| 6553 | u8 mpp[ETH_ALEN]; |
| 6554 | int path_idx = cb->args[2]; |
| 6555 | int err; |
| 6556 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6557 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 6558 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6559 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6560 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6561 | |
| 6562 | if (!rdev->ops->dump_mpp) { |
| 6563 | err = -EOPNOTSUPP; |
| 6564 | goto out_err; |
| 6565 | } |
| 6566 | |
| 6567 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 6568 | err = -EOPNOTSUPP; |
| 6569 | goto out_err; |
| 6570 | } |
| 6571 | |
| 6572 | while (1) { |
| 6573 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 6574 | mpp, &pinfo); |
| 6575 | if (err == -ENOENT) |
| 6576 | break; |
| 6577 | if (err) |
| 6578 | goto out_err; |
| 6579 | |
| 6580 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 6581 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6582 | wdev->netdev, dst, mpp, |
| 6583 | &pinfo) < 0) |
| 6584 | goto out; |
| 6585 | |
| 6586 | path_idx++; |
| 6587 | } |
| 6588 | |
| 6589 | out: |
| 6590 | cb->args[2] = path_idx; |
| 6591 | err = skb->len; |
| 6592 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6593 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6594 | return err; |
| 6595 | } |
| 6596 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6597 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 6598 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6599 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6600 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6601 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6602 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6603 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6604 | |
| 6605 | memset(¶ms, 0, sizeof(params)); |
| 6606 | /* default to not changing parameters */ |
| 6607 | params.use_cts_prot = -1; |
| 6608 | params.use_short_preamble = -1; |
| 6609 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 6610 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 6611 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6612 | params.p2p_ctwindow = -1; |
| 6613 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6614 | |
| 6615 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 6616 | params.use_cts_prot = |
| 6617 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 6618 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 6619 | params.use_short_preamble = |
| 6620 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 6621 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 6622 | params.use_short_slot_time = |
| 6623 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 6624 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6625 | params.basic_rates = |
| 6626 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6627 | params.basic_rates_len = |
| 6628 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6629 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 6630 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 6631 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 6632 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 6633 | params.ht_opmode = |
| 6634 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6635 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6636 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 6637 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6638 | return -EINVAL; |
| 6639 | params.p2p_ctwindow = |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6640 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6641 | if (params.p2p_ctwindow != 0 && |
| 6642 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 6643 | return -EINVAL; |
| 6644 | } |
| 6645 | |
| 6646 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 6647 | u8 tmp; |
| 6648 | |
| 6649 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6650 | return -EINVAL; |
| 6651 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6652 | params.p2p_opp_ps = tmp; |
| 6653 | if (params.p2p_opp_ps && |
| 6654 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 6655 | return -EINVAL; |
| 6656 | } |
| 6657 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6658 | if (!rdev->ops->change_bss) |
| 6659 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6660 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6661 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6662 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6663 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6664 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6665 | wdev_lock(wdev); |
| 6666 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 6667 | wdev_unlock(wdev); |
| 6668 | |
| 6669 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6670 | } |
| 6671 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6672 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6673 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6674 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6675 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6676 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6677 | u32 owner_nlportid; |
| 6678 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 6679 | /* |
| 6680 | * You should only get this when cfg80211 hasn't yet initialized |
| 6681 | * completely when built-in to the kernel right between the time |
| 6682 | * window between nl80211_init() and regulatory_init(), if that is |
| 6683 | * even possible. |
| 6684 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6685 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 6686 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 6687 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6688 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 6689 | user_reg_hint_type = |
| 6690 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 6691 | else |
| 6692 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 6693 | |
| 6694 | switch (user_reg_hint_type) { |
| 6695 | case NL80211_USER_REG_HINT_USER: |
| 6696 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 6697 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6698 | return -EINVAL; |
| 6699 | |
| 6700 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6701 | return regulatory_hint_user(data, user_reg_hint_type); |
| 6702 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6703 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 6704 | owner_nlportid = info->snd_portid; |
| 6705 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 6706 | } else { |
| 6707 | owner_nlportid = 0; |
| 6708 | is_indoor = true; |
| 6709 | } |
| 6710 | |
| 6711 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6712 | default: |
| 6713 | return -EINVAL; |
| 6714 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6715 | } |
| 6716 | |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 6717 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
| 6718 | { |
| 6719 | return reg_reload_regdb(); |
| 6720 | } |
| 6721 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6722 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6723 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6724 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6726 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6727 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6728 | struct mesh_config cur_params; |
| 6729 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6730 | void *hdr; |
| 6731 | struct nlattr *pinfoattr; |
| 6732 | struct sk_buff *msg; |
| 6733 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6734 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6735 | return -EOPNOTSUPP; |
| 6736 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6737 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6738 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 6739 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6740 | wdev_lock(wdev); |
| 6741 | /* If not connected, get default parameters */ |
| 6742 | if (!wdev->mesh_id_len) |
| 6743 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 6744 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6745 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6746 | wdev_unlock(wdev); |
| 6747 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6748 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6749 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6750 | |
| 6751 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6752 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6753 | if (!msg) |
| 6754 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6755 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6756 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6757 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6758 | goto out; |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 6759 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6760 | if (!pinfoattr) |
| 6761 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6762 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 6763 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 6764 | cur_params.dot11MeshRetryTimeout) || |
| 6765 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 6766 | cur_params.dot11MeshConfirmTimeout) || |
| 6767 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 6768 | cur_params.dot11MeshHoldingTimeout) || |
| 6769 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 6770 | cur_params.dot11MeshMaxPeerLinks) || |
| 6771 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 6772 | cur_params.dot11MeshMaxRetries) || |
| 6773 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 6774 | cur_params.dot11MeshTTL) || |
| 6775 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 6776 | cur_params.element_ttl) || |
| 6777 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 6778 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 6779 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 6780 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6781 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 6782 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 6783 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 6784 | cur_params.path_refresh_time) || |
| 6785 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 6786 | cur_params.min_discovery_timeout) || |
| 6787 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 6788 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 6789 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 6790 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 6791 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 6792 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 6793 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 6794 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 6795 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 6796 | cur_params.dot11MeshHWMPRootMode) || |
| 6797 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 6798 | cur_params.dot11MeshHWMPRannInterval) || |
| 6799 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 6800 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 6801 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 6802 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 6803 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 6804 | cur_params.rssi_threshold) || |
| 6805 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6806 | cur_params.ht_opmode) || |
| 6807 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 6808 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 6809 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6810 | cur_params.dot11MeshHWMProotInterval) || |
| 6811 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6812 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 6813 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 6814 | cur_params.power_mode) || |
| 6815 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6816 | cur_params.dot11MeshAwakeWindowDuration) || |
| 6817 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 6818 | cur_params.plink_timeout) || |
| 6819 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, |
| 6820 | cur_params.dot11MeshConnectedToMeshGate)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6821 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6822 | nla_nest_end(msg, pinfoattr); |
| 6823 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6824 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6825 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6826 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6827 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6828 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6829 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6830 | } |
| 6831 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6832 | static const struct nla_policy |
| 6833 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
| 6834 | [NL80211_MESHCONF_RETRY_TIMEOUT] = |
| 6835 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 6836 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = |
| 6837 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 6838 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = |
| 6839 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 6840 | [NL80211_MESHCONF_MAX_PEER_LINKS] = |
| 6841 | NLA_POLICY_RANGE(NLA_U16, 0, 255), |
| 6842 | [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), |
| 6843 | [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 6844 | [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 6845 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 6846 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = |
| 6847 | NLA_POLICY_RANGE(NLA_U32, 1, 255), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6848 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 6849 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6850 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6851 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6852 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = |
| 6853 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6854 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = |
| 6855 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6856 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = |
| 6857 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6858 | [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), |
| 6859 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = |
| 6860 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6861 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 6862 | [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), |
| 6863 | [NL80211_MESHCONF_RSSI_THRESHOLD] = |
| 6864 | NLA_POLICY_RANGE(NLA_S32, -255, 0), |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6865 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6866 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6867 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = |
| 6868 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6869 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = |
| 6870 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6871 | [NL80211_MESHCONF_POWER_MODE] = |
| 6872 | NLA_POLICY_RANGE(NLA_U32, |
| 6873 | NL80211_MESH_POWER_ACTIVE, |
| 6874 | NL80211_MESH_POWER_MAX), |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6875 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6876 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 6877 | [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6878 | }; |
| 6879 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6880 | static const struct nla_policy |
| 6881 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6882 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6883 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 6884 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 6885 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6886 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6887 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 6888 | [NL80211_MESH_SETUP_IE] = |
| 6889 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 6890 | IEEE80211_MAX_DATA_LEN), |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6891 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6892 | }; |
| 6893 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6894 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6895 | struct mesh_config *cfg, |
| 6896 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6897 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6898 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6899 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6900 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6901 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6902 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ |
| 6903 | do { \ |
| 6904 | if (tb[attr]) { \ |
| 6905 | cfg->param = fn(tb[attr]); \ |
| 6906 | mask |= BIT((attr) - 1); \ |
| 6907 | } \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6908 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6909 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6910 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6911 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 6912 | if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6913 | return -EINVAL; |
| 6914 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6915 | /* This makes sure that there aren't more than 32 mesh config |
| 6916 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 6917 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 6918 | |
| 6919 | /* Fill in the params struct */ |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6920 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, |
| 6921 | NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 6922 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, |
| 6923 | NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 6924 | nla_get_u16); |
| 6925 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, |
| 6926 | NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 6927 | nla_get_u16); |
| 6928 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, |
| 6929 | NL80211_MESHCONF_MAX_PEER_LINKS, |
| 6930 | nla_get_u16); |
| 6931 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, |
| 6932 | NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 6933 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, |
| 6934 | NL80211_MESHCONF_TTL, nla_get_u8); |
| 6935 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, |
| 6936 | NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
| 6937 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, |
| 6938 | NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 6939 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6940 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6941 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6942 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6943 | nla_get_u32); |
| 6944 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, |
| 6945 | NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 6946 | nla_get_u8); |
| 6947 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, |
| 6948 | NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 6949 | nla_get_u32); |
| 6950 | if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && |
| 6951 | (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) |
| 6952 | return -EINVAL; |
| 6953 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, |
| 6954 | NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 6955 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6956 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6957 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6958 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6959 | nla_get_u32); |
| 6960 | if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && |
| 6961 | (cfg->dot11MeshHWMPactivePathTimeout < 1 || |
| 6962 | cfg->dot11MeshHWMPactivePathTimeout > 65535)) |
| 6963 | return -EINVAL; |
| 6964 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6965 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6966 | nla_get_u16); |
| 6967 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6968 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6969 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6970 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6971 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6972 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6973 | nla_get_u16); |
| 6974 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 6975 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 6976 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 6977 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 6978 | nla_get_u16); |
| 6979 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6980 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6981 | nla_get_u8); |
| 6982 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, |
| 6983 | NL80211_MESHCONF_FORWARDING, nla_get_u8); |
| 6984 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, |
| 6985 | NL80211_MESHCONF_RSSI_THRESHOLD, |
| 6986 | nla_get_s32); |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 6987 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, |
| 6988 | NL80211_MESHCONF_CONNECTED_TO_GATE, |
| 6989 | nla_get_u8); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6990 | /* |
| 6991 | * Check HT operation mode based on |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 6992 | * IEEE 802.11-2016 9.4.2.57 HT Operation element. |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6993 | */ |
| 6994 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 6995 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 6996 | |
| 6997 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 6998 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 6999 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 7000 | return -EINVAL; |
| 7001 | |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 7002 | /* NON_HT_STA bit is reserved, but some programs set it */ |
| 7003 | ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7004 | |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7005 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 7006 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7007 | } |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7008 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7009 | dot11MeshHWMPactivePathToRootTimeout, mask, |
| 7010 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 7011 | nla_get_u32); |
| 7012 | if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && |
| 7013 | (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || |
| 7014 | cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) |
| 7015 | return -EINVAL; |
| 7016 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, |
| 7017 | NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 7018 | nla_get_u16); |
| 7019 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, |
| 7020 | mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7021 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7022 | nla_get_u16); |
| 7023 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, |
| 7024 | NL80211_MESHCONF_POWER_MODE, nla_get_u32); |
| 7025 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, |
| 7026 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
| 7027 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, |
| 7028 | NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7029 | if (mask_out) |
| 7030 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7031 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7032 | return 0; |
| 7033 | |
| 7034 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 7035 | } |
| 7036 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7037 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 7038 | struct mesh_setup *setup) |
| 7039 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7041 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 7042 | |
| 7043 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 7044 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7045 | if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7046 | return -EINVAL; |
| 7047 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 7048 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 7049 | setup->sync_method = |
| 7050 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 7051 | IEEE80211_SYNC_METHOD_VENDOR : |
| 7052 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 7053 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7054 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 7055 | setup->path_sel_proto = |
| 7056 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 7057 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 7058 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 7059 | |
| 7060 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 7061 | setup->path_metric = |
| 7062 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 7063 | IEEE80211_PATH_METRIC_VENDOR : |
| 7064 | IEEE80211_PATH_METRIC_AIRTIME; |
| 7065 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7066 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7067 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7068 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7069 | setup->ie = nla_data(ieattr); |
| 7070 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7071 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7072 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 7073 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 7074 | return -EINVAL; |
| 7075 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 7076 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 7077 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7078 | if (setup->is_secure) |
| 7079 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7080 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 7081 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 7082 | if (!setup->user_mpm) |
| 7083 | return -EINVAL; |
| 7084 | setup->auth_id = |
| 7085 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 7086 | } |
| 7087 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7088 | return 0; |
| 7089 | } |
| 7090 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7091 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7092 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7093 | { |
| 7094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7095 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7096 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7097 | struct mesh_config cfg; |
| 7098 | u32 mask; |
| 7099 | int err; |
| 7100 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7101 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7102 | return -EOPNOTSUPP; |
| 7103 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7104 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7105 | return -EOPNOTSUPP; |
| 7106 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7107 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7108 | if (err) |
| 7109 | return err; |
| 7110 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7111 | wdev_lock(wdev); |
| 7112 | if (!wdev->mesh_id_len) |
| 7113 | err = -ENOLINK; |
| 7114 | |
| 7115 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7116 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7117 | |
| 7118 | wdev_unlock(wdev); |
| 7119 | |
| 7120 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7121 | } |
| 7122 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7123 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 7124 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7125 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7126 | struct nlattr *nl_reg_rules; |
| 7127 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7128 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7129 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 7130 | (regdom->dfs_region && |
| 7131 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7132 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7133 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7134 | nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7135 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7136 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7137 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7138 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7139 | struct nlattr *nl_reg_rule; |
| 7140 | const struct ieee80211_reg_rule *reg_rule; |
| 7141 | const struct ieee80211_freq_range *freq_range; |
| 7142 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7143 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7144 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7145 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7146 | freq_range = ®_rule->freq_range; |
| 7147 | power_rule = ®_rule->power_rule; |
| 7148 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7149 | nl_reg_rule = nla_nest_start_noflag(msg, i); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7150 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7151 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7152 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7153 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 7154 | if (!max_bandwidth_khz) |
| 7155 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 7156 | reg_rule); |
| 7157 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7158 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 7159 | reg_rule->flags) || |
| 7160 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 7161 | freq_range->start_freq_khz) || |
| 7162 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 7163 | freq_range->end_freq_khz) || |
| 7164 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7165 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7166 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 7167 | power_rule->max_antenna_gain) || |
| 7168 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 7169 | power_rule->max_eirp) || |
| 7170 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 7171 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7172 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7173 | |
| 7174 | nla_nest_end(msg, nl_reg_rule); |
| 7175 | } |
| 7176 | |
| 7177 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7178 | return 0; |
| 7179 | |
| 7180 | nla_put_failure: |
| 7181 | return -EMSGSIZE; |
| 7182 | } |
| 7183 | |
| 7184 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 7185 | { |
| 7186 | const struct ieee80211_regdomain *regdom = NULL; |
| 7187 | struct cfg80211_registered_device *rdev; |
| 7188 | struct wiphy *wiphy = NULL; |
| 7189 | struct sk_buff *msg; |
| 7190 | void *hdr; |
| 7191 | |
| 7192 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7193 | if (!msg) |
| 7194 | return -ENOBUFS; |
| 7195 | |
| 7196 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 7197 | NL80211_CMD_GET_REG); |
| 7198 | if (!hdr) |
| 7199 | goto put_failure; |
| 7200 | |
| 7201 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7202 | bool self_managed; |
| 7203 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7204 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 7205 | if (IS_ERR(rdev)) { |
| 7206 | nlmsg_free(msg); |
| 7207 | return PTR_ERR(rdev); |
| 7208 | } |
| 7209 | |
| 7210 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7211 | self_managed = wiphy->regulatory_flags & |
| 7212 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7213 | regdom = get_wiphy_regdom(wiphy); |
| 7214 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7215 | /* a self-managed-reg device must have a private regdom */ |
| 7216 | if (WARN_ON(!regdom && self_managed)) { |
| 7217 | nlmsg_free(msg); |
| 7218 | return -EINVAL; |
| 7219 | } |
| 7220 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7221 | if (regdom && |
| 7222 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7223 | goto nla_put_failure; |
| 7224 | } |
| 7225 | |
| 7226 | if (!wiphy && reg_last_request_cell_base() && |
| 7227 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7228 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7229 | goto nla_put_failure; |
| 7230 | |
| 7231 | rcu_read_lock(); |
| 7232 | |
| 7233 | if (!regdom) |
| 7234 | regdom = rcu_dereference(cfg80211_regdomain); |
| 7235 | |
| 7236 | if (nl80211_put_regdom(regdom, msg)) |
| 7237 | goto nla_put_failure_rcu; |
| 7238 | |
| 7239 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7240 | |
| 7241 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7242 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7243 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7244 | nla_put_failure_rcu: |
| 7245 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7246 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 7247 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 7248 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7249 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7250 | } |
| 7251 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7252 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 7253 | u32 seq, int flags, struct wiphy *wiphy, |
| 7254 | const struct ieee80211_regdomain *regdom) |
| 7255 | { |
| 7256 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 7257 | NL80211_CMD_GET_REG); |
| 7258 | |
| 7259 | if (!hdr) |
| 7260 | return -1; |
| 7261 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 7262 | genl_dump_check_consistent(cb, hdr); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7263 | |
| 7264 | if (nl80211_put_regdom(regdom, msg)) |
| 7265 | goto nla_put_failure; |
| 7266 | |
| 7267 | if (!wiphy && reg_last_request_cell_base() && |
| 7268 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7269 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7270 | goto nla_put_failure; |
| 7271 | |
| 7272 | if (wiphy && |
| 7273 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7274 | goto nla_put_failure; |
| 7275 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7276 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 7277 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 7278 | goto nla_put_failure; |
| 7279 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7280 | genlmsg_end(msg, hdr); |
| 7281 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7282 | |
| 7283 | nla_put_failure: |
| 7284 | genlmsg_cancel(msg, hdr); |
| 7285 | return -EMSGSIZE; |
| 7286 | } |
| 7287 | |
| 7288 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 7289 | struct netlink_callback *cb) |
| 7290 | { |
| 7291 | const struct ieee80211_regdomain *regdom = NULL; |
| 7292 | struct cfg80211_registered_device *rdev; |
| 7293 | int err, reg_idx, start = cb->args[2]; |
| 7294 | |
| 7295 | rtnl_lock(); |
| 7296 | |
| 7297 | if (cfg80211_regdomain && start == 0) { |
| 7298 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 7299 | NLM_F_MULTI, NULL, |
| 7300 | rtnl_dereference(cfg80211_regdomain)); |
| 7301 | if (err < 0) |
| 7302 | goto out_err; |
| 7303 | } |
| 7304 | |
| 7305 | /* the global regdom is idx 0 */ |
| 7306 | reg_idx = 1; |
| 7307 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 7308 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 7309 | if (!regdom) |
| 7310 | continue; |
| 7311 | |
| 7312 | if (++reg_idx <= start) |
| 7313 | continue; |
| 7314 | |
| 7315 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 7316 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 7317 | if (err < 0) { |
| 7318 | reg_idx--; |
| 7319 | break; |
| 7320 | } |
| 7321 | } |
| 7322 | |
| 7323 | cb->args[2] = reg_idx; |
| 7324 | err = skb->len; |
| 7325 | out_err: |
| 7326 | rtnl_unlock(); |
| 7327 | return err; |
| 7328 | } |
| 7329 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 7330 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 7331 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 7332 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 7333 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 7334 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 7335 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 7336 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 7337 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 7338 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 7339 | }; |
| 7340 | |
| 7341 | static int parse_reg_rule(struct nlattr *tb[], |
| 7342 | struct ieee80211_reg_rule *reg_rule) |
| 7343 | { |
| 7344 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 7345 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 7346 | |
| 7347 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 7348 | return -EINVAL; |
| 7349 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 7350 | return -EINVAL; |
| 7351 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 7352 | return -EINVAL; |
| 7353 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 7354 | return -EINVAL; |
| 7355 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 7356 | return -EINVAL; |
| 7357 | |
| 7358 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 7359 | |
| 7360 | freq_range->start_freq_khz = |
| 7361 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 7362 | freq_range->end_freq_khz = |
| 7363 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 7364 | freq_range->max_bandwidth_khz = |
| 7365 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 7366 | |
| 7367 | power_rule->max_eirp = |
| 7368 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 7369 | |
| 7370 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 7371 | power_rule->max_antenna_gain = |
| 7372 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 7373 | |
| 7374 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 7375 | reg_rule->dfs_cac_ms = |
| 7376 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 7377 | |
| 7378 | return 0; |
| 7379 | } |
| 7380 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7381 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 7382 | { |
| 7383 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 7384 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 7385 | char *alpha2; |
| 7386 | int rem_reg_rules, r; |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 7387 | u32 num_rules = 0, rule_idx = 0; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 7388 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 7389 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7390 | |
| 7391 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 7392 | return -EINVAL; |
| 7393 | |
| 7394 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 7395 | return -EINVAL; |
| 7396 | |
| 7397 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 7398 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 7399 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 7400 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 7401 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7402 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 7403 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7404 | num_rules++; |
| 7405 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 7406 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7407 | } |
| 7408 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 7409 | if (!reg_is_valid_request(alpha2)) |
| 7410 | return -EINVAL; |
| 7411 | |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 7412 | rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 7413 | if (!rd) |
| 7414 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7415 | |
| 7416 | rd->n_reg_rules = num_rules; |
| 7417 | rd->alpha2[0] = alpha2[0]; |
| 7418 | rd->alpha2[1] = alpha2[1]; |
| 7419 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 7420 | /* |
| 7421 | * Disable DFS master mode if the DFS region was |
| 7422 | * not supported or known on this kernel. |
| 7423 | */ |
| 7424 | if (reg_supported_dfs_region(dfs_region)) |
| 7425 | rd->dfs_region = dfs_region; |
| 7426 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7427 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 7428 | rem_reg_rules) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7429 | r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, |
| 7430 | nl_reg_rule, reg_rule_policy, |
| 7431 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7432 | if (r) |
| 7433 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7434 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 7435 | if (r) |
| 7436 | goto bad_reg; |
| 7437 | |
| 7438 | rule_idx++; |
| 7439 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7440 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 7441 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7442 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7443 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7444 | } |
| 7445 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 7446 | /* set_regdom takes ownership of rd */ |
| 7447 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 7448 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7449 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7450 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7451 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 7452 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7453 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7454 | static int validate_scan_freqs(struct nlattr *freqs) |
| 7455 | { |
| 7456 | struct nlattr *attr1, *attr2; |
| 7457 | int n_channels = 0, tmp1, tmp2; |
| 7458 | |
Srinivas Dasari | d7f13f7 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 7459 | nla_for_each_nested(attr1, freqs, tmp1) |
| 7460 | if (nla_len(attr1) != sizeof(u32)) |
| 7461 | return 0; |
| 7462 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7463 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 7464 | n_channels++; |
| 7465 | /* |
| 7466 | * Some hardware has a limited channel list for |
| 7467 | * scanning, and it is pretty much nonsensical |
| 7468 | * to scan for a channel twice, so disallow that |
| 7469 | * and don't require drivers to check that the |
| 7470 | * channel list they get isn't longer than what |
| 7471 | * they can scan, as long as they can scan all |
| 7472 | * the channels they registered at once. |
| 7473 | */ |
| 7474 | nla_for_each_nested(attr2, freqs, tmp2) |
| 7475 | if (attr1 != attr2 && |
| 7476 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 7477 | return 0; |
| 7478 | } |
| 7479 | |
| 7480 | return n_channels; |
| 7481 | } |
| 7482 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7483 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7484 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7485 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7486 | } |
| 7487 | |
| 7488 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 7489 | struct cfg80211_bss_selection *bss_select) |
| 7490 | { |
| 7491 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 7492 | struct nlattr *nest; |
| 7493 | int err; |
| 7494 | bool found = false; |
| 7495 | int i; |
| 7496 | |
| 7497 | /* only process one nested attribute */ |
| 7498 | nest = nla_data(nla); |
| 7499 | if (!nla_ok(nest, nla_len(nest))) |
| 7500 | return -EINVAL; |
| 7501 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7502 | err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, |
| 7503 | nest, nl80211_bss_select_policy, |
| 7504 | NULL); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7505 | if (err) |
| 7506 | return err; |
| 7507 | |
| 7508 | /* only one attribute may be given */ |
| 7509 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 7510 | if (attr[i]) { |
| 7511 | if (found) |
| 7512 | return -EINVAL; |
| 7513 | found = true; |
| 7514 | } |
| 7515 | } |
| 7516 | |
| 7517 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 7518 | |
| 7519 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 7520 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 7521 | |
| 7522 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 7523 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 7524 | bss_select->param.band_pref = |
| 7525 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 7526 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 7527 | return -EINVAL; |
| 7528 | } |
| 7529 | |
| 7530 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 7531 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 7532 | |
| 7533 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 7534 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 7535 | bss_select->param.adjust.band = adj_param->band; |
| 7536 | bss_select->param.adjust.delta = adj_param->delta; |
| 7537 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 7538 | return -EINVAL; |
| 7539 | } |
| 7540 | |
| 7541 | /* user-space did not provide behaviour attribute */ |
| 7542 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 7543 | return -EINVAL; |
| 7544 | |
| 7545 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 7546 | return -EINVAL; |
| 7547 | |
| 7548 | return 0; |
| 7549 | } |
| 7550 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 7551 | int nl80211_parse_random_mac(struct nlattr **attrs, |
| 7552 | u8 *mac_addr, u8 *mac_addr_mask) |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7553 | { |
| 7554 | int i; |
| 7555 | |
| 7556 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 7557 | eth_zero_addr(mac_addr); |
| 7558 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7559 | mac_addr[0] = 0x2; |
| 7560 | mac_addr_mask[0] = 0x3; |
| 7561 | |
| 7562 | return 0; |
| 7563 | } |
| 7564 | |
| 7565 | /* need both or none */ |
| 7566 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 7567 | return -EINVAL; |
| 7568 | |
| 7569 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 7570 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 7571 | |
| 7572 | /* don't allow or configure an mcast address */ |
| 7573 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 7574 | is_multicast_ether_addr(mac_addr)) |
| 7575 | return -EINVAL; |
| 7576 | |
| 7577 | /* |
| 7578 | * allow users to pass a MAC address that has bits set outside |
| 7579 | * of the mask, but don't bother drivers with having to deal |
| 7580 | * with such bits |
| 7581 | */ |
| 7582 | for (i = 0; i < ETH_ALEN; i++) |
| 7583 | mac_addr[i] &= mac_addr_mask[i]; |
| 7584 | |
| 7585 | return 0; |
| 7586 | } |
| 7587 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 7588 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 7589 | { |
| 7590 | ASSERT_WDEV_LOCK(wdev); |
| 7591 | |
| 7592 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 7593 | return true; |
| 7594 | |
| 7595 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 7596 | return true; |
| 7597 | |
| 7598 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 7599 | } |
| 7600 | |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 7601 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, |
| 7602 | enum nl80211_ext_feature_index feat) |
| 7603 | { |
| 7604 | if (!(flags & flag)) |
| 7605 | return true; |
| 7606 | if (wiphy_ext_feature_isset(wiphy, feat)) |
| 7607 | return true; |
| 7608 | return false; |
| 7609 | } |
| 7610 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7611 | static int |
| 7612 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 7613 | void *request, struct nlattr **attrs, |
| 7614 | bool is_sched_scan) |
| 7615 | { |
| 7616 | u8 *mac_addr, *mac_addr_mask; |
| 7617 | u32 *flags; |
| 7618 | enum nl80211_feature_flags randomness_flag; |
| 7619 | |
| 7620 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) |
| 7621 | return 0; |
| 7622 | |
| 7623 | if (is_sched_scan) { |
| 7624 | struct cfg80211_sched_scan_request *req = request; |
| 7625 | |
| 7626 | randomness_flag = wdev ? |
| 7627 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : |
| 7628 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7629 | flags = &req->flags; |
| 7630 | mac_addr = req->mac_addr; |
| 7631 | mac_addr_mask = req->mac_addr_mask; |
| 7632 | } else { |
| 7633 | struct cfg80211_scan_request *req = request; |
| 7634 | |
| 7635 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 7636 | flags = &req->flags; |
| 7637 | mac_addr = req->mac_addr; |
| 7638 | mac_addr_mask = req->mac_addr_mask; |
| 7639 | } |
| 7640 | |
| 7641 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); |
| 7642 | |
Sunil Dutt | 5037a00 | 2018-01-25 17:13:37 +0200 | [diff] [blame] | 7643 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 7644 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 7645 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7646 | NL80211_SCAN_FLAG_LOW_SPAN, |
| 7647 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || |
| 7648 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7649 | NL80211_SCAN_FLAG_LOW_POWER, |
| 7650 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || |
| 7651 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7652 | NL80211_SCAN_FLAG_HIGH_ACCURACY, |
| 7653 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || |
| 7654 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7655 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, |
| 7656 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || |
| 7657 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7658 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, |
| 7659 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || |
| 7660 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7661 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, |
| 7662 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || |
| 7663 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7664 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, |
Johannes Berg | 2e076f1 | 2018-05-28 15:47:40 +0200 | [diff] [blame] | 7665 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || |
| 7666 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7667 | NL80211_SCAN_FLAG_RANDOM_SN, |
| 7668 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || |
| 7669 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7670 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, |
| 7671 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7672 | return -EOPNOTSUPP; |
| 7673 | |
| 7674 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 7675 | int err; |
| 7676 | |
| 7677 | if (!(wiphy->features & randomness_flag) || |
| 7678 | (wdev && wdev->current_bss)) |
| 7679 | return -EOPNOTSUPP; |
| 7680 | |
| 7681 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); |
| 7682 | if (err) |
| 7683 | return err; |
| 7684 | } |
| 7685 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7686 | return 0; |
| 7687 | } |
| 7688 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7689 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 7690 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7691 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7692 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7693 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7694 | struct nlattr *attr; |
| 7695 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7696 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7697 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7698 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7699 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7700 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 7701 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 7702 | return -EOPNOTSUPP; |
| 7703 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7704 | if (!rdev->ops->scan) |
| 7705 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7706 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 7707 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7708 | err = -EBUSY; |
| 7709 | goto unlock; |
| 7710 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7711 | |
| 7712 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7713 | n_channels = validate_scan_freqs( |
| 7714 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7715 | if (!n_channels) { |
| 7716 | err = -EINVAL; |
| 7717 | goto unlock; |
| 7718 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7719 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7720 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7721 | } |
| 7722 | |
| 7723 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7724 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 7725 | n_ssids++; |
| 7726 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7727 | if (n_ssids > wiphy->max_scan_ssids) { |
| 7728 | err = -EINVAL; |
| 7729 | goto unlock; |
| 7730 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7731 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7732 | if (info->attrs[NL80211_ATTR_IE]) |
| 7733 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7734 | else |
| 7735 | ie_len = 0; |
| 7736 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7737 | if (ie_len > wiphy->max_scan_ie_len) { |
| 7738 | err = -EINVAL; |
| 7739 | goto unlock; |
| 7740 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 7741 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7742 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7743 | + sizeof(*request->ssids) * n_ssids |
| 7744 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7745 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7746 | if (!request) { |
| 7747 | err = -ENOMEM; |
| 7748 | goto unlock; |
| 7749 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7750 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7751 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 7752 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7753 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7754 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7755 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7756 | request->ie = (void *)(request->ssids + n_ssids); |
| 7757 | else |
| 7758 | request->ie = (void *)(request->channels + n_channels); |
| 7759 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7760 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7761 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7762 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 7763 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7764 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7765 | struct ieee80211_channel *chan; |
| 7766 | |
| 7767 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7768 | |
| 7769 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7770 | err = -EINVAL; |
| 7771 | goto out_free; |
| 7772 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7773 | |
| 7774 | /* ignore disabled channels */ |
| 7775 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7776 | continue; |
| 7777 | |
| 7778 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7779 | i++; |
| 7780 | } |
| 7781 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7782 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7783 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7784 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7785 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7786 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7787 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7788 | if (!wiphy->bands[band]) |
| 7789 | continue; |
| 7790 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7791 | struct ieee80211_channel *chan; |
| 7792 | |
| 7793 | chan = &wiphy->bands[band]->channels[j]; |
| 7794 | |
| 7795 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7796 | continue; |
| 7797 | |
| 7798 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7799 | i++; |
| 7800 | } |
| 7801 | } |
| 7802 | } |
| 7803 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7804 | if (!i) { |
| 7805 | err = -EINVAL; |
| 7806 | goto out_free; |
| 7807 | } |
| 7808 | |
| 7809 | request->n_channels = i; |
| 7810 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 7811 | wdev_lock(wdev); |
| 7812 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 7813 | struct ieee80211_channel *chan; |
| 7814 | |
| 7815 | if (request->n_channels != 1) { |
| 7816 | wdev_unlock(wdev); |
| 7817 | err = -EBUSY; |
| 7818 | goto out_free; |
| 7819 | } |
| 7820 | |
| 7821 | chan = request->channels[0]; |
| 7822 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 7823 | wdev_unlock(wdev); |
| 7824 | err = -EBUSY; |
| 7825 | goto out_free; |
| 7826 | } |
| 7827 | } |
| 7828 | wdev_unlock(wdev); |
| 7829 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7830 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7831 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7832 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7833 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7834 | err = -EINVAL; |
| 7835 | goto out_free; |
| 7836 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7837 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7838 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7839 | i++; |
| 7840 | } |
| 7841 | } |
| 7842 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7843 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7844 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54b | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 7845 | memcpy((void *)request->ie, |
| 7846 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7847 | request->ie_len); |
| 7848 | } |
| 7849 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7850 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 7851 | if (wiphy->bands[i]) |
| 7852 | request->rates[i] = |
| 7853 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7854 | |
| 7855 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 7856 | nla_for_each_nested(attr, |
| 7857 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 7858 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7859 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7860 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7861 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7862 | err = -EINVAL; |
| 7863 | goto out_free; |
| 7864 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 7865 | |
| 7866 | if (!wiphy->bands[band]) |
| 7867 | continue; |
| 7868 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7869 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 7870 | nla_data(attr), |
| 7871 | nla_len(attr), |
| 7872 | &request->rates[band]); |
| 7873 | if (err) |
| 7874 | goto out_free; |
| 7875 | } |
| 7876 | } |
| 7877 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7878 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 7879 | if (!wiphy_ext_feature_isset(wiphy, |
| 7880 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 7881 | err = -EOPNOTSUPP; |
| 7882 | goto out_free; |
| 7883 | } |
| 7884 | |
| 7885 | request->duration = |
| 7886 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 7887 | request->duration_mandatory = |
| 7888 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 7889 | } |
| 7890 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7891 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
| 7892 | false); |
| 7893 | if (err) |
| 7894 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7895 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7896 | request->no_cck = |
| 7897 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7898 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 7899 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 7900 | * BSSID to scan for. This was problematic because that same attribute |
| 7901 | * was already used for another purpose (local random MAC address). The |
| 7902 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 7903 | * compatibility with older userspace components, also use the |
| 7904 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 7905 | * the specific BSSID use case instead of the random MAC address |
| 7906 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 7907 | */ |
| 7908 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 7909 | memcpy(request->bssid, |
| 7910 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 7911 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 7912 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 7913 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 7914 | ETH_ALEN); |
| 7915 | else |
| 7916 | eth_broadcast_addr(request->bssid); |
| 7917 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7918 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7919 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7920 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7921 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7922 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7923 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7924 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7925 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7926 | nl80211_send_scan_start(rdev, wdev); |
| 7927 | if (wdev->netdev) |
| 7928 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7929 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7930 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7931 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7932 | kfree(request); |
| 7933 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7934 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7935 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7936 | return err; |
| 7937 | } |
| 7938 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 7939 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 7940 | { |
| 7941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7942 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7943 | |
| 7944 | if (!rdev->ops->abort_scan) |
| 7945 | return -EOPNOTSUPP; |
| 7946 | |
| 7947 | if (rdev->scan_msg) |
| 7948 | return 0; |
| 7949 | |
| 7950 | if (!rdev->scan_req) |
| 7951 | return -ENOENT; |
| 7952 | |
| 7953 | rdev_abort_scan(rdev, wdev); |
| 7954 | return 0; |
| 7955 | } |
| 7956 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7957 | static int |
| 7958 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 7959 | struct cfg80211_sched_scan_request *request, |
| 7960 | struct nlattr **attrs) |
| 7961 | { |
| 7962 | int tmp, err, i = 0; |
| 7963 | struct nlattr *attr; |
| 7964 | |
| 7965 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 7966 | u32 interval; |
| 7967 | |
| 7968 | /* |
| 7969 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 7970 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7971 | * case one scan plan will be set with the specified scan |
| 7972 | * interval and infinite number of iterations. |
| 7973 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7974 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 7975 | if (!interval) |
| 7976 | return -EINVAL; |
| 7977 | |
| 7978 | request->scan_plans[0].interval = |
| 7979 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 7980 | if (!request->scan_plans[0].interval) |
| 7981 | return -EINVAL; |
| 7982 | |
| 7983 | if (request->scan_plans[0].interval > |
| 7984 | wiphy->max_sched_scan_plan_interval) |
| 7985 | request->scan_plans[0].interval = |
| 7986 | wiphy->max_sched_scan_plan_interval; |
| 7987 | |
| 7988 | return 0; |
| 7989 | } |
| 7990 | |
| 7991 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 7992 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 7993 | |
| 7994 | if (WARN_ON(i >= n_plans)) |
| 7995 | return -EINVAL; |
| 7996 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7997 | err = nla_parse_nested_deprecated(plan, |
| 7998 | NL80211_SCHED_SCAN_PLAN_MAX, |
| 7999 | attr, nl80211_plan_policy, |
| 8000 | NULL); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8001 | if (err) |
| 8002 | return err; |
| 8003 | |
| 8004 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 8005 | return -EINVAL; |
| 8006 | |
| 8007 | request->scan_plans[i].interval = |
| 8008 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 8009 | if (!request->scan_plans[i].interval || |
| 8010 | request->scan_plans[i].interval > |
| 8011 | wiphy->max_sched_scan_plan_interval) |
| 8012 | return -EINVAL; |
| 8013 | |
| 8014 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 8015 | request->scan_plans[i].iterations = |
| 8016 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 8017 | if (!request->scan_plans[i].iterations || |
| 8018 | (request->scan_plans[i].iterations > |
| 8019 | wiphy->max_sched_scan_plan_iterations)) |
| 8020 | return -EINVAL; |
| 8021 | } else if (i < n_plans - 1) { |
| 8022 | /* |
| 8023 | * All scan plans but the last one must specify |
| 8024 | * a finite number of iterations |
| 8025 | */ |
| 8026 | return -EINVAL; |
| 8027 | } |
| 8028 | |
| 8029 | i++; |
| 8030 | } |
| 8031 | |
| 8032 | /* |
| 8033 | * The last scan plan must not specify the number of |
| 8034 | * iterations, it is supposed to run infinitely |
| 8035 | */ |
| 8036 | if (request->scan_plans[n_plans - 1].iterations) |
| 8037 | return -EINVAL; |
| 8038 | |
| 8039 | return 0; |
| 8040 | } |
| 8041 | |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 8042 | static int |
| 8043 | nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, |
| 8044 | struct cfg80211_match_set *match_sets, |
| 8045 | struct nlattr *tb_band_rssi, |
| 8046 | s32 rssi_thold) |
| 8047 | { |
| 8048 | struct nlattr *attr; |
| 8049 | int i, tmp, ret = 0; |
| 8050 | |
| 8051 | if (!wiphy_ext_feature_isset(wiphy, |
| 8052 | NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { |
| 8053 | if (tb_band_rssi) |
| 8054 | ret = -EOPNOTSUPP; |
| 8055 | else |
| 8056 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8057 | match_sets->per_band_rssi_thold[i] = |
| 8058 | NL80211_SCAN_RSSI_THOLD_OFF; |
| 8059 | return ret; |
| 8060 | } |
| 8061 | |
| 8062 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8063 | match_sets->per_band_rssi_thold[i] = rssi_thold; |
| 8064 | |
| 8065 | nla_for_each_nested(attr, tb_band_rssi, tmp) { |
| 8066 | enum nl80211_band band = nla_type(attr); |
| 8067 | |
| 8068 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 8069 | return -EINVAL; |
| 8070 | |
| 8071 | match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); |
| 8072 | } |
| 8073 | |
| 8074 | return 0; |
| 8075 | } |
| 8076 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8077 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8078 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8079 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8080 | { |
| 8081 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8082 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8083 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8084 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8085 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8086 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8087 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8088 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8089 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8090 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8091 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8092 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8093 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8094 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 8095 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8096 | } |
| 8097 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8098 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 8099 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8100 | tmp) |
| 8101 | n_ssids++; |
| 8102 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 8103 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8104 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8105 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8106 | /* |
| 8107 | * First, count the number of 'real' matchsets. Due to an issue with |
| 8108 | * the old implementation, matchsets containing only the RSSI attribute |
| 8109 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 8110 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 8111 | * all APs with a strong RSSI. This is needed to be compatible with |
| 8112 | * older userspace that treated a matchset with only the RSSI as the |
| 8113 | * global RSSI for all other matchsets - if there are other matchsets. |
| 8114 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8115 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8116 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8117 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8118 | tmp) { |
| 8119 | struct nlattr *rssi; |
| 8120 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8121 | err = nla_parse_nested_deprecated(tb, |
| 8122 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8123 | attr, |
| 8124 | nl80211_match_policy, |
| 8125 | NULL); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8126 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8127 | return ERR_PTR(err); |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8128 | |
| 8129 | /* SSID and BSSID are mutually exclusive */ |
| 8130 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 8131 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 8132 | return ERR_PTR(-EINVAL); |
| 8133 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8134 | /* add other standalone attributes here */ |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8135 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 8136 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8137 | n_match_sets++; |
| 8138 | continue; |
| 8139 | } |
| 8140 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8141 | if (rssi) |
| 8142 | default_match_rssi = nla_get_s32(rssi); |
| 8143 | } |
| 8144 | } |
| 8145 | |
| 8146 | /* However, if there's no other matchset, add the RSSI one */ |
| 8147 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 8148 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8149 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8150 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8151 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8152 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8153 | if (attrs[NL80211_ATTR_IE]) |
| 8154 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8155 | else |
| 8156 | ie_len = 0; |
| 8157 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 8158 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8159 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 8160 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8161 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8162 | /* |
| 8163 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 8164 | * each scan plan already specifies its own interval |
| 8165 | */ |
| 8166 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8167 | return ERR_PTR(-EINVAL); |
| 8168 | |
| 8169 | nla_for_each_nested(attr, |
| 8170 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 8171 | n_plans++; |
| 8172 | } else { |
| 8173 | /* |
| 8174 | * The scan interval attribute is kept for backward |
| 8175 | * compatibility. If no scan plans are specified and sched scan |
| 8176 | * interval is specified, one scan plan will be set with this |
| 8177 | * scan interval and infinite number of iterations. |
| 8178 | */ |
| 8179 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8180 | return ERR_PTR(-EINVAL); |
| 8181 | |
| 8182 | n_plans = 1; |
| 8183 | } |
| 8184 | |
| 8185 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 8186 | return ERR_PTR(-EINVAL); |
| 8187 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 8188 | if (!wiphy_ext_feature_isset( |
| 8189 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 8190 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 8191 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 8192 | return ERR_PTR(-EINVAL); |
| 8193 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8194 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8195 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8196 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8197 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8198 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8199 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8200 | if (!request) |
| 8201 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8202 | |
| 8203 | if (n_ssids) |
| 8204 | request->ssids = (void *)&request->channels[n_channels]; |
| 8205 | request->n_ssids = n_ssids; |
| 8206 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8207 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8208 | request->ie = (void *)(request->ssids + n_ssids); |
| 8209 | else |
| 8210 | request->ie = (void *)(request->channels + n_channels); |
| 8211 | } |
| 8212 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8213 | if (n_match_sets) { |
| 8214 | if (request->ie) |
| 8215 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8216 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8217 | request->match_sets = |
| 8218 | (void *)(request->ssids + n_ssids); |
| 8219 | else |
| 8220 | request->match_sets = |
| 8221 | (void *)(request->channels + n_channels); |
| 8222 | } |
| 8223 | request->n_match_sets = n_match_sets; |
| 8224 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8225 | if (n_match_sets) |
| 8226 | request->scan_plans = (void *)(request->match_sets + |
| 8227 | n_match_sets); |
| 8228 | else if (request->ie) |
| 8229 | request->scan_plans = (void *)(request->ie + ie_len); |
| 8230 | else if (n_ssids) |
| 8231 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 8232 | else |
| 8233 | request->scan_plans = (void *)(request->channels + n_channels); |
| 8234 | |
| 8235 | request->n_scan_plans = n_plans; |
| 8236 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8237 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8238 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8239 | /* user specified, bail out if channel not found */ |
| 8240 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8241 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8242 | tmp) { |
| 8243 | struct ieee80211_channel *chan; |
| 8244 | |
| 8245 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 8246 | |
| 8247 | if (!chan) { |
| 8248 | err = -EINVAL; |
| 8249 | goto out_free; |
| 8250 | } |
| 8251 | |
| 8252 | /* ignore disabled channels */ |
| 8253 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8254 | continue; |
| 8255 | |
| 8256 | request->channels[i] = chan; |
| 8257 | i++; |
| 8258 | } |
| 8259 | } else { |
| 8260 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8261 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8262 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8263 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8264 | if (!wiphy->bands[band]) |
| 8265 | continue; |
| 8266 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 8267 | struct ieee80211_channel *chan; |
| 8268 | |
| 8269 | chan = &wiphy->bands[band]->channels[j]; |
| 8270 | |
| 8271 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8272 | continue; |
| 8273 | |
| 8274 | request->channels[i] = chan; |
| 8275 | i++; |
| 8276 | } |
| 8277 | } |
| 8278 | } |
| 8279 | |
| 8280 | if (!i) { |
| 8281 | err = -EINVAL; |
| 8282 | goto out_free; |
| 8283 | } |
| 8284 | |
| 8285 | request->n_channels = i; |
| 8286 | |
| 8287 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8288 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8289 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8290 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8291 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8292 | err = -EINVAL; |
| 8293 | goto out_free; |
| 8294 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8295 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8296 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 8297 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8298 | i++; |
| 8299 | } |
| 8300 | } |
| 8301 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8302 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8303 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8304 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8305 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8306 | tmp) { |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8307 | struct nlattr *ssid, *bssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8308 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8309 | err = nla_parse_nested_deprecated(tb, |
| 8310 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8311 | attr, |
| 8312 | nl80211_match_policy, |
| 8313 | NULL); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8314 | if (err) |
| 8315 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 8316 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8317 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8318 | |
| 8319 | if (!ssid && !bssid) { |
| 8320 | i++; |
| 8321 | continue; |
| 8322 | } |
| 8323 | |
| 8324 | if (WARN_ON(i >= n_match_sets)) { |
| 8325 | /* this indicates a programming error, |
| 8326 | * the loop above should have verified |
| 8327 | * things properly |
| 8328 | */ |
| 8329 | err = -EINVAL; |
| 8330 | goto out_free; |
| 8331 | } |
| 8332 | |
| 8333 | if (ssid) { |
| 8334 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8335 | err = -EINVAL; |
| 8336 | goto out_free; |
| 8337 | } |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8338 | memcpy(request->match_sets[i].ssid.ssid, |
| 8339 | nla_data(ssid), nla_len(ssid)); |
| 8340 | request->match_sets[i].ssid.ssid_len = |
| 8341 | nla_len(ssid); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8342 | } |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8343 | if (bssid) { |
| 8344 | if (nla_len(bssid) != ETH_ALEN) { |
| 8345 | err = -EINVAL; |
| 8346 | goto out_free; |
| 8347 | } |
| 8348 | memcpy(request->match_sets[i].bssid, |
| 8349 | nla_data(bssid), ETH_ALEN); |
| 8350 | } |
| 8351 | |
| 8352 | /* special attribute - old implementation w/a */ |
| 8353 | request->match_sets[i].rssi_thold = default_match_rssi; |
| 8354 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8355 | if (rssi) |
| 8356 | request->match_sets[i].rssi_thold = |
| 8357 | nla_get_s32(rssi); |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 8358 | |
| 8359 | /* Parse per band RSSI attribute */ |
| 8360 | err = nl80211_parse_sched_scan_per_band_rssi(wiphy, |
| 8361 | &request->match_sets[i], |
| 8362 | tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], |
| 8363 | request->match_sets[i].rssi_thold); |
| 8364 | if (err) |
| 8365 | goto out_free; |
| 8366 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8367 | i++; |
| 8368 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8369 | |
| 8370 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 8371 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8372 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 8373 | |
| 8374 | request->min_rssi_thold = INT_MAX; |
| 8375 | for (i = 0; i < n_match_sets; i++) |
| 8376 | request->min_rssi_thold = |
| 8377 | min(request->match_sets[i].rssi_thold, |
| 8378 | request->min_rssi_thold); |
| 8379 | } else { |
| 8380 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8381 | } |
| 8382 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 8383 | if (ie_len) { |
| 8384 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8385 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8386 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8387 | request->ie_len); |
| 8388 | } |
| 8389 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8390 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
| 8391 | if (err) |
| 8392 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8393 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 8394 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 8395 | request->delay = |
| 8396 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 8397 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 8398 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 8399 | request->relative_rssi = nla_get_s8( |
| 8400 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 8401 | request->relative_rssi_set = true; |
| 8402 | } |
| 8403 | |
| 8404 | if (request->relative_rssi_set && |
| 8405 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 8406 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 8407 | |
| 8408 | rssi_adjust = nla_data( |
| 8409 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 8410 | request->rssi_adjust.band = rssi_adjust->band; |
| 8411 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 8412 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 8413 | err = -EINVAL; |
| 8414 | goto out_free; |
| 8415 | } |
| 8416 | } |
| 8417 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8418 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 8419 | if (err) |
| 8420 | goto out_free; |
| 8421 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 8422 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8423 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8424 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8425 | |
| 8426 | out_free: |
| 8427 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8428 | return ERR_PTR(err); |
| 8429 | } |
| 8430 | |
| 8431 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 8432 | struct genl_info *info) |
| 8433 | { |
| 8434 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8435 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8436 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8437 | struct cfg80211_sched_scan_request *sched_scan_req; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8438 | bool want_multi; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8439 | int err; |
| 8440 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8441 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8442 | return -EOPNOTSUPP; |
| 8443 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8444 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 8445 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 8446 | if (err) |
| 8447 | return err; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8448 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8449 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8450 | info->attrs, |
| 8451 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8452 | |
| 8453 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8454 | if (err) |
| 8455 | goto out_err; |
| 8456 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8457 | /* leave request id zero for legacy request |
| 8458 | * or if driver does not support multi-scheduled scan |
| 8459 | */ |
Denis Kenzior | 2fd351a | 2019-10-08 11:43:50 -0500 | [diff] [blame] | 8460 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) |
| 8461 | sched_scan_req->reqid = cfg80211_assign_cookie(rdev); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8462 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8463 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8464 | if (err) |
| 8465 | goto out_free; |
| 8466 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8467 | sched_scan_req->dev = dev; |
| 8468 | sched_scan_req->wiphy = &rdev->wiphy; |
| 8469 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 8470 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 8471 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 8472 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8473 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8474 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 8475 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8476 | return 0; |
| 8477 | |
| 8478 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8479 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8480 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8481 | return err; |
| 8482 | } |
| 8483 | |
| 8484 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 8485 | struct genl_info *info) |
| 8486 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8487 | struct cfg80211_sched_scan_request *req; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8489 | u64 cookie; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8490 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8491 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8492 | return -EOPNOTSUPP; |
| 8493 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8494 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 8495 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8496 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 8497 | } |
| 8498 | |
| 8499 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 8500 | struct cfg80211_sched_scan_request, |
| 8501 | list); |
| 8502 | if (!req || req->reqid || |
| 8503 | (req->owner_nlportid && |
| 8504 | req->owner_nlportid != info->snd_portid)) |
| 8505 | return -ENOENT; |
| 8506 | |
| 8507 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8508 | } |
| 8509 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8510 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 8511 | struct genl_info *info) |
| 8512 | { |
| 8513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8514 | struct net_device *dev = info->user_ptr[1]; |
| 8515 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8516 | struct wiphy *wiphy = wdev->wiphy; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8517 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 8518 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8519 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8520 | int err; |
| 8521 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8522 | dfs_region = reg_get_dfs_region(wiphy); |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 8523 | if (dfs_region == NL80211_DFS_UNSET) |
| 8524 | return -EINVAL; |
| 8525 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8526 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8527 | if (err) |
| 8528 | return err; |
| 8529 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 8530 | if (netif_carrier_ok(dev)) |
| 8531 | return -EBUSY; |
| 8532 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8533 | if (wdev->cac_started) |
| 8534 | return -EBUSY; |
| 8535 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8536 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8537 | if (err < 0) |
| 8538 | return err; |
| 8539 | |
| 8540 | if (err == 0) |
| 8541 | return -EINVAL; |
| 8542 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8543 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8544 | return -EINVAL; |
| 8545 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8546 | /* CAC start is offloaded to HW and can't be started manually */ |
| 8547 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) |
| 8548 | return -EOPNOTSUPP; |
| 8549 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8550 | if (!rdev->ops->start_radar_detection) |
| 8551 | return -EOPNOTSUPP; |
| 8552 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8553 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 8554 | if (WARN_ON(!cac_time_ms)) |
| 8555 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 8556 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8557 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8558 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 8559 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8560 | wdev->cac_started = true; |
| 8561 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8562 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8563 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8564 | return err; |
| 8565 | } |
| 8566 | |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 8567 | static int nl80211_notify_radar_detection(struct sk_buff *skb, |
| 8568 | struct genl_info *info) |
| 8569 | { |
| 8570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8571 | struct net_device *dev = info->user_ptr[1]; |
| 8572 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8573 | struct wiphy *wiphy = wdev->wiphy; |
| 8574 | struct cfg80211_chan_def chandef; |
| 8575 | enum nl80211_dfs_regions dfs_region; |
| 8576 | int err; |
| 8577 | |
| 8578 | dfs_region = reg_get_dfs_region(wiphy); |
| 8579 | if (dfs_region == NL80211_DFS_UNSET) { |
| 8580 | GENL_SET_ERR_MSG(info, |
| 8581 | "DFS Region is not set. Unexpected Radar indication"); |
| 8582 | return -EINVAL; |
| 8583 | } |
| 8584 | |
| 8585 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8586 | if (err) { |
| 8587 | GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); |
| 8588 | return err; |
| 8589 | } |
| 8590 | |
| 8591 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
| 8592 | if (err < 0) { |
| 8593 | GENL_SET_ERR_MSG(info, "chandef is invalid"); |
| 8594 | return err; |
| 8595 | } |
| 8596 | |
| 8597 | if (err == 0) { |
| 8598 | GENL_SET_ERR_MSG(info, |
| 8599 | "Unexpected Radar indication for chandef/iftype"); |
| 8600 | return -EINVAL; |
| 8601 | } |
| 8602 | |
| 8603 | /* Do not process this notification if radar is already detected |
| 8604 | * by kernel on this channel, and return success. |
| 8605 | */ |
| 8606 | if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) |
| 8607 | return 0; |
| 8608 | |
| 8609 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); |
| 8610 | |
| 8611 | cfg80211_sched_dfs_chan_update(rdev); |
| 8612 | |
Luca Coelho | a680fe4 | 2019-04-17 09:34:40 +0300 | [diff] [blame] | 8613 | rdev->radar_chandef = chandef; |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 8614 | |
| 8615 | /* Propagate this notification to other radios as well */ |
| 8616 | queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); |
| 8617 | |
| 8618 | return 0; |
| 8619 | } |
| 8620 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8621 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 8622 | { |
| 8623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8624 | struct net_device *dev = info->user_ptr[1]; |
| 8625 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8626 | struct cfg80211_csa_settings params; |
| 8627 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 8628 | * function is called under RTNL lock, so this should not be a problem. |
| 8629 | */ |
| 8630 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8631 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8632 | bool need_new_beacon = false; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8633 | bool need_handle_dfs_flag = true; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8634 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 8635 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8636 | |
| 8637 | if (!rdev->ops->channel_switch || |
| 8638 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 8639 | return -EOPNOTSUPP; |
| 8640 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8641 | switch (dev->ieee80211_ptr->iftype) { |
| 8642 | case NL80211_IFTYPE_AP: |
| 8643 | case NL80211_IFTYPE_P2P_GO: |
| 8644 | need_new_beacon = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8645 | /* For all modes except AP the handle_dfs flag needs to be |
| 8646 | * supplied to tell the kernel that userspace will handle radar |
| 8647 | * events when they happen. Otherwise a switch to a channel |
| 8648 | * requiring DFS will be rejected. |
| 8649 | */ |
| 8650 | need_handle_dfs_flag = false; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8651 | |
| 8652 | /* useless if AP is not running */ |
| 8653 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8654 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8655 | break; |
| 8656 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8657 | if (!wdev->ssid_len) |
| 8658 | return -ENOTCONN; |
| 8659 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 8660 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8661 | if (!wdev->mesh_id_len) |
| 8662 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8663 | break; |
| 8664 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8665 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8666 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8667 | |
| 8668 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | c177db2 | 2018-10-30 09:17:44 +0100 | [diff] [blame] | 8669 | params.beacon_csa.ftm_responder = -1; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8670 | |
| 8671 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8672 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 8673 | return -EINVAL; |
| 8674 | |
| 8675 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 8676 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8677 | return -EINVAL; |
| 8678 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 8679 | /* Even though the attribute is u32, the specification says |
| 8680 | * u8, so let's make sure we don't overflow. |
| 8681 | */ |
| 8682 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 8683 | if (cs_count > 255) |
| 8684 | return -EINVAL; |
| 8685 | |
| 8686 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8687 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8688 | if (!need_new_beacon) |
| 8689 | goto skip_beacons; |
| 8690 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 8691 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8692 | if (err) |
| 8693 | return err; |
| 8694 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8695 | err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, |
| 8696 | info->attrs[NL80211_ATTR_CSA_IES], |
| 8697 | nl80211_policy, info->extack); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8698 | if (err) |
| 8699 | return err; |
| 8700 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 8701 | err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8702 | if (err) |
| 8703 | return err; |
| 8704 | |
| 8705 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 8706 | return -EINVAL; |
| 8707 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8708 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 8709 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8710 | return -EINVAL; |
| 8711 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8712 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 8713 | if (rdev->wiphy.max_num_csa_counters && |
| 8714 | (params.n_counter_offsets_beacon > |
| 8715 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8716 | return -EINVAL; |
| 8717 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8718 | params.counter_offsets_beacon = |
| 8719 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 8720 | |
| 8721 | /* sanity checks - counters should fit and be the same */ |
| 8722 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 8723 | u16 offset = params.counter_offsets_beacon[i]; |
| 8724 | |
| 8725 | if (offset >= params.beacon_csa.tail_len) |
| 8726 | return -EINVAL; |
| 8727 | |
| 8728 | if (params.beacon_csa.tail[offset] != params.count) |
| 8729 | return -EINVAL; |
| 8730 | } |
| 8731 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8732 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8733 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 8734 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8735 | return -EINVAL; |
| 8736 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8737 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 8738 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 8739 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8740 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8741 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8742 | |
| 8743 | params.counter_offsets_presp = |
| 8744 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 8745 | |
| 8746 | /* sanity checks - counters should fit and be the same */ |
| 8747 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 8748 | u16 offset = params.counter_offsets_presp[i]; |
| 8749 | |
| 8750 | if (offset >= params.beacon_csa.probe_resp_len) |
| 8751 | return -EINVAL; |
| 8752 | |
| 8753 | if (params.beacon_csa.probe_resp[offset] != |
| 8754 | params.count) |
| 8755 | return -EINVAL; |
| 8756 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8757 | } |
| 8758 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8759 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8760 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 8761 | if (err) |
| 8762 | return err; |
| 8763 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 8764 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 8765 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8766 | return -EINVAL; |
| 8767 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 8768 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 8769 | ¶ms.chandef, |
| 8770 | wdev->iftype); |
| 8771 | if (err < 0) |
| 8772 | return err; |
| 8773 | |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8774 | if (err > 0) { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 8775 | params.radar_required = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8776 | if (need_handle_dfs_flag && |
| 8777 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
| 8778 | return -EINVAL; |
| 8779 | } |
| 8780 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8781 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8782 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 8783 | params.block_tx = true; |
| 8784 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 8785 | wdev_lock(wdev); |
| 8786 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 8787 | wdev_unlock(wdev); |
| 8788 | |
| 8789 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8790 | } |
| 8791 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8792 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 8793 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8794 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8795 | struct wireless_dev *wdev, |
| 8796 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8797 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8798 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8799 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8800 | void *hdr; |
| 8801 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8802 | |
| 8803 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8804 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8805 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8806 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 8807 | if (!hdr) |
| 8808 | return -1; |
| 8809 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 8810 | genl_dump_check_consistent(cb, hdr); |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8811 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8812 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 8813 | goto nla_put_failure; |
| 8814 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8815 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 8816 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8817 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 8818 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8819 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8820 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 8821 | bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8822 | if (!bss) |
| 8823 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8824 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8825 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8826 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8827 | |
| 8828 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8829 | /* indicate whether we have probe response data or not */ |
| 8830 | if (rcu_access_pointer(res->proberesp_ies) && |
| 8831 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 8832 | goto fail_unlock_rcu; |
| 8833 | |
| 8834 | /* this pointer prefers to be pointed to probe response data |
| 8835 | * but is always valid |
| 8836 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8837 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8838 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8839 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 8840 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8841 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8842 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 8843 | ies->len, ies->data)) |
| 8844 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8845 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8846 | |
| 8847 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8848 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8849 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8850 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 8851 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8852 | goto fail_unlock_rcu; |
| 8853 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 8854 | ies->len, ies->data)) |
| 8855 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8856 | } |
| 8857 | rcu_read_unlock(); |
| 8858 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8859 | if (res->beacon_interval && |
| 8860 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 8861 | goto nla_put_failure; |
| 8862 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 8863 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 8864 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8865 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 8866 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 8867 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8868 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 8869 | if (intbss->parent_tsf && |
| 8870 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 8871 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 8872 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 8873 | intbss->parent_bssid))) |
| 8874 | goto nla_put_failure; |
| 8875 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 8876 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8877 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 8878 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 8879 | goto nla_put_failure; |
| 8880 | |
Sunil Dutt | 983dafa | 2017-12-13 19:51:36 +0200 | [diff] [blame] | 8881 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
| 8882 | intbss->pub.chain_signal, |
| 8883 | NL80211_BSS_CHAIN_SIGNAL)) |
| 8884 | goto nla_put_failure; |
| 8885 | |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 8886 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8887 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8888 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 8889 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8890 | break; |
| 8891 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8892 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 8893 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8894 | break; |
| 8895 | default: |
| 8896 | break; |
| 8897 | } |
| 8898 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8899 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8900 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8901 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8902 | if (intbss == wdev->current_bss && |
| 8903 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 8904 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 8905 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8906 | break; |
| 8907 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8908 | if (intbss == wdev->current_bss && |
| 8909 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 8910 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 8911 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8912 | break; |
| 8913 | default: |
| 8914 | break; |
| 8915 | } |
| 8916 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8917 | nla_nest_end(msg, bss); |
| 8918 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 8919 | genlmsg_end(msg, hdr); |
| 8920 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8921 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8922 | fail_unlock_rcu: |
| 8923 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8924 | nla_put_failure: |
| 8925 | genlmsg_cancel(msg, hdr); |
| 8926 | return -EMSGSIZE; |
| 8927 | } |
| 8928 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8929 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8930 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8931 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8932 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8933 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8934 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8935 | int err; |
| 8936 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8937 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 8938 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8939 | if (err) { |
| 8940 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8941 | return err; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8942 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8943 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8944 | wdev_lock(wdev); |
| 8945 | spin_lock_bh(&rdev->bss_lock); |
Denis Kenzior | d1e23c9 | 2018-05-21 10:31:13 -0500 | [diff] [blame] | 8946 | |
| 8947 | /* |
| 8948 | * dump_scan will be called multiple times to break up the scan results |
| 8949 | * into multiple messages. It is unlikely that any more bss-es will be |
| 8950 | * expired after the first call, so only call only call this on the |
| 8951 | * first dump_scan invocation. |
| 8952 | */ |
| 8953 | if (start == 0) |
| 8954 | cfg80211_bss_expire(rdev); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8955 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8956 | cb->seq = rdev->bss_generation; |
| 8957 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8958 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8959 | if (++idx <= start) |
| 8960 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8961 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8962 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8963 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8964 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8965 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8966 | } |
| 8967 | } |
| 8968 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8969 | spin_unlock_bh(&rdev->bss_lock); |
| 8970 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8971 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8972 | cb->args[2] = idx; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8973 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8974 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8975 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8976 | } |
| 8977 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8978 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8979 | int flags, struct net_device *dev, |
| 8980 | bool allow_radio_stats, |
| 8981 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8982 | { |
| 8983 | void *hdr; |
| 8984 | struct nlattr *infoattr; |
| 8985 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8986 | /* skip radio stats if userspace didn't request them */ |
| 8987 | if (!survey->channel && !allow_radio_stats) |
| 8988 | return 0; |
| 8989 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8990 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8991 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 8992 | if (!hdr) |
| 8993 | return -ENOMEM; |
| 8994 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8995 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 8996 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8997 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 8998 | infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8999 | if (!infoattr) |
| 9000 | goto nla_put_failure; |
| 9001 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9002 | if (survey->channel && |
| 9003 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9004 | survey->channel->center_freq)) |
| 9005 | goto nla_put_failure; |
| 9006 | |
| 9007 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 9008 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 9009 | goto nla_put_failure; |
| 9010 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 9011 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 9012 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9013 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9014 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 9015 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9016 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9017 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9018 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 9019 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9020 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9021 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9022 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 9023 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9024 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9025 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9026 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 9027 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9028 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9029 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9030 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 9031 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9032 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 9033 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9034 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 9035 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 9036 | goto nla_put_failure; |
Felix Fietkau | c8cd6e7 | 2019-08-28 12:20:42 +0200 | [diff] [blame] | 9037 | if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && |
| 9038 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, |
| 9039 | survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) |
| 9040 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9041 | |
| 9042 | nla_nest_end(msg, infoattr); |
| 9043 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 9044 | genlmsg_end(msg, hdr); |
| 9045 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9046 | |
| 9047 | nla_put_failure: |
| 9048 | genlmsg_cancel(msg, hdr); |
| 9049 | return -EMSGSIZE; |
| 9050 | } |
| 9051 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9052 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9053 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9054 | struct nlattr **attrbuf; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9055 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9056 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9057 | struct wireless_dev *wdev; |
| 9058 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9059 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9060 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9061 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9062 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 9063 | if (!attrbuf) |
| 9064 | return -ENOMEM; |
| 9065 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9066 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 9067 | res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9068 | if (res) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9069 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9070 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9071 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9072 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9073 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9074 | if (!wdev->netdev) { |
| 9075 | res = -EINVAL; |
| 9076 | goto out_err; |
| 9077 | } |
| 9078 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9079 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9080 | res = -EOPNOTSUPP; |
| 9081 | goto out_err; |
| 9082 | } |
| 9083 | |
| 9084 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9085 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9086 | if (res == -ENOENT) |
| 9087 | break; |
| 9088 | if (res) |
| 9089 | goto out_err; |
| 9090 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9091 | /* don't send disabled channels, but do send non-channel data */ |
| 9092 | if (survey.channel && |
| 9093 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 9094 | survey_idx++; |
| 9095 | continue; |
| 9096 | } |
| 9097 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9098 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9099 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9100 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9101 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9102 | goto out; |
| 9103 | survey_idx++; |
| 9104 | } |
| 9105 | |
| 9106 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9107 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9108 | res = skb->len; |
| 9109 | out_err: |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9110 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9111 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9112 | return res; |
| 9113 | } |
| 9114 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9115 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 9116 | { |
| 9117 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
Chung-Hsien Hsu | cc3e14c | 2019-05-09 09:49:05 +0000 | [diff] [blame] | 9118 | NL80211_WPA_VERSION_2 | |
| 9119 | NL80211_WPA_VERSION_3)); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9120 | } |
| 9121 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9122 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 9123 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9124 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9125 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9126 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9127 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 9128 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9129 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9130 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9131 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9132 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9133 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9134 | return -EINVAL; |
| 9135 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 9136 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 9137 | return -EINVAL; |
| 9138 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9139 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 9140 | return -EINVAL; |
| 9141 | |
| 9142 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9143 | return -EINVAL; |
| 9144 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9145 | err = nl80211_parse_key(info, &key); |
| 9146 | if (err) |
| 9147 | return err; |
| 9148 | |
| 9149 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 9150 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 9151 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9152 | if (!key.p.key || !key.p.key_len) |
| 9153 | return -EINVAL; |
| 9154 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 9155 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 9156 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 9157 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 9158 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 9159 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9160 | return -EINVAL; |
| 9161 | } else { |
| 9162 | key.p.key_len = 0; |
| 9163 | key.p.key = NULL; |
| 9164 | } |
| 9165 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9166 | if (key.idx >= 0) { |
| 9167 | int i; |
| 9168 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 9169 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9170 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 9171 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 9172 | ok = true; |
| 9173 | break; |
| 9174 | } |
| 9175 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9176 | if (!ok) |
| 9177 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9178 | } |
| 9179 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9180 | if (!rdev->ops->auth) |
| 9181 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9182 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9183 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9184 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9185 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9186 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9187 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9188 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 9189 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 9190 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9191 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9192 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9193 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9194 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9195 | |
| 9196 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9197 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9198 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9199 | } |
| 9200 | |
| 9201 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9202 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9203 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9204 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 9205 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 9206 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 9207 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 9208 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9209 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9210 | return -EINVAL; |
| 9211 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9212 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 9213 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 9214 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 9215 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 9216 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9217 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9218 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 9219 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9220 | /* need to include at least Auth Transaction and Status Code */ |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9221 | if (auth_data_len < 4) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9222 | return -EINVAL; |
| 9223 | } |
| 9224 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9225 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9226 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 9227 | /* |
| 9228 | * Since we no longer track auth state, ignore |
| 9229 | * requests to only change local state. |
| 9230 | */ |
| 9231 | if (local_state_change) |
| 9232 | return 0; |
| 9233 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9234 | wdev_lock(dev->ieee80211_ptr); |
| 9235 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 9236 | ssid, ssid_len, ie, ie_len, |
| 9237 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9238 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9239 | wdev_unlock(dev->ieee80211_ptr); |
| 9240 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9241 | } |
| 9242 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9243 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, |
| 9244 | struct genl_info *info) |
| 9245 | { |
| 9246 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9247 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); |
| 9248 | return -EINVAL; |
| 9249 | } |
| 9250 | |
| 9251 | if (!rdev->ops->tx_control_port || |
| 9252 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9253 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 9254 | return -EOPNOTSUPP; |
| 9255 | |
| 9256 | return 0; |
| 9257 | } |
| 9258 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9259 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 9260 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 9261 | struct cfg80211_crypto_settings *settings, |
| 9262 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9263 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 9264 | memset(settings, 0, sizeof(*settings)); |
| 9265 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9266 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 9267 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9268 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 9269 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 9270 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9271 | proto = nla_get_u16( |
| 9272 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 9273 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 9274 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 9275 | proto != ETH_P_PAE) |
| 9276 | return -EINVAL; |
| 9277 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 9278 | settings->control_port_no_encrypt = true; |
| 9279 | } else |
| 9280 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 9281 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9282 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 9283 | int r = validate_pae_over_nl80211(rdev, info); |
| 9284 | |
| 9285 | if (r < 0) |
| 9286 | return r; |
| 9287 | |
| 9288 | settings->control_port_over_nl80211 = true; |
| 9289 | } |
| 9290 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9291 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 9292 | void *data; |
| 9293 | int len, i; |
| 9294 | |
| 9295 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 9296 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 9297 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 9298 | |
| 9299 | if (len % sizeof(u32)) |
| 9300 | return -EINVAL; |
| 9301 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 9302 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9303 | return -EINVAL; |
| 9304 | |
| 9305 | memcpy(settings->ciphers_pairwise, data, len); |
| 9306 | |
| 9307 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 9308 | if (!cfg80211_supported_cipher_suite( |
| 9309 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9310 | settings->ciphers_pairwise[i])) |
| 9311 | return -EINVAL; |
| 9312 | } |
| 9313 | |
| 9314 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 9315 | settings->cipher_group = |
| 9316 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 9317 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 9318 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9319 | return -EINVAL; |
| 9320 | } |
| 9321 | |
| 9322 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 9323 | settings->wpa_versions = |
| 9324 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 9325 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 9326 | return -EINVAL; |
| 9327 | } |
| 9328 | |
| 9329 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 9330 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 9331 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9332 | |
| 9333 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 9334 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 9335 | settings->n_akm_suites = len / sizeof(u32); |
| 9336 | |
| 9337 | if (len % sizeof(u32)) |
| 9338 | return -EINVAL; |
| 9339 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 9340 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 9341 | return -EINVAL; |
| 9342 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9343 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9344 | } |
| 9345 | |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 9346 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9347 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 9348 | return -EINVAL; |
| 9349 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9350 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) |
| 9351 | return -EINVAL; |
| 9352 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9353 | } |
| 9354 | |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 9355 | if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { |
| 9356 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9357 | NL80211_EXT_FEATURE_SAE_OFFLOAD)) |
| 9358 | return -EINVAL; |
| 9359 | settings->sae_pwd = |
| 9360 | nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 9361 | settings->sae_pwd_len = |
| 9362 | nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 9363 | } |
| 9364 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9365 | return 0; |
| 9366 | } |
| 9367 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9368 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 9369 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9371 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9372 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9373 | struct cfg80211_assoc_request req = {}; |
| 9374 | const u8 *bssid, *ssid; |
| 9375 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9376 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9377 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9378 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9379 | return -EPERM; |
| 9380 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9381 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9382 | !info->attrs[NL80211_ATTR_SSID] || |
| 9383 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9384 | return -EINVAL; |
| 9385 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9386 | if (!rdev->ops->assoc) |
| 9387 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9388 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9389 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9390 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9391 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9392 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9393 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9394 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9395 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 9396 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 9397 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9398 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9399 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9400 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9401 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9402 | |
| 9403 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9404 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9405 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9406 | } |
| 9407 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9408 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 9409 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9410 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 9411 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9412 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9413 | else if (mfp != NL80211_MFP_NO) |
| 9414 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9415 | } |
| 9416 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 9417 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9418 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 9419 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9420 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9421 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9422 | |
| 9423 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9424 | memcpy(&req.ht_capa_mask, |
| 9425 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9426 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9427 | |
| 9428 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9429 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9430 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9431 | memcpy(&req.ht_capa, |
| 9432 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9433 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9434 | } |
| 9435 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9436 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9437 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9438 | |
| 9439 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9440 | memcpy(&req.vht_capa_mask, |
| 9441 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 9442 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9443 | |
| 9444 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9445 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9446 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9447 | memcpy(&req.vht_capa, |
| 9448 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 9449 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9450 | } |
| 9451 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9452 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 9453 | if (!((rdev->wiphy.features & |
| 9454 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 9455 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 9456 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9457 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9458 | return -EINVAL; |
| 9459 | req.flags |= ASSOC_REQ_USE_RRM; |
| 9460 | } |
| 9461 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 9462 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 9463 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 9464 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 9465 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 9466 | return -EINVAL; |
| 9467 | req.fils_nonces = |
| 9468 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 9469 | } |
| 9470 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9471 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9472 | if (!err) { |
| 9473 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9474 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9475 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 9476 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9477 | |
| 9478 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9479 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 9480 | info->snd_portid; |
| 9481 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 9482 | bssid, ETH_ALEN); |
| 9483 | } |
| 9484 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9485 | wdev_unlock(dev->ieee80211_ptr); |
| 9486 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9487 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9488 | return err; |
| 9489 | } |
| 9490 | |
| 9491 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 9492 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9494 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9495 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9496 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9497 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9498 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9499 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9500 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9501 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9502 | return -EPERM; |
| 9503 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9504 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9505 | return -EINVAL; |
| 9506 | |
| 9507 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9508 | return -EINVAL; |
| 9509 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9510 | if (!rdev->ops->deauth) |
| 9511 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9512 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9513 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9514 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9515 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9516 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9517 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9518 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9519 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9520 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9521 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9522 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 9523 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9524 | |
| 9525 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9526 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9527 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9528 | } |
| 9529 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9530 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9531 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9532 | wdev_lock(dev->ieee80211_ptr); |
| 9533 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9534 | local_state_change); |
| 9535 | wdev_unlock(dev->ieee80211_ptr); |
| 9536 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9537 | } |
| 9538 | |
| 9539 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 9540 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9542 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9543 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9544 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9545 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9546 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9547 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9548 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9549 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9550 | return -EPERM; |
| 9551 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9552 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9553 | return -EINVAL; |
| 9554 | |
| 9555 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9556 | return -EINVAL; |
| 9557 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9558 | if (!rdev->ops->disassoc) |
| 9559 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9560 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9561 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9562 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9563 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9564 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9565 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9566 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9567 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9568 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9569 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9570 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 9571 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9572 | |
| 9573 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9574 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9575 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9576 | } |
| 9577 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9578 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9579 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9580 | wdev_lock(dev->ieee80211_ptr); |
| 9581 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9582 | local_state_change); |
| 9583 | wdev_unlock(dev->ieee80211_ptr); |
| 9584 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9585 | } |
| 9586 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9587 | static bool |
| 9588 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9589 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9590 | int rateval) |
| 9591 | { |
| 9592 | struct wiphy *wiphy = &rdev->wiphy; |
| 9593 | bool found = false; |
| 9594 | int band, i; |
| 9595 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9596 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9597 | struct ieee80211_supported_band *sband; |
| 9598 | |
| 9599 | sband = wiphy->bands[band]; |
| 9600 | if (!sband) |
| 9601 | continue; |
| 9602 | |
| 9603 | for (i = 0; i < sband->n_bitrates; i++) { |
| 9604 | if (sband->bitrates[i].bitrate == rateval) { |
| 9605 | mcast_rate[band] = i + 1; |
| 9606 | found = true; |
| 9607 | break; |
| 9608 | } |
| 9609 | } |
| 9610 | } |
| 9611 | |
| 9612 | return found; |
| 9613 | } |
| 9614 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9615 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 9616 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9617 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9618 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9619 | struct cfg80211_ibss_params ibss; |
| 9620 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9621 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9622 | int err; |
| 9623 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9624 | memset(&ibss, 0, sizeof(ibss)); |
| 9625 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9626 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9627 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 9628 | return -EINVAL; |
| 9629 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9630 | ibss.beacon_interval = 100; |
| 9631 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9632 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9633 | ibss.beacon_interval = |
| 9634 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9635 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 9636 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 9637 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9638 | if (err) |
| 9639 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9640 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9641 | if (!rdev->ops->join_ibss) |
| 9642 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9643 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9644 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 9645 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9646 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 9647 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9648 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 9649 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9650 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 9651 | |
| 9652 | if (!is_valid_ether_addr(ibss.bssid)) |
| 9653 | return -EINVAL; |
| 9654 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9655 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9656 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9657 | |
| 9658 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9659 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9660 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9661 | } |
| 9662 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9663 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 9664 | if (err) |
| 9665 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 9666 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 9667 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 9668 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 9669 | return -EINVAL; |
| 9670 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9671 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 9672 | case NL80211_CHAN_WIDTH_5: |
| 9673 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9674 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 9675 | break; |
| 9676 | case NL80211_CHAN_WIDTH_20: |
| 9677 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 9678 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 9679 | return -EINVAL; |
| 9680 | break; |
| 9681 | case NL80211_CHAN_WIDTH_80: |
| 9682 | case NL80211_CHAN_WIDTH_80P80: |
| 9683 | case NL80211_CHAN_WIDTH_160: |
| 9684 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 9685 | return -EINVAL; |
| 9686 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9687 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 9688 | return -EINVAL; |
| 9689 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9690 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 9691 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9692 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 9693 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9694 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9695 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9696 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9697 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9698 | u8 *rates = |
| 9699 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9700 | int n_rates = |
| 9701 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9702 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9703 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9704 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 9705 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9706 | &ibss.basic_rates); |
| 9707 | if (err) |
| 9708 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9709 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9710 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 9711 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9712 | memcpy(&ibss.ht_capa_mask, |
| 9713 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9714 | sizeof(ibss.ht_capa_mask)); |
| 9715 | |
| 9716 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 9717 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9718 | return -EINVAL; |
| 9719 | memcpy(&ibss.ht_capa, |
| 9720 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9721 | sizeof(ibss.ht_capa)); |
| 9722 | } |
| 9723 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9724 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9725 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 9726 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9727 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9728 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9729 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 9730 | bool no_ht = false; |
| 9731 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 9732 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9733 | if (IS_ERR(connkeys)) |
| 9734 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 9735 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 9736 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 9737 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 9738 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 9739 | return -EINVAL; |
| 9740 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9741 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9742 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 9743 | ibss.control_port = |
| 9744 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 9745 | |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 9746 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 9747 | int r = validate_pae_over_nl80211(rdev, info); |
| 9748 | |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 9749 | if (r < 0) { |
| 9750 | kzfree(connkeys); |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 9751 | return r; |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 9752 | } |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 9753 | |
| 9754 | ibss.control_port_over_nl80211 = true; |
| 9755 | } |
| 9756 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 9757 | ibss.userspace_handles_dfs = |
| 9758 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 9759 | |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 9760 | wdev_lock(dev->ieee80211_ptr); |
| 9761 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9762 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9763 | kzfree(connkeys); |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 9764 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 9765 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 9766 | wdev_unlock(dev->ieee80211_ptr); |
| 9767 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9768 | return err; |
| 9769 | } |
| 9770 | |
| 9771 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 9772 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9773 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9774 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9775 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9776 | if (!rdev->ops->leave_ibss) |
| 9777 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9778 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9779 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 9780 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9781 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9782 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9783 | } |
| 9784 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9785 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 9786 | { |
| 9787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9788 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9789 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9790 | u32 nla_rate; |
| 9791 | int err; |
| 9792 | |
| 9793 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 9794 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 9795 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9796 | return -EOPNOTSUPP; |
| 9797 | |
| 9798 | if (!rdev->ops->set_mcast_rate) |
| 9799 | return -EOPNOTSUPP; |
| 9800 | |
| 9801 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 9802 | |
| 9803 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 9804 | return -EINVAL; |
| 9805 | |
| 9806 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 9807 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 9808 | return -EINVAL; |
| 9809 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 9810 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9811 | |
| 9812 | return err; |
| 9813 | } |
| 9814 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9815 | static struct sk_buff * |
| 9816 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9817 | struct wireless_dev *wdev, int approxlen, |
| 9818 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9819 | enum nl80211_attrs attr, |
| 9820 | const struct nl80211_vendor_cmd_info *info, |
| 9821 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9822 | { |
| 9823 | struct sk_buff *skb; |
| 9824 | void *hdr; |
| 9825 | struct nlattr *data; |
| 9826 | |
| 9827 | skb = nlmsg_new(approxlen + 100, gfp); |
| 9828 | if (!skb) |
| 9829 | return NULL; |
| 9830 | |
| 9831 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 9832 | if (!hdr) { |
| 9833 | kfree_skb(skb); |
| 9834 | return NULL; |
| 9835 | } |
| 9836 | |
| 9837 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 9838 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9839 | |
| 9840 | if (info) { |
| 9841 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 9842 | info->vendor_id)) |
| 9843 | goto nla_put_failure; |
| 9844 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 9845 | info->subcmd)) |
| 9846 | goto nla_put_failure; |
| 9847 | } |
| 9848 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9849 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9850 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 9851 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9852 | goto nla_put_failure; |
| 9853 | if (wdev->netdev && |
| 9854 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 9855 | wdev->netdev->ifindex)) |
| 9856 | goto nla_put_failure; |
| 9857 | } |
| 9858 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 9859 | data = nla_nest_start_noflag(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9860 | if (!data) |
| 9861 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9862 | |
| 9863 | ((void **)skb->cb)[0] = rdev; |
| 9864 | ((void **)skb->cb)[1] = hdr; |
| 9865 | ((void **)skb->cb)[2] = data; |
| 9866 | |
| 9867 | return skb; |
| 9868 | |
| 9869 | nla_put_failure: |
| 9870 | kfree_skb(skb); |
| 9871 | return NULL; |
| 9872 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9873 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9874 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9875 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9876 | enum nl80211_commands cmd, |
| 9877 | enum nl80211_attrs attr, |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 9878 | unsigned int portid, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9879 | int vendor_event_idx, |
| 9880 | int approxlen, gfp_t gfp) |
| 9881 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9882 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9883 | const struct nl80211_vendor_cmd_info *info; |
| 9884 | |
| 9885 | switch (cmd) { |
| 9886 | case NL80211_CMD_TESTMODE: |
| 9887 | if (WARN_ON(vendor_event_idx != -1)) |
| 9888 | return NULL; |
| 9889 | info = NULL; |
| 9890 | break; |
| 9891 | case NL80211_CMD_VENDOR: |
| 9892 | if (WARN_ON(vendor_event_idx < 0 || |
| 9893 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 9894 | return NULL; |
| 9895 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 9896 | break; |
| 9897 | default: |
| 9898 | WARN_ON(1); |
| 9899 | return NULL; |
| 9900 | } |
| 9901 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 9902 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9903 | cmd, attr, info, gfp); |
| 9904 | } |
| 9905 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 9906 | |
| 9907 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 9908 | { |
| 9909 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9910 | void *hdr = ((void **)skb->cb)[1]; |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 9911 | struct nlmsghdr *nlhdr = nlmsg_hdr(skb); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9912 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9913 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 9914 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9915 | /* clear CB data for netlink core to own from now on */ |
| 9916 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 9917 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9918 | nla_nest_end(skb, data); |
| 9919 | genlmsg_end(skb, hdr); |
| 9920 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 9921 | if (nlhdr->nlmsg_pid) { |
| 9922 | genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, |
| 9923 | nlhdr->nlmsg_pid); |
| 9924 | } else { |
| 9925 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 9926 | mcgrp = NL80211_MCGRP_VENDOR; |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9927 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 9928 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 9929 | skb, 0, mcgrp, gfp); |
| 9930 | } |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9931 | } |
| 9932 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 9933 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9934 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9935 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 9936 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9937 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 9938 | struct wireless_dev *wdev = |
| 9939 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9940 | int err; |
| 9941 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 9942 | if (!rdev->ops->testmode_cmd) |
| 9943 | return -EOPNOTSUPP; |
| 9944 | |
| 9945 | if (IS_ERR(wdev)) { |
| 9946 | err = PTR_ERR(wdev); |
| 9947 | if (err != -EINVAL) |
| 9948 | return err; |
| 9949 | wdev = NULL; |
| 9950 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9951 | return -EINVAL; |
| 9952 | } |
| 9953 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9954 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 9955 | return -EINVAL; |
| 9956 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9957 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 9958 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9959 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 9960 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9961 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9962 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9963 | return err; |
| 9964 | } |
| 9965 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9966 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 9967 | struct netlink_callback *cb) |
| 9968 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 9969 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9970 | struct nlattr **attrbuf = NULL; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9971 | int err; |
| 9972 | long phy_idx; |
| 9973 | void *data = NULL; |
| 9974 | int data_len = 0; |
| 9975 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9976 | rtnl_lock(); |
| 9977 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9978 | if (cb->args[0]) { |
| 9979 | /* |
| 9980 | * 0 is a valid index, but not valid for args[0], |
| 9981 | * so we need to offset by 1. |
| 9982 | */ |
| 9983 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 9984 | |
| 9985 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 9986 | if (!rdev) { |
| 9987 | err = -ENOENT; |
| 9988 | goto out_err; |
| 9989 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9990 | } else { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9991 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 9992 | GFP_KERNEL); |
| 9993 | if (!attrbuf) { |
| 9994 | err = -ENOMEM; |
| 9995 | goto out_err; |
| 9996 | } |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9997 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 9998 | err = nlmsg_parse_deprecated(cb->nlh, |
| 9999 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10000 | attrbuf, nl80211_fam.maxattr, |
| 10001 | nl80211_policy, NULL); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10002 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10003 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10004 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10005 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10006 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10007 | err = PTR_ERR(rdev); |
| 10008 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10009 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10010 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10011 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10012 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 10013 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10014 | } |
| 10015 | |
| 10016 | if (cb->args[1]) { |
| 10017 | data = nla_data((void *)cb->args[1]); |
| 10018 | data_len = nla_len((void *)cb->args[1]); |
| 10019 | } |
| 10020 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10021 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10022 | err = -EOPNOTSUPP; |
| 10023 | goto out_err; |
| 10024 | } |
| 10025 | |
| 10026 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10027 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10028 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10029 | NL80211_CMD_TESTMODE); |
| 10030 | struct nlattr *tmdata; |
| 10031 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10032 | if (!hdr) |
| 10033 | break; |
| 10034 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10035 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10036 | genlmsg_cancel(skb, hdr); |
| 10037 | break; |
| 10038 | } |
| 10039 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 10040 | tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10041 | if (!tmdata) { |
| 10042 | genlmsg_cancel(skb, hdr); |
| 10043 | break; |
| 10044 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10045 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10046 | nla_nest_end(skb, tmdata); |
| 10047 | |
| 10048 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10049 | genlmsg_cancel(skb, hdr); |
| 10050 | break; |
| 10051 | } else if (err) { |
| 10052 | genlmsg_cancel(skb, hdr); |
| 10053 | goto out_err; |
| 10054 | } |
| 10055 | |
| 10056 | genlmsg_end(skb, hdr); |
| 10057 | } |
| 10058 | |
| 10059 | err = skb->len; |
| 10060 | /* see above */ |
| 10061 | cb->args[0] = phy_idx + 1; |
| 10062 | out_err: |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10063 | kfree(attrbuf); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10064 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10065 | return err; |
| 10066 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10067 | #endif |
| 10068 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10069 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 10070 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10072 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10073 | struct cfg80211_connect_params connect; |
| 10074 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10075 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10076 | int err; |
| 10077 | |
| 10078 | memset(&connect, 0, sizeof(connect)); |
| 10079 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10080 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 10081 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 10082 | return -EINVAL; |
| 10083 | |
| 10084 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10085 | connect.auth_type = |
| 10086 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 10087 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 10088 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10089 | return -EINVAL; |
| 10090 | } else |
| 10091 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 10092 | |
| 10093 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 10094 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 10095 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 10096 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10097 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 10098 | return -EINVAL; |
| 10099 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 10100 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 10101 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 10102 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10103 | if (err) |
| 10104 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10105 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10106 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10107 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10108 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10109 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 10110 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10111 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 10112 | connect.bg_scan_period = -1; |
| 10113 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 10114 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 10115 | connect.bg_scan_period = |
| 10116 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 10117 | } |
| 10118 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10119 | if (info->attrs[NL80211_ATTR_MAC]) |
| 10120 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10121 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 10122 | connect.bssid_hint = |
| 10123 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10124 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10125 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10126 | |
| 10127 | if (info->attrs[NL80211_ATTR_IE]) { |
| 10128 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10129 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10130 | } |
| 10131 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 10132 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 10133 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 10134 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
| 10135 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10136 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) |
| 10137 | return -EOPNOTSUPP; |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 10138 | } else { |
| 10139 | connect.mfp = NL80211_MFP_NO; |
| 10140 | } |
| 10141 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 10142 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 10143 | connect.prev_bssid = |
| 10144 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 10145 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10146 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10147 | connect.channel = nl80211_get_valid_chan( |
| 10148 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 10149 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10150 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10151 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10152 | connect.channel_hint = nl80211_get_valid_chan( |
| 10153 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 10154 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10155 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10156 | } |
| 10157 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 10158 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 10159 | connect.edmg.channels = |
| 10160 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 10161 | |
| 10162 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 10163 | connect.edmg.bw_config = |
| 10164 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 10165 | } |
| 10166 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10167 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 10168 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10169 | if (IS_ERR(connkeys)) |
| 10170 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10171 | } |
| 10172 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10173 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 10174 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 10175 | |
| 10176 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10177 | memcpy(&connect.ht_capa_mask, |
| 10178 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 10179 | sizeof(connect.ht_capa_mask)); |
| 10180 | |
| 10181 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 10182 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 10183 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10184 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 10185 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10186 | memcpy(&connect.ht_capa, |
| 10187 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 10188 | sizeof(connect.ht_capa)); |
| 10189 | } |
| 10190 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10191 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 10192 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 10193 | |
| 10194 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 10195 | memcpy(&connect.vht_capa_mask, |
| 10196 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 10197 | sizeof(connect.vht_capa_mask)); |
| 10198 | |
| 10199 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 10200 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 10201 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10202 | return -EINVAL; |
| 10203 | } |
| 10204 | memcpy(&connect.vht_capa, |
| 10205 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 10206 | sizeof(connect.vht_capa)); |
| 10207 | } |
| 10208 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10209 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 10210 | if (!((rdev->wiphy.features & |
| 10211 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 10212 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 10213 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10214 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 10215 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10216 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 10217 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10218 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 10219 | } |
| 10220 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 10221 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10222 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 10223 | kzfree(connkeys); |
| 10224 | return -EOPNOTSUPP; |
| 10225 | } |
| 10226 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 10227 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 10228 | /* bss selection makes no sense if bssid is set */ |
| 10229 | if (connect.bssid) { |
| 10230 | kzfree(connkeys); |
| 10231 | return -EINVAL; |
| 10232 | } |
| 10233 | |
| 10234 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 10235 | wiphy, &connect.bss_select); |
| 10236 | if (err) { |
| 10237 | kzfree(connkeys); |
| 10238 | return err; |
| 10239 | } |
| 10240 | } |
| 10241 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10242 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 10243 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 10244 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 10245 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 10246 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 10247 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10248 | connect.fils_erp_username = |
| 10249 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10250 | connect.fils_erp_username_len = |
| 10251 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10252 | connect.fils_erp_realm = |
| 10253 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10254 | connect.fils_erp_realm_len = |
| 10255 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10256 | connect.fils_erp_next_seq_num = |
| 10257 | nla_get_u16( |
| 10258 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 10259 | connect.fils_erp_rrk = |
| 10260 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10261 | connect.fils_erp_rrk_len = |
| 10262 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10263 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 10264 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 10265 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 10266 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10267 | kzfree(connkeys); |
| 10268 | return -EINVAL; |
| 10269 | } |
| 10270 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 10271 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
| 10272 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
Srinivas Dasari | 2f0605a | 2018-04-20 11:41:14 +0530 | [diff] [blame] | 10273 | kzfree(connkeys); |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 10274 | GENL_SET_ERR_MSG(info, |
| 10275 | "external auth requires connection ownership"); |
| 10276 | return -EINVAL; |
| 10277 | } |
| 10278 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; |
| 10279 | } |
| 10280 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10281 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10282 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 10283 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 10284 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10285 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 10286 | kzfree(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10287 | |
| 10288 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 10289 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10290 | if (connect.bssid) |
| 10291 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 10292 | connect.bssid, ETH_ALEN); |
| 10293 | else |
| 10294 | memset(dev->ieee80211_ptr->disconnect_bssid, |
| 10295 | 0, ETH_ALEN); |
| 10296 | } |
| 10297 | |
| 10298 | wdev_unlock(dev->ieee80211_ptr); |
| 10299 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10300 | return err; |
| 10301 | } |
| 10302 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10303 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 10304 | struct genl_info *info) |
| 10305 | { |
| 10306 | struct cfg80211_connect_params connect = {}; |
| 10307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10308 | struct net_device *dev = info->user_ptr[1]; |
| 10309 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 10310 | bool fils_sk_offload; |
| 10311 | u32 auth_type; |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10312 | u32 changed = 0; |
| 10313 | int ret; |
| 10314 | |
| 10315 | if (!rdev->ops->update_connect_params) |
| 10316 | return -EOPNOTSUPP; |
| 10317 | |
| 10318 | if (info->attrs[NL80211_ATTR_IE]) { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10319 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10320 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10321 | changed |= UPDATE_ASSOC_IES; |
| 10322 | } |
| 10323 | |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 10324 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, |
| 10325 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); |
| 10326 | |
| 10327 | /* |
| 10328 | * when driver supports fils-sk offload all attributes must be |
| 10329 | * provided. So the else covers "fils-sk-not-all" and |
| 10330 | * "no-fils-sk-any". |
| 10331 | */ |
| 10332 | if (fils_sk_offload && |
| 10333 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 10334 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 10335 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 10336 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10337 | connect.fils_erp_username = |
| 10338 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10339 | connect.fils_erp_username_len = |
| 10340 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10341 | connect.fils_erp_realm = |
| 10342 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10343 | connect.fils_erp_realm_len = |
| 10344 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10345 | connect.fils_erp_next_seq_num = |
| 10346 | nla_get_u16( |
| 10347 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 10348 | connect.fils_erp_rrk = |
| 10349 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10350 | connect.fils_erp_rrk_len = |
| 10351 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10352 | changed |= UPDATE_FILS_ERP_INFO; |
| 10353 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 10354 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 10355 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 10356 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10357 | return -EINVAL; |
| 10358 | } |
| 10359 | |
| 10360 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10361 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 10362 | if (!nl80211_valid_auth_type(rdev, auth_type, |
| 10363 | NL80211_CMD_CONNECT)) |
| 10364 | return -EINVAL; |
| 10365 | |
| 10366 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && |
| 10367 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) |
| 10368 | return -EINVAL; |
| 10369 | |
| 10370 | connect.auth_type = auth_type; |
| 10371 | changed |= UPDATE_AUTH_TYPE; |
| 10372 | } |
| 10373 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10374 | wdev_lock(dev->ieee80211_ptr); |
| 10375 | if (!wdev->current_bss) |
| 10376 | ret = -ENOLINK; |
| 10377 | else |
| 10378 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 10379 | wdev_unlock(dev->ieee80211_ptr); |
| 10380 | |
| 10381 | return ret; |
| 10382 | } |
| 10383 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10384 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 10385 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10387 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10388 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10389 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10390 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 10391 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 10392 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 10393 | return -EPERM; |
| 10394 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10395 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 10396 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 10397 | else |
| 10398 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 10399 | |
| 10400 | if (reason == 0) |
| 10401 | return -EINVAL; |
| 10402 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10403 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10404 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10405 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10406 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10407 | wdev_lock(dev->ieee80211_ptr); |
| 10408 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 10409 | wdev_unlock(dev->ieee80211_ptr); |
| 10410 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10411 | } |
| 10412 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10413 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 10414 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10415 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10416 | struct net *net; |
| 10417 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10418 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 10419 | if (info->attrs[NL80211_ATTR_PID]) { |
| 10420 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 10421 | |
| 10422 | net = get_net_ns_by_pid(pid); |
| 10423 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 10424 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 10425 | |
| 10426 | net = get_net_ns_by_fd(fd); |
| 10427 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10428 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 10429 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10430 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10431 | if (IS_ERR(net)) |
| 10432 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10433 | |
| 10434 | err = 0; |
| 10435 | |
| 10436 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10437 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 10438 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10439 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10440 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10441 | return err; |
| 10442 | } |
| 10443 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10444 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 10445 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10447 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 10448 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10449 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10450 | struct cfg80211_pmksa pmksa; |
| 10451 | |
| 10452 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 10453 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10454 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 10455 | return -EINVAL; |
| 10456 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10457 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10458 | |
| 10459 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 10460 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10461 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 10462 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 10463 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 10464 | info->attrs[NL80211_ATTR_PMK])) { |
| 10465 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10466 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10467 | pmksa.cache_id = |
| 10468 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 10469 | } else { |
| 10470 | return -EINVAL; |
| 10471 | } |
| 10472 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 10473 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 10474 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 10475 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10476 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10477 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Liangwei Dong | 6c90036 | 2019-01-18 16:54:38 +0530 | [diff] [blame] | 10478 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 10479 | !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && |
| 10480 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 10481 | NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10482 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10483 | |
| 10484 | switch (info->genlhdr->cmd) { |
| 10485 | case NL80211_CMD_SET_PMKSA: |
| 10486 | rdev_ops = rdev->ops->set_pmksa; |
| 10487 | break; |
| 10488 | case NL80211_CMD_DEL_PMKSA: |
| 10489 | rdev_ops = rdev->ops->del_pmksa; |
| 10490 | break; |
| 10491 | default: |
| 10492 | WARN_ON(1); |
| 10493 | break; |
| 10494 | } |
| 10495 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10496 | if (!rdev_ops) |
| 10497 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10498 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10499 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10500 | } |
| 10501 | |
| 10502 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 10503 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10505 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10506 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10507 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10508 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10509 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10510 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10511 | if (!rdev->ops->flush_pmksa) |
| 10512 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10513 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10514 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10515 | } |
| 10516 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10517 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 10518 | { |
| 10519 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10520 | struct net_device *dev = info->user_ptr[1]; |
| 10521 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10522 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10523 | u16 status_code; |
| 10524 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10525 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10526 | |
| 10527 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 10528 | !rdev->ops->tdls_mgmt) |
| 10529 | return -EOPNOTSUPP; |
| 10530 | |
| 10531 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 10532 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 10533 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 10534 | !info->attrs[NL80211_ATTR_IE] || |
| 10535 | !info->attrs[NL80211_ATTR_MAC]) |
| 10536 | return -EINVAL; |
| 10537 | |
| 10538 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10539 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 10540 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 10541 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10542 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10543 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 10544 | peer_capability = |
| 10545 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10546 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10547 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10548 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10549 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10550 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 10551 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10552 | } |
| 10553 | |
| 10554 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 10555 | { |
| 10556 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10557 | struct net_device *dev = info->user_ptr[1]; |
| 10558 | enum nl80211_tdls_operation operation; |
| 10559 | u8 *peer; |
| 10560 | |
| 10561 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 10562 | !rdev->ops->tdls_oper) |
| 10563 | return -EOPNOTSUPP; |
| 10564 | |
| 10565 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 10566 | !info->attrs[NL80211_ATTR_MAC]) |
| 10567 | return -EINVAL; |
| 10568 | |
| 10569 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 10570 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10571 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10572 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10573 | } |
| 10574 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10575 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 10576 | struct genl_info *info) |
| 10577 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10579 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10580 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10581 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10582 | struct sk_buff *msg; |
| 10583 | void *hdr; |
| 10584 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10585 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10586 | int err; |
| 10587 | |
| 10588 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 10589 | !info->attrs[NL80211_ATTR_DURATION]) |
| 10590 | return -EINVAL; |
| 10591 | |
| 10592 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 10593 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10594 | if (!rdev->ops->remain_on_channel || |
| 10595 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10596 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10597 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10598 | /* |
| 10599 | * We should be on that channel for at least a minimum amount of |
| 10600 | * time (10ms) but no longer than the driver supports. |
| 10601 | */ |
| 10602 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 10603 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 10604 | return -EINVAL; |
| 10605 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10606 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10607 | if (err) |
| 10608 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10609 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10610 | wdev_lock(wdev); |
| 10611 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 10612 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 10613 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 10614 | &chandef); |
| 10615 | if (compat_chandef != &chandef) { |
| 10616 | wdev_unlock(wdev); |
| 10617 | return -EBUSY; |
| 10618 | } |
| 10619 | } |
| 10620 | wdev_unlock(wdev); |
| 10621 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10622 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10623 | if (!msg) |
| 10624 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10625 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10626 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10627 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10628 | if (!hdr) { |
| 10629 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10630 | goto free_msg; |
| 10631 | } |
| 10632 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10633 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 10634 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10635 | |
| 10636 | if (err) |
| 10637 | goto free_msg; |
| 10638 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10639 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10640 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10641 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10642 | |
| 10643 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10644 | |
| 10645 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10646 | |
| 10647 | nla_put_failure: |
| 10648 | err = -ENOBUFS; |
| 10649 | free_msg: |
| 10650 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10651 | return err; |
| 10652 | } |
| 10653 | |
| 10654 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 10655 | struct genl_info *info) |
| 10656 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10657 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10658 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10659 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10660 | |
| 10661 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 10662 | return -EINVAL; |
| 10663 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10664 | if (!rdev->ops->cancel_remain_on_channel) |
| 10665 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10666 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10667 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 10668 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10669 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10670 | } |
| 10671 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10672 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 10673 | struct genl_info *info) |
| 10674 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10675 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10676 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10677 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10678 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10680 | if (!rdev->ops->set_bitrate_mask) |
| 10681 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10682 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10683 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
| 10684 | if (err) |
| 10685 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 10686 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10687 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10688 | } |
| 10689 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10690 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10691 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10692 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10693 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10694 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10695 | |
| 10696 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 10697 | return -EINVAL; |
| 10698 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10699 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 10700 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10701 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10702 | switch (wdev->iftype) { |
| 10703 | case NL80211_IFTYPE_STATION: |
| 10704 | case NL80211_IFTYPE_ADHOC: |
| 10705 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10706 | case NL80211_IFTYPE_AP: |
| 10707 | case NL80211_IFTYPE_AP_VLAN: |
| 10708 | case NL80211_IFTYPE_MESH_POINT: |
| 10709 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10710 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10711 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10712 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10713 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10714 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10715 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10716 | |
| 10717 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10718 | if (!rdev->ops->mgmt_tx) |
| 10719 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10720 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10721 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Ilan Peer | ff74c51 | 2020-01-31 13:45:29 +0200 | [diff] [blame] | 10722 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 10723 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 10724 | info->extack); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10725 | } |
| 10726 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10727 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10728 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10730 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10731 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10732 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 10733 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10734 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10735 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10736 | struct cfg80211_mgmt_tx_params params = { |
| 10737 | .dont_wait_for_ack = |
| 10738 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 10739 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10740 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10741 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10742 | return -EINVAL; |
| 10743 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10744 | if (!rdev->ops->mgmt_tx) |
| 10745 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10746 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10747 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10748 | case NL80211_IFTYPE_P2P_DEVICE: |
| 10749 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 10750 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10751 | case NL80211_IFTYPE_STATION: |
| 10752 | case NL80211_IFTYPE_ADHOC: |
| 10753 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10754 | case NL80211_IFTYPE_AP: |
| 10755 | case NL80211_IFTYPE_AP_VLAN: |
| 10756 | case NL80211_IFTYPE_MESH_POINT: |
| 10757 | case NL80211_IFTYPE_P2P_GO: |
| 10758 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10759 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10760 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10761 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10762 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10763 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10764 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10765 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10766 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10767 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10768 | |
| 10769 | /* |
| 10770 | * We should wait on the channel for at least a minimum amount |
| 10771 | * of time (10ms) but no longer than the driver supports. |
| 10772 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10773 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 10774 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10775 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10776 | } |
| 10777 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10778 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10779 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10780 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10781 | return -EINVAL; |
| 10782 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10783 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 10784 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10785 | /* get the channel if any has been specified, otherwise pass NULL to |
| 10786 | * the driver. The latter will use the current one |
| 10787 | */ |
| 10788 | chandef.chan = NULL; |
| 10789 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 10790 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10791 | if (err) |
| 10792 | return err; |
| 10793 | } |
| 10794 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10795 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10796 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10797 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10798 | wdev_lock(wdev); |
| 10799 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 10800 | wdev_unlock(wdev); |
| 10801 | return -EBUSY; |
| 10802 | } |
| 10803 | wdev_unlock(wdev); |
| 10804 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 10805 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 10806 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 10807 | |
| 10808 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 10809 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 10810 | int i; |
| 10811 | |
| 10812 | if (len % sizeof(u16)) |
| 10813 | return -EINVAL; |
| 10814 | |
| 10815 | params.n_csa_offsets = len / sizeof(u16); |
| 10816 | params.csa_offsets = |
| 10817 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 10818 | |
| 10819 | /* check that all the offsets fit the frame */ |
| 10820 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 10821 | if (params.csa_offsets[i] >= params.len) |
| 10822 | return -EINVAL; |
| 10823 | } |
| 10824 | } |
| 10825 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10826 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10827 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10828 | if (!msg) |
| 10829 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10830 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10831 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10832 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10833 | if (!hdr) { |
| 10834 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10835 | goto free_msg; |
| 10836 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10837 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10838 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10839 | params.chan = chandef.chan; |
| 10840 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10841 | if (err) |
| 10842 | goto free_msg; |
| 10843 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10844 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10845 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10846 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10847 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10848 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10849 | genlmsg_end(msg, hdr); |
| 10850 | return genlmsg_reply(msg, info); |
| 10851 | } |
| 10852 | |
| 10853 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10854 | |
| 10855 | nla_put_failure: |
| 10856 | err = -ENOBUFS; |
| 10857 | free_msg: |
| 10858 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10859 | return err; |
| 10860 | } |
| 10861 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10862 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 10863 | { |
| 10864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10865 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10866 | u64 cookie; |
| 10867 | |
| 10868 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 10869 | return -EINVAL; |
| 10870 | |
| 10871 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 10872 | return -EOPNOTSUPP; |
| 10873 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10874 | switch (wdev->iftype) { |
| 10875 | case NL80211_IFTYPE_STATION: |
| 10876 | case NL80211_IFTYPE_ADHOC: |
| 10877 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10878 | case NL80211_IFTYPE_AP: |
| 10879 | case NL80211_IFTYPE_AP_VLAN: |
| 10880 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10881 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10882 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10883 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10884 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10885 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10886 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10887 | |
| 10888 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 10889 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10890 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10891 | } |
| 10892 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10893 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 10894 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10896 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10897 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10898 | u8 ps_state; |
| 10899 | bool state; |
| 10900 | int err; |
| 10901 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10902 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 10903 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10904 | |
| 10905 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 10906 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10907 | wdev = dev->ieee80211_ptr; |
| 10908 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10909 | if (!rdev->ops->set_power_mgmt) |
| 10910 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10911 | |
| 10912 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 10913 | |
| 10914 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10915 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10916 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10917 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10918 | if (!err) |
| 10919 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10920 | return err; |
| 10921 | } |
| 10922 | |
| 10923 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 10924 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10926 | enum nl80211_ps_state ps_state; |
| 10927 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10928 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10929 | struct sk_buff *msg; |
| 10930 | void *hdr; |
| 10931 | int err; |
| 10932 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10933 | wdev = dev->ieee80211_ptr; |
| 10934 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10935 | if (!rdev->ops->set_power_mgmt) |
| 10936 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10937 | |
| 10938 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10939 | if (!msg) |
| 10940 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10941 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10942 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10943 | NL80211_CMD_GET_POWER_SAVE); |
| 10944 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10945 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10946 | goto free_msg; |
| 10947 | } |
| 10948 | |
| 10949 | if (wdev->ps) |
| 10950 | ps_state = NL80211_PS_ENABLED; |
| 10951 | else |
| 10952 | ps_state = NL80211_PS_DISABLED; |
| 10953 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10954 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 10955 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10956 | |
| 10957 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10958 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10959 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10960 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10961 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10962 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10963 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10964 | return err; |
| 10965 | } |
| 10966 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 10967 | static const struct nla_policy |
| 10968 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10969 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10970 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 10971 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10972 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 10973 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 10974 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 10975 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10976 | }; |
| 10977 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10978 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 10979 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10980 | { |
| 10981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10982 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10983 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10984 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 10985 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10986 | return -EINVAL; |
| 10987 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10988 | if (!rdev->ops->set_cqm_txe_config) |
| 10989 | return -EOPNOTSUPP; |
| 10990 | |
| 10991 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 10992 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10993 | return -EOPNOTSUPP; |
| 10994 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10995 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10996 | } |
| 10997 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10998 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 10999 | struct net_device *dev) |
| 11000 | { |
| 11001 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11002 | s32 last, low, high; |
| 11003 | u32 hyst; |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 11004 | int i, n, low_index; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11005 | int err; |
| 11006 | |
| 11007 | /* RSSI reporting disabled? */ |
| 11008 | if (!wdev->cqm_config) |
| 11009 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 11010 | |
| 11011 | /* |
| 11012 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 11013 | * event has been received yet, we should receive an event after a |
| 11014 | * connection is established and enough beacons received to calculate |
| 11015 | * the average. |
| 11016 | */ |
| 11017 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 11018 | rdev->ops->get_station) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11019 | struct station_info sinfo = {}; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11020 | u8 *mac_addr; |
| 11021 | |
| 11022 | mac_addr = wdev->current_bss->pub.bssid; |
| 11023 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11024 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 11025 | if (err) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11026 | return err; |
| 11027 | |
Felix Fietkau | df16737 | 2020-01-08 18:06:30 +0100 | [diff] [blame] | 11028 | cfg80211_sinfo_release_content(&sinfo); |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 11029 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11030 | wdev->cqm_config->last_rssi_event_value = |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11031 | (s8) sinfo.rx_beacon_signal_avg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11032 | } |
| 11033 | |
| 11034 | last = wdev->cqm_config->last_rssi_event_value; |
| 11035 | hyst = wdev->cqm_config->rssi_hyst; |
| 11036 | n = wdev->cqm_config->n_rssi_thresholds; |
| 11037 | |
Masashi Honma | 4b2c5a1 | 2019-09-08 09:56:53 +0900 | [diff] [blame] | 11038 | for (i = 0; i < n; i++) { |
| 11039 | i = array_index_nospec(i, n); |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11040 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 11041 | break; |
Masashi Honma | 4b2c5a1 | 2019-09-08 09:56:53 +0900 | [diff] [blame] | 11042 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11043 | |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 11044 | low_index = i - 1; |
| 11045 | if (low_index >= 0) { |
| 11046 | low_index = array_index_nospec(low_index, n); |
| 11047 | low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; |
| 11048 | } else { |
| 11049 | low = S32_MIN; |
| 11050 | } |
| 11051 | if (i < n) { |
| 11052 | i = array_index_nospec(i, n); |
| 11053 | high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; |
| 11054 | } else { |
| 11055 | high = S32_MAX; |
| 11056 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11057 | |
| 11058 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 11059 | } |
| 11060 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11061 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11062 | const s32 *thresholds, int n_thresholds, |
| 11063 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11064 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11066 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11067 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11068 | int i, err; |
| 11069 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11070 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11071 | /* Check all values negative and sorted */ |
| 11072 | for (i = 0; i < n_thresholds; i++) { |
| 11073 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 11074 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11075 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11076 | prev = thresholds[i]; |
| 11077 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11078 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 11079 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11080 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11081 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11082 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11083 | wdev_lock(wdev); |
| 11084 | cfg80211_cqm_config_free(wdev); |
| 11085 | wdev_unlock(wdev); |
| 11086 | |
| 11087 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 11088 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 11089 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 11090 | |
| 11091 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 11092 | thresholds[0], hysteresis); |
| 11093 | } |
| 11094 | |
| 11095 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 11096 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 11097 | return -EOPNOTSUPP; |
| 11098 | |
| 11099 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 11100 | n_thresholds = 0; |
| 11101 | |
| 11102 | wdev_lock(wdev); |
| 11103 | if (n_thresholds) { |
| 11104 | struct cfg80211_cqm_config *cqm_config; |
| 11105 | |
| 11106 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 11107 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 11108 | if (!cqm_config) { |
| 11109 | err = -ENOMEM; |
| 11110 | goto unlock; |
| 11111 | } |
| 11112 | |
| 11113 | cqm_config->rssi_hyst = hysteresis; |
| 11114 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 11115 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 11116 | n_thresholds * sizeof(s32)); |
| 11117 | |
| 11118 | wdev->cqm_config = cqm_config; |
| 11119 | } |
| 11120 | |
| 11121 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 11122 | |
| 11123 | unlock: |
| 11124 | wdev_unlock(wdev); |
| 11125 | |
| 11126 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11127 | } |
| 11128 | |
| 11129 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 11130 | { |
| 11131 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 11132 | struct nlattr *cqm; |
| 11133 | int err; |
| 11134 | |
| 11135 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11136 | if (!cqm) |
| 11137 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11138 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11139 | err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 11140 | nl80211_attr_cqm_policy, |
| 11141 | info->extack); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11142 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11143 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11144 | |
| 11145 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 11146 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11147 | const s32 *thresholds = |
| 11148 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 11149 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11150 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11151 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11152 | if (len % 4) |
| 11153 | return -EINVAL; |
| 11154 | |
| 11155 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 11156 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11157 | } |
| 11158 | |
| 11159 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 11160 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 11161 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 11162 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 11163 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 11164 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 11165 | |
| 11166 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 11167 | } |
| 11168 | |
| 11169 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11170 | } |
| 11171 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11172 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 11173 | { |
| 11174 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11175 | struct net_device *dev = info->user_ptr[1]; |
| 11176 | struct ocb_setup setup = {}; |
| 11177 | int err; |
| 11178 | |
| 11179 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 11180 | if (err) |
| 11181 | return err; |
| 11182 | |
| 11183 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 11184 | } |
| 11185 | |
| 11186 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 11187 | { |
| 11188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11189 | struct net_device *dev = info->user_ptr[1]; |
| 11190 | |
| 11191 | return cfg80211_leave_ocb(rdev, dev); |
| 11192 | } |
| 11193 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11194 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 11195 | { |
| 11196 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11197 | struct net_device *dev = info->user_ptr[1]; |
| 11198 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11199 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11200 | int err; |
| 11201 | |
| 11202 | /* start with default */ |
| 11203 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11204 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11205 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11206 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11207 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11208 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11209 | if (err) |
| 11210 | return err; |
| 11211 | } |
| 11212 | |
| 11213 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 11214 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 11215 | return -EINVAL; |
| 11216 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11217 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 11218 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 11219 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 11220 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 11221 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 11222 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 11223 | return -EINVAL; |
| 11224 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 11225 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 11226 | setup.beacon_interval = |
| 11227 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 11228 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 11229 | err = cfg80211_validate_beacon_int(rdev, |
| 11230 | NL80211_IFTYPE_MESH_POINT, |
| 11231 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 11232 | if (err) |
| 11233 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 11234 | } |
| 11235 | |
| 11236 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 11237 | setup.dtim_period = |
| 11238 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 11239 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 11240 | return -EINVAL; |
| 11241 | } |
| 11242 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11243 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 11244 | /* parse additional setup parameters if given */ |
| 11245 | err = nl80211_parse_mesh_setup(info, &setup); |
| 11246 | if (err) |
| 11247 | return err; |
| 11248 | } |
| 11249 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 11250 | if (setup.user_mpm) |
| 11251 | cfg.auto_open_plinks = false; |
| 11252 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11253 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11254 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 11255 | if (err) |
| 11256 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11257 | } else { |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 11258 | /* __cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11259 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11260 | } |
| 11261 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 11262 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 11263 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 11264 | int n_rates = |
| 11265 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 11266 | struct ieee80211_supported_band *sband; |
| 11267 | |
| 11268 | if (!setup.chandef.chan) |
| 11269 | return -EINVAL; |
| 11270 | |
| 11271 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 11272 | |
| 11273 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 11274 | &setup.basic_rates); |
| 11275 | if (err) |
| 11276 | return err; |
| 11277 | } |
| 11278 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11279 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 11280 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); |
| 11281 | if (err) |
| 11282 | return err; |
| 11283 | |
Johannes Berg | 265698d | 2017-09-18 22:46:36 +0200 | [diff] [blame] | 11284 | if (!setup.chandef.chan) |
| 11285 | return -EINVAL; |
| 11286 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11287 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 11288 | &setup.beacon_rate); |
| 11289 | if (err) |
| 11290 | return err; |
| 11291 | } |
| 11292 | |
Benjamin Berg | d37d49c | 2017-05-16 11:23:11 +0200 | [diff] [blame] | 11293 | setup.userspace_handles_dfs = |
| 11294 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 11295 | |
Denis Kenzior | 1224f58 | 2018-03-26 12:52:49 -0500 | [diff] [blame] | 11296 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 11297 | int r = validate_pae_over_nl80211(rdev, info); |
| 11298 | |
| 11299 | if (r < 0) |
| 11300 | return r; |
| 11301 | |
| 11302 | setup.control_port_over_nl80211 = true; |
| 11303 | } |
| 11304 | |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 11305 | wdev_lock(dev->ieee80211_ptr); |
| 11306 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
| 11307 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 11308 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 11309 | wdev_unlock(dev->ieee80211_ptr); |
| 11310 | |
| 11311 | return err; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11312 | } |
| 11313 | |
| 11314 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 11315 | { |
| 11316 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11317 | struct net_device *dev = info->user_ptr[1]; |
| 11318 | |
| 11319 | return cfg80211_leave_mesh(rdev, dev); |
| 11320 | } |
| 11321 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11322 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11323 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 11324 | struct cfg80211_registered_device *rdev) |
| 11325 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11326 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11327 | struct nlattr *nl_pats, *nl_pat; |
| 11328 | int i, pat_len; |
| 11329 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11330 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11331 | return 0; |
| 11332 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11333 | nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11334 | if (!nl_pats) |
| 11335 | return -ENOBUFS; |
| 11336 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11337 | for (i = 0; i < wowlan->n_patterns; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11338 | nl_pat = nla_nest_start_noflag(msg, i + 1); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11339 | if (!nl_pat) |
| 11340 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11341 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11342 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11343 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11344 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 11345 | wowlan->patterns[i].pattern) || |
| 11346 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11347 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11348 | return -ENOBUFS; |
| 11349 | nla_nest_end(msg, nl_pat); |
| 11350 | } |
| 11351 | nla_nest_end(msg, nl_pats); |
| 11352 | |
| 11353 | return 0; |
| 11354 | } |
| 11355 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11356 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 11357 | struct cfg80211_wowlan_tcp *tcp) |
| 11358 | { |
| 11359 | struct nlattr *nl_tcp; |
| 11360 | |
| 11361 | if (!tcp) |
| 11362 | return 0; |
| 11363 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11364 | nl_tcp = nla_nest_start_noflag(msg, |
| 11365 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11366 | if (!nl_tcp) |
| 11367 | return -ENOBUFS; |
| 11368 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 11369 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 11370 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11371 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 11372 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 11373 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 11374 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 11375 | tcp->payload_len, tcp->payload) || |
| 11376 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 11377 | tcp->data_interval) || |
| 11378 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 11379 | tcp->wake_len, tcp->wake_data) || |
| 11380 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 11381 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 11382 | return -ENOBUFS; |
| 11383 | |
| 11384 | if (tcp->payload_seq.len && |
| 11385 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 11386 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 11387 | return -ENOBUFS; |
| 11388 | |
| 11389 | if (tcp->payload_tok.len && |
| 11390 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 11391 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 11392 | &tcp->payload_tok)) |
| 11393 | return -ENOBUFS; |
| 11394 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 11395 | nla_nest_end(msg, nl_tcp); |
| 11396 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11397 | return 0; |
| 11398 | } |
| 11399 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11400 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 11401 | struct cfg80211_sched_scan_request *req) |
| 11402 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11403 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11404 | int i; |
| 11405 | |
| 11406 | if (!req) |
| 11407 | return 0; |
| 11408 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11409 | nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11410 | if (!nd) |
| 11411 | return -ENOBUFS; |
| 11412 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11413 | if (req->n_scan_plans == 1 && |
| 11414 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 11415 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11416 | return -ENOBUFS; |
| 11417 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 11418 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 11419 | return -ENOBUFS; |
| 11420 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 11421 | if (req->relative_rssi_set) { |
| 11422 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 11423 | |
| 11424 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 11425 | req->relative_rssi)) |
| 11426 | return -ENOBUFS; |
| 11427 | |
| 11428 | rssi_adjust.band = req->rssi_adjust.band; |
| 11429 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 11430 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 11431 | sizeof(rssi_adjust), &rssi_adjust)) |
| 11432 | return -ENOBUFS; |
| 11433 | } |
| 11434 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11435 | freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11436 | if (!freqs) |
| 11437 | return -ENOBUFS; |
| 11438 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 11439 | for (i = 0; i < req->n_channels; i++) { |
| 11440 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11441 | return -ENOBUFS; |
| 11442 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11443 | |
| 11444 | nla_nest_end(msg, freqs); |
| 11445 | |
| 11446 | if (req->n_match_sets) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11447 | matches = nla_nest_start_noflag(msg, |
| 11448 | NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11449 | if (!matches) |
| 11450 | return -ENOBUFS; |
| 11451 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11452 | for (i = 0; i < req->n_match_sets; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11453 | match = nla_nest_start_noflag(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11454 | if (!match) |
| 11455 | return -ENOBUFS; |
| 11456 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 11457 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 11458 | req->match_sets[i].ssid.ssid_len, |
| 11459 | req->match_sets[i].ssid.ssid)) |
| 11460 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11461 | nla_nest_end(msg, match); |
| 11462 | } |
| 11463 | nla_nest_end(msg, matches); |
| 11464 | } |
| 11465 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11466 | scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11467 | if (!scan_plans) |
| 11468 | return -ENOBUFS; |
| 11469 | |
| 11470 | for (i = 0; i < req->n_scan_plans; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11471 | scan_plan = nla_nest_start_noflag(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11472 | if (!scan_plan) |
| 11473 | return -ENOBUFS; |
| 11474 | |
Colin Ian King | 6762696 | 2018-09-06 10:58:44 +0100 | [diff] [blame] | 11475 | if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11476 | req->scan_plans[i].interval) || |
| 11477 | (req->scan_plans[i].iterations && |
| 11478 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 11479 | req->scan_plans[i].iterations))) |
| 11480 | return -ENOBUFS; |
| 11481 | nla_nest_end(msg, scan_plan); |
| 11482 | } |
| 11483 | nla_nest_end(msg, scan_plans); |
| 11484 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11485 | nla_nest_end(msg, nd); |
| 11486 | |
| 11487 | return 0; |
| 11488 | } |
| 11489 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11490 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 11491 | { |
| 11492 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11493 | struct sk_buff *msg; |
| 11494 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11495 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11496 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11497 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11498 | return -EOPNOTSUPP; |
| 11499 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11500 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11501 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11502 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 11503 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 11504 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 11505 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11506 | } |
| 11507 | |
| 11508 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11509 | if (!msg) |
| 11510 | return -ENOMEM; |
| 11511 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11512 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11513 | NL80211_CMD_GET_WOWLAN); |
| 11514 | if (!hdr) |
| 11515 | goto nla_put_failure; |
| 11516 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11517 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11518 | struct nlattr *nl_wowlan; |
| 11519 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11520 | nl_wowlan = nla_nest_start_noflag(msg, |
| 11521 | NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11522 | if (!nl_wowlan) |
| 11523 | goto nla_put_failure; |
| 11524 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11525 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11526 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11527 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11528 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11529 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11530 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11531 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11532 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11533 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11534 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11535 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11536 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11537 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11538 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 11539 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11540 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11541 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 11542 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11543 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11544 | if (nl80211_send_wowlan_tcp(msg, |
| 11545 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11546 | goto nla_put_failure; |
| 11547 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11548 | if (nl80211_send_wowlan_nd( |
| 11549 | msg, |
| 11550 | rdev->wiphy.wowlan_config->nd_config)) |
| 11551 | goto nla_put_failure; |
| 11552 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11553 | nla_nest_end(msg, nl_wowlan); |
| 11554 | } |
| 11555 | |
| 11556 | genlmsg_end(msg, hdr); |
| 11557 | return genlmsg_reply(msg, info); |
| 11558 | |
| 11559 | nla_put_failure: |
| 11560 | nlmsg_free(msg); |
| 11561 | return -ENOBUFS; |
| 11562 | } |
| 11563 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11564 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 11565 | struct nlattr *attr, |
| 11566 | struct cfg80211_wowlan *trig) |
| 11567 | { |
| 11568 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 11569 | struct cfg80211_wowlan_tcp *cfg; |
| 11570 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 11571 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 11572 | u32 size; |
| 11573 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 11574 | int err, port; |
| 11575 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11576 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11577 | return -EINVAL; |
| 11578 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11579 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, |
| 11580 | nl80211_wowlan_tcp_policy, NULL); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11581 | if (err) |
| 11582 | return err; |
| 11583 | |
| 11584 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 11585 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 11586 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 11587 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 11588 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 11589 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 11590 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 11591 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 11592 | return -EINVAL; |
| 11593 | |
| 11594 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11595 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11596 | return -EINVAL; |
| 11597 | |
| 11598 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11599 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 11600 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11601 | return -EINVAL; |
| 11602 | |
| 11603 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11604 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11605 | return -EINVAL; |
| 11606 | |
| 11607 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 11608 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 11609 | return -EINVAL; |
| 11610 | |
| 11611 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 11612 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 11613 | |
| 11614 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 11615 | tokens_size = tokln - sizeof(*tok); |
| 11616 | |
| 11617 | if (!tok->len || tokens_size % tok->len) |
| 11618 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11619 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11620 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11621 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11622 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11623 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11624 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11625 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11626 | return -EINVAL; |
| 11627 | if (tok->offset + tok->len > data_size) |
| 11628 | return -EINVAL; |
| 11629 | } |
| 11630 | |
| 11631 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 11632 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11633 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11634 | return -EINVAL; |
| 11635 | if (seq->len == 0 || seq->len > 4) |
| 11636 | return -EINVAL; |
| 11637 | if (seq->len + seq->offset > data_size) |
| 11638 | return -EINVAL; |
| 11639 | } |
| 11640 | |
| 11641 | size = sizeof(*cfg); |
| 11642 | size += data_size; |
| 11643 | size += wake_size + wake_mask_size; |
| 11644 | size += tokens_size; |
| 11645 | |
| 11646 | cfg = kzalloc(size, GFP_KERNEL); |
| 11647 | if (!cfg) |
| 11648 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 11649 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 11650 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11651 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 11652 | ETH_ALEN); |
| 11653 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 11654 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 11655 | else |
| 11656 | port = 0; |
| 11657 | #ifdef CONFIG_INET |
| 11658 | /* allocate a socket and port for it and use it */ |
| 11659 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 11660 | IPPROTO_TCP, &cfg->sock, 1); |
| 11661 | if (err) { |
| 11662 | kfree(cfg); |
| 11663 | return err; |
| 11664 | } |
| 11665 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 11666 | sock_release(cfg->sock); |
| 11667 | kfree(cfg); |
| 11668 | return -EADDRINUSE; |
| 11669 | } |
| 11670 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 11671 | #else |
| 11672 | if (!port) { |
| 11673 | kfree(cfg); |
| 11674 | return -EINVAL; |
| 11675 | } |
| 11676 | cfg->src_port = port; |
| 11677 | #endif |
| 11678 | |
| 11679 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 11680 | cfg->payload_len = data_size; |
| 11681 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 11682 | memcpy((void *)cfg->payload, |
| 11683 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 11684 | data_size); |
| 11685 | if (seq) |
| 11686 | cfg->payload_seq = *seq; |
| 11687 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 11688 | cfg->wake_len = wake_size; |
| 11689 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 11690 | memcpy((void *)cfg->wake_data, |
| 11691 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 11692 | wake_size); |
| 11693 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 11694 | data_size + wake_size; |
| 11695 | memcpy((void *)cfg->wake_mask, |
| 11696 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 11697 | wake_mask_size); |
| 11698 | if (tok) { |
| 11699 | cfg->tokens_size = tokens_size; |
| 11700 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 11701 | } |
| 11702 | |
| 11703 | trig->tcp = cfg; |
| 11704 | |
| 11705 | return 0; |
| 11706 | } |
| 11707 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11708 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 11709 | const struct wiphy_wowlan_support *wowlan, |
| 11710 | struct nlattr *attr, |
| 11711 | struct cfg80211_wowlan *trig) |
| 11712 | { |
| 11713 | struct nlattr **tb; |
| 11714 | int err; |
| 11715 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 11716 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11717 | if (!tb) |
| 11718 | return -ENOMEM; |
| 11719 | |
| 11720 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 11721 | err = -EOPNOTSUPP; |
| 11722 | goto out; |
| 11723 | } |
| 11724 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11725 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, |
| 11726 | nl80211_policy, NULL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11727 | if (err) |
| 11728 | goto out; |
| 11729 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 11730 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 11731 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11732 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 11733 | if (err) |
| 11734 | trig->nd_config = NULL; |
| 11735 | |
| 11736 | out: |
| 11737 | kfree(tb); |
| 11738 | return err; |
| 11739 | } |
| 11740 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11741 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 11742 | { |
| 11743 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11744 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11745 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11746 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11747 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11748 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11749 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11750 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11751 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11752 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11753 | return -EOPNOTSUPP; |
| 11754 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11755 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 11756 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11757 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11758 | goto set_wakeup; |
| 11759 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11760 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11761 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, |
| 11762 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
| 11763 | nl80211_wowlan_policy, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11764 | if (err) |
| 11765 | return err; |
| 11766 | |
| 11767 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 11768 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 11769 | return -EINVAL; |
| 11770 | new_triggers.any = true; |
| 11771 | } |
| 11772 | |
| 11773 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 11774 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 11775 | return -EINVAL; |
| 11776 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11777 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11778 | } |
| 11779 | |
| 11780 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 11781 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 11782 | return -EINVAL; |
| 11783 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11784 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11785 | } |
| 11786 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11787 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 11788 | return -EINVAL; |
| 11789 | |
| 11790 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 11791 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 11792 | return -EINVAL; |
| 11793 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11794 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11795 | } |
| 11796 | |
| 11797 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 11798 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 11799 | return -EINVAL; |
| 11800 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11801 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11802 | } |
| 11803 | |
| 11804 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 11805 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 11806 | return -EINVAL; |
| 11807 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11808 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11809 | } |
| 11810 | |
| 11811 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 11812 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 11813 | return -EINVAL; |
| 11814 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11815 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11816 | } |
| 11817 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11818 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 11819 | struct nlattr *pat; |
| 11820 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11821 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11822 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11823 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11824 | regular = true; |
| 11825 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11826 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 11827 | rem) |
| 11828 | n_patterns++; |
| 11829 | if (n_patterns > wowlan->n_patterns) |
| 11830 | return -EINVAL; |
| 11831 | |
| 11832 | new_triggers.patterns = kcalloc(n_patterns, |
| 11833 | sizeof(new_triggers.patterns[0]), |
| 11834 | GFP_KERNEL); |
| 11835 | if (!new_triggers.patterns) |
| 11836 | return -ENOMEM; |
| 11837 | |
| 11838 | new_triggers.n_patterns = n_patterns; |
| 11839 | i = 0; |
| 11840 | |
| 11841 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 11842 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11843 | u8 *mask_pat; |
| 11844 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11845 | err = nla_parse_nested_deprecated(pat_tb, |
| 11846 | MAX_NL80211_PKTPAT, |
| 11847 | pat, |
| 11848 | nl80211_packet_pattern_policy, |
| 11849 | info->extack); |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 11850 | if (err) |
| 11851 | goto error; |
| 11852 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11853 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11854 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 11855 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11856 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11857 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11858 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11859 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11860 | goto error; |
| 11861 | if (pat_len > wowlan->pattern_max_len || |
| 11862 | pat_len < wowlan->pattern_min_len) |
| 11863 | goto error; |
| 11864 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11865 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11866 | pkt_offset = 0; |
| 11867 | else |
| 11868 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11869 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11870 | if (pkt_offset > wowlan->max_pkt_offset) |
| 11871 | goto error; |
| 11872 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 11873 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11874 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 11875 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11876 | err = -ENOMEM; |
| 11877 | goto error; |
| 11878 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11879 | new_triggers.patterns[i].mask = mask_pat; |
| 11880 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11881 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11882 | mask_pat += mask_len; |
| 11883 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11884 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11885 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11886 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11887 | pat_len); |
| 11888 | i++; |
| 11889 | } |
| 11890 | } |
| 11891 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11892 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11893 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11894 | err = nl80211_parse_wowlan_tcp( |
| 11895 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 11896 | &new_triggers); |
| 11897 | if (err) |
| 11898 | goto error; |
| 11899 | } |
| 11900 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11901 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11902 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11903 | err = nl80211_parse_wowlan_nd( |
| 11904 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 11905 | &new_triggers); |
| 11906 | if (err) |
| 11907 | goto error; |
| 11908 | } |
| 11909 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11910 | /* The 'any' trigger means the device continues operating more or less |
| 11911 | * as in its normal operation mode and wakes up the host on most of the |
| 11912 | * normal interrupts (like packet RX, ...) |
| 11913 | * It therefore makes little sense to combine with the more constrained |
| 11914 | * wakeup trigger modes. |
| 11915 | */ |
| 11916 | if (new_triggers.any && regular) { |
| 11917 | err = -EINVAL; |
| 11918 | goto error; |
| 11919 | } |
| 11920 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11921 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 11922 | if (!ntrig) { |
| 11923 | err = -ENOMEM; |
| 11924 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11925 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11926 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11927 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11928 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11929 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11930 | if (rdev->ops->set_wakeup && |
| 11931 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 11932 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 11933 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11934 | return 0; |
| 11935 | error: |
| 11936 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 11937 | kfree(new_triggers.patterns[i].mask); |
| 11938 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11939 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 11940 | sock_release(new_triggers.tcp->sock); |
| 11941 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 11942 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11943 | return err; |
| 11944 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11945 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11946 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11947 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 11948 | struct cfg80211_registered_device *rdev) |
| 11949 | { |
| 11950 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 11951 | int i, j, pat_len; |
| 11952 | struct cfg80211_coalesce_rules *rule; |
| 11953 | |
| 11954 | if (!rdev->coalesce->n_rules) |
| 11955 | return 0; |
| 11956 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11957 | nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11958 | if (!nl_rules) |
| 11959 | return -ENOBUFS; |
| 11960 | |
| 11961 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11962 | nl_rule = nla_nest_start_noflag(msg, i + 1); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11963 | if (!nl_rule) |
| 11964 | return -ENOBUFS; |
| 11965 | |
| 11966 | rule = &rdev->coalesce->rules[i]; |
| 11967 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 11968 | rule->delay)) |
| 11969 | return -ENOBUFS; |
| 11970 | |
| 11971 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 11972 | rule->condition)) |
| 11973 | return -ENOBUFS; |
| 11974 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11975 | nl_pats = nla_nest_start_noflag(msg, |
| 11976 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11977 | if (!nl_pats) |
| 11978 | return -ENOBUFS; |
| 11979 | |
| 11980 | for (j = 0; j < rule->n_patterns; j++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11981 | nl_pat = nla_nest_start_noflag(msg, j + 1); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11982 | if (!nl_pat) |
| 11983 | return -ENOBUFS; |
| 11984 | pat_len = rule->patterns[j].pattern_len; |
| 11985 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 11986 | DIV_ROUND_UP(pat_len, 8), |
| 11987 | rule->patterns[j].mask) || |
| 11988 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 11989 | rule->patterns[j].pattern) || |
| 11990 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 11991 | rule->patterns[j].pkt_offset)) |
| 11992 | return -ENOBUFS; |
| 11993 | nla_nest_end(msg, nl_pat); |
| 11994 | } |
| 11995 | nla_nest_end(msg, nl_pats); |
| 11996 | nla_nest_end(msg, nl_rule); |
| 11997 | } |
| 11998 | nla_nest_end(msg, nl_rules); |
| 11999 | |
| 12000 | return 0; |
| 12001 | } |
| 12002 | |
| 12003 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12004 | { |
| 12005 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12006 | struct sk_buff *msg; |
| 12007 | void *hdr; |
| 12008 | |
| 12009 | if (!rdev->wiphy.coalesce) |
| 12010 | return -EOPNOTSUPP; |
| 12011 | |
| 12012 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12013 | if (!msg) |
| 12014 | return -ENOMEM; |
| 12015 | |
| 12016 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12017 | NL80211_CMD_GET_COALESCE); |
| 12018 | if (!hdr) |
| 12019 | goto nla_put_failure; |
| 12020 | |
| 12021 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 12022 | goto nla_put_failure; |
| 12023 | |
| 12024 | genlmsg_end(msg, hdr); |
| 12025 | return genlmsg_reply(msg, info); |
| 12026 | |
| 12027 | nla_put_failure: |
| 12028 | nlmsg_free(msg); |
| 12029 | return -ENOBUFS; |
| 12030 | } |
| 12031 | |
| 12032 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 12033 | { |
| 12034 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 12035 | int i, j; |
| 12036 | struct cfg80211_coalesce_rules *rule; |
| 12037 | |
| 12038 | if (!coalesce) |
| 12039 | return; |
| 12040 | |
| 12041 | for (i = 0; i < coalesce->n_rules; i++) { |
| 12042 | rule = &coalesce->rules[i]; |
| 12043 | for (j = 0; j < rule->n_patterns; j++) |
| 12044 | kfree(rule->patterns[j].mask); |
| 12045 | kfree(rule->patterns); |
| 12046 | } |
| 12047 | kfree(coalesce->rules); |
| 12048 | kfree(coalesce); |
| 12049 | rdev->coalesce = NULL; |
| 12050 | } |
| 12051 | |
| 12052 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 12053 | struct nlattr *rule, |
| 12054 | struct cfg80211_coalesce_rules *new_rule) |
| 12055 | { |
| 12056 | int err, i; |
| 12057 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12058 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 12059 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 12060 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 12061 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12062 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, |
| 12063 | rule, nl80211_coalesce_policy, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12064 | if (err) |
| 12065 | return err; |
| 12066 | |
| 12067 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 12068 | new_rule->delay = |
| 12069 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 12070 | if (new_rule->delay > coalesce->max_delay) |
| 12071 | return -EINVAL; |
| 12072 | |
| 12073 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 12074 | new_rule->condition = |
| 12075 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12076 | |
| 12077 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 12078 | return -EINVAL; |
| 12079 | |
| 12080 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12081 | rem) |
| 12082 | n_patterns++; |
| 12083 | if (n_patterns > coalesce->n_patterns) |
| 12084 | return -EINVAL; |
| 12085 | |
| 12086 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 12087 | GFP_KERNEL); |
| 12088 | if (!new_rule->patterns) |
| 12089 | return -ENOMEM; |
| 12090 | |
| 12091 | new_rule->n_patterns = n_patterns; |
| 12092 | i = 0; |
| 12093 | |
| 12094 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12095 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12096 | u8 *mask_pat; |
| 12097 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12098 | err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, |
| 12099 | pat, |
| 12100 | nl80211_packet_pattern_policy, |
| 12101 | NULL); |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 12102 | if (err) |
| 12103 | return err; |
| 12104 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12105 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 12106 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 12107 | return -EINVAL; |
| 12108 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 12109 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 12110 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 12111 | return -EINVAL; |
| 12112 | if (pat_len > coalesce->pattern_max_len || |
| 12113 | pat_len < coalesce->pattern_min_len) |
| 12114 | return -EINVAL; |
| 12115 | |
| 12116 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 12117 | pkt_offset = 0; |
| 12118 | else |
| 12119 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 12120 | if (pkt_offset > coalesce->max_pkt_offset) |
| 12121 | return -EINVAL; |
| 12122 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 12123 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12124 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 12125 | if (!mask_pat) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12126 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12127 | |
| 12128 | new_rule->patterns[i].mask = mask_pat; |
| 12129 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 12130 | mask_len); |
| 12131 | |
| 12132 | mask_pat += mask_len; |
| 12133 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12134 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12135 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 12136 | pat_len); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12137 | i++; |
| 12138 | } |
| 12139 | |
| 12140 | return 0; |
| 12141 | } |
| 12142 | |
| 12143 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12144 | { |
| 12145 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12146 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12147 | struct cfg80211_coalesce new_coalesce = {}; |
| 12148 | struct cfg80211_coalesce *n_coalesce; |
| 12149 | int err, rem_rule, n_rules = 0, i, j; |
| 12150 | struct nlattr *rule; |
| 12151 | struct cfg80211_coalesce_rules *tmp_rule; |
| 12152 | |
| 12153 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 12154 | return -EOPNOTSUPP; |
| 12155 | |
| 12156 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 12157 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 12158 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12159 | return 0; |
| 12160 | } |
| 12161 | |
| 12162 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 12163 | rem_rule) |
| 12164 | n_rules++; |
| 12165 | if (n_rules > coalesce->n_rules) |
| 12166 | return -EINVAL; |
| 12167 | |
| 12168 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 12169 | GFP_KERNEL); |
| 12170 | if (!new_coalesce.rules) |
| 12171 | return -ENOMEM; |
| 12172 | |
| 12173 | new_coalesce.n_rules = n_rules; |
| 12174 | i = 0; |
| 12175 | |
| 12176 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 12177 | rem_rule) { |
| 12178 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 12179 | &new_coalesce.rules[i]); |
| 12180 | if (err) |
| 12181 | goto error; |
| 12182 | |
| 12183 | i++; |
| 12184 | } |
| 12185 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 12186 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12187 | if (err) |
| 12188 | goto error; |
| 12189 | |
| 12190 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 12191 | if (!n_coalesce) { |
| 12192 | err = -ENOMEM; |
| 12193 | goto error; |
| 12194 | } |
| 12195 | cfg80211_rdev_free_coalesce(rdev); |
| 12196 | rdev->coalesce = n_coalesce; |
| 12197 | |
| 12198 | return 0; |
| 12199 | error: |
| 12200 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 12201 | tmp_rule = &new_coalesce.rules[i]; |
| 12202 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 12203 | kfree(tmp_rule->patterns[j].mask); |
| 12204 | kfree(tmp_rule->patterns); |
| 12205 | } |
| 12206 | kfree(new_coalesce.rules); |
| 12207 | |
| 12208 | return err; |
| 12209 | } |
| 12210 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12211 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 12212 | { |
| 12213 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12214 | struct net_device *dev = info->user_ptr[1]; |
| 12215 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12216 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 12217 | struct cfg80211_gtk_rekey_data rekey_data; |
| 12218 | int err; |
| 12219 | |
| 12220 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 12221 | return -EINVAL; |
| 12222 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12223 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, |
| 12224 | info->attrs[NL80211_ATTR_REKEY_DATA], |
| 12225 | nl80211_rekey_policy, info->extack); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12226 | if (err) |
| 12227 | return err; |
| 12228 | |
Vladis Dronov | e785fa0 | 2017-09-13 00:21:21 +0200 | [diff] [blame] | 12229 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
| 12230 | !tb[NL80211_REKEY_DATA_KCK]) |
| 12231 | return -EINVAL; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12232 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 12233 | return -ERANGE; |
| 12234 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 12235 | return -ERANGE; |
| 12236 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 12237 | return -ERANGE; |
| 12238 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 12239 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 12240 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 12241 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12242 | |
| 12243 | wdev_lock(wdev); |
| 12244 | if (!wdev->current_bss) { |
| 12245 | err = -ENOTCONN; |
| 12246 | goto out; |
| 12247 | } |
| 12248 | |
| 12249 | if (!rdev->ops->set_rekey_data) { |
| 12250 | err = -EOPNOTSUPP; |
| 12251 | goto out; |
| 12252 | } |
| 12253 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 12254 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12255 | out: |
| 12256 | wdev_unlock(wdev); |
| 12257 | return err; |
| 12258 | } |
| 12259 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12260 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 12261 | struct genl_info *info) |
| 12262 | { |
| 12263 | struct net_device *dev = info->user_ptr[1]; |
| 12264 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12265 | |
| 12266 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12267 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12268 | return -EINVAL; |
| 12269 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12270 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12271 | return -EBUSY; |
| 12272 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12273 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12274 | return 0; |
| 12275 | } |
| 12276 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12277 | static int nl80211_probe_client(struct sk_buff *skb, |
| 12278 | struct genl_info *info) |
| 12279 | { |
| 12280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12281 | struct net_device *dev = info->user_ptr[1]; |
| 12282 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12283 | struct sk_buff *msg; |
| 12284 | void *hdr; |
| 12285 | const u8 *addr; |
| 12286 | u64 cookie; |
| 12287 | int err; |
| 12288 | |
| 12289 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12290 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12291 | return -EOPNOTSUPP; |
| 12292 | |
| 12293 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12294 | return -EINVAL; |
| 12295 | |
| 12296 | if (!rdev->ops->probe_client) |
| 12297 | return -EOPNOTSUPP; |
| 12298 | |
| 12299 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12300 | if (!msg) |
| 12301 | return -ENOMEM; |
| 12302 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12303 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12304 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 12305 | if (!hdr) { |
| 12306 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12307 | goto free_msg; |
| 12308 | } |
| 12309 | |
| 12310 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12311 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 12312 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12313 | if (err) |
| 12314 | goto free_msg; |
| 12315 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12316 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12317 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12318 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12319 | |
| 12320 | genlmsg_end(msg, hdr); |
| 12321 | |
| 12322 | return genlmsg_reply(msg, info); |
| 12323 | |
| 12324 | nla_put_failure: |
| 12325 | err = -ENOBUFS; |
| 12326 | free_msg: |
| 12327 | nlmsg_free(msg); |
| 12328 | return err; |
| 12329 | } |
| 12330 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12331 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 12332 | { |
| 12333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12334 | struct cfg80211_beacon_registration *reg, *nreg; |
| 12335 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12336 | |
| 12337 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 12338 | return -EOPNOTSUPP; |
| 12339 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12340 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 12341 | if (!nreg) |
| 12342 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12343 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12344 | /* First, check if already registered. */ |
| 12345 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12346 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12347 | if (reg->nlportid == info->snd_portid) { |
| 12348 | rv = -EALREADY; |
| 12349 | goto out_err; |
| 12350 | } |
| 12351 | } |
| 12352 | /* Add it to the list */ |
| 12353 | nreg->nlportid = info->snd_portid; |
| 12354 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 12355 | |
| 12356 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12357 | |
| 12358 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12359 | out_err: |
| 12360 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12361 | kfree(nreg); |
| 12362 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12363 | } |
| 12364 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12365 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 12366 | { |
| 12367 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12368 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12369 | int err; |
| 12370 | |
| 12371 | if (!rdev->ops->start_p2p_device) |
| 12372 | return -EOPNOTSUPP; |
| 12373 | |
| 12374 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 12375 | return -EOPNOTSUPP; |
| 12376 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12377 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12378 | return 0; |
| 12379 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 12380 | if (rfkill_blocked(rdev->rfkill)) |
| 12381 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12382 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 12383 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12384 | if (err) |
| 12385 | return err; |
| 12386 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12387 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12388 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12389 | |
| 12390 | return 0; |
| 12391 | } |
| 12392 | |
| 12393 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 12394 | { |
| 12395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12396 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12397 | |
| 12398 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 12399 | return -EOPNOTSUPP; |
| 12400 | |
| 12401 | if (!rdev->ops->stop_p2p_device) |
| 12402 | return -EOPNOTSUPP; |
| 12403 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 12404 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12405 | |
| 12406 | return 0; |
| 12407 | } |
| 12408 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12409 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 12410 | { |
| 12411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12412 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12413 | struct cfg80211_nan_conf conf = {}; |
| 12414 | int err; |
| 12415 | |
| 12416 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12417 | return -EOPNOTSUPP; |
| 12418 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 12419 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12420 | return -EEXIST; |
| 12421 | |
| 12422 | if (rfkill_blocked(rdev->rfkill)) |
| 12423 | return -ERFKILL; |
| 12424 | |
| 12425 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 12426 | return -EINVAL; |
| 12427 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12428 | conf.master_pref = |
| 12429 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12430 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 12431 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 12432 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 12433 | |
| 12434 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 12435 | return -EOPNOTSUPP; |
| 12436 | |
| 12437 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 12438 | return -EINVAL; |
| 12439 | |
| 12440 | conf.bands = bands; |
| 12441 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12442 | |
| 12443 | err = rdev_start_nan(rdev, wdev, &conf); |
| 12444 | if (err) |
| 12445 | return err; |
| 12446 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12447 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12448 | rdev->opencount++; |
| 12449 | |
| 12450 | return 0; |
| 12451 | } |
| 12452 | |
| 12453 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 12454 | { |
| 12455 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12456 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12457 | |
| 12458 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12459 | return -EOPNOTSUPP; |
| 12460 | |
| 12461 | cfg80211_stop_nan(rdev, wdev); |
| 12462 | |
| 12463 | return 0; |
| 12464 | } |
| 12465 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12466 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 12467 | { |
| 12468 | struct nlattr *attr; |
| 12469 | int len = 0, n_entries = 0, rem; |
| 12470 | |
| 12471 | nla_for_each_nested(attr, filter_attr, rem) { |
| 12472 | len += nla_len(attr); |
| 12473 | n_entries++; |
| 12474 | } |
| 12475 | |
| 12476 | if (len >= U8_MAX) |
| 12477 | return -EINVAL; |
| 12478 | |
| 12479 | return n_entries; |
| 12480 | } |
| 12481 | |
| 12482 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 12483 | struct cfg80211_nan_func *func, |
| 12484 | bool tx) |
| 12485 | { |
| 12486 | struct nlattr *attr; |
| 12487 | int n_entries, rem, i; |
| 12488 | struct cfg80211_nan_func_filter *filter; |
| 12489 | |
| 12490 | n_entries = validate_nan_filter(attr_filter); |
| 12491 | if (n_entries < 0) |
| 12492 | return n_entries; |
| 12493 | |
| 12494 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 12495 | |
| 12496 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 12497 | if (!filter) |
| 12498 | return -ENOMEM; |
| 12499 | |
| 12500 | i = 0; |
| 12501 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 12502 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12503 | filter[i].len = nla_len(attr); |
| 12504 | i++; |
| 12505 | } |
| 12506 | if (tx) { |
| 12507 | func->num_tx_filters = n_entries; |
| 12508 | func->tx_filters = filter; |
| 12509 | } else { |
| 12510 | func->num_rx_filters = n_entries; |
| 12511 | func->rx_filters = filter; |
| 12512 | } |
| 12513 | |
| 12514 | return 0; |
| 12515 | } |
| 12516 | |
| 12517 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 12518 | struct genl_info *info) |
| 12519 | { |
| 12520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12521 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12522 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 12523 | struct cfg80211_nan_func *func; |
| 12524 | struct sk_buff *msg = NULL; |
| 12525 | void *hdr = NULL; |
| 12526 | int err = 0; |
| 12527 | |
| 12528 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12529 | return -EOPNOTSUPP; |
| 12530 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12531 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12532 | return -ENOTCONN; |
| 12533 | |
| 12534 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 12535 | return -EINVAL; |
| 12536 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12537 | err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 12538 | info->attrs[NL80211_ATTR_NAN_FUNC], |
| 12539 | nl80211_nan_func_policy, |
| 12540 | info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12541 | if (err) |
| 12542 | return err; |
| 12543 | |
| 12544 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 12545 | if (!func) |
| 12546 | return -ENOMEM; |
| 12547 | |
Johannes Berg | b60ad34 | 2018-10-01 11:52:07 +0200 | [diff] [blame] | 12548 | func->cookie = cfg80211_assign_cookie(rdev); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12549 | |
| 12550 | if (!tb[NL80211_NAN_FUNC_TYPE] || |
| 12551 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { |
| 12552 | err = -EINVAL; |
| 12553 | goto out; |
| 12554 | } |
| 12555 | |
| 12556 | |
| 12557 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 12558 | |
| 12559 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 12560 | err = -EINVAL; |
| 12561 | goto out; |
| 12562 | } |
| 12563 | |
| 12564 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 12565 | sizeof(func->service_id)); |
| 12566 | |
| 12567 | func->close_range = |
| 12568 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 12569 | |
| 12570 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 12571 | func->serv_spec_info_len = |
| 12572 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 12573 | func->serv_spec_info = |
| 12574 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 12575 | func->serv_spec_info_len, |
| 12576 | GFP_KERNEL); |
| 12577 | if (!func->serv_spec_info) { |
| 12578 | err = -ENOMEM; |
| 12579 | goto out; |
| 12580 | } |
| 12581 | } |
| 12582 | |
| 12583 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 12584 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 12585 | |
| 12586 | switch (func->type) { |
| 12587 | case NL80211_NAN_FUNC_PUBLISH: |
| 12588 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 12589 | err = -EINVAL; |
| 12590 | goto out; |
| 12591 | } |
| 12592 | |
| 12593 | func->publish_type = |
| 12594 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 12595 | func->publish_bcast = |
| 12596 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 12597 | |
| 12598 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 12599 | func->publish_bcast) { |
| 12600 | err = -EINVAL; |
| 12601 | goto out; |
| 12602 | } |
| 12603 | break; |
| 12604 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 12605 | func->subscribe_active = |
| 12606 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 12607 | break; |
| 12608 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 12609 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
Hao Chen | 3ea1545 | 2018-01-03 11:00:31 +0800 | [diff] [blame] | 12610 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
| 12611 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12612 | err = -EINVAL; |
| 12613 | goto out; |
| 12614 | } |
| 12615 | |
| 12616 | func->followup_id = |
| 12617 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 12618 | func->followup_reqid = |
| 12619 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 12620 | memcpy(func->followup_dest.addr, |
| 12621 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 12622 | sizeof(func->followup_dest.addr)); |
| 12623 | if (func->ttl) { |
| 12624 | err = -EINVAL; |
| 12625 | goto out; |
| 12626 | } |
| 12627 | break; |
| 12628 | default: |
| 12629 | err = -EINVAL; |
| 12630 | goto out; |
| 12631 | } |
| 12632 | |
| 12633 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 12634 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 12635 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12636 | err = nla_parse_nested_deprecated(srf_tb, |
| 12637 | NL80211_NAN_SRF_ATTR_MAX, |
| 12638 | tb[NL80211_NAN_FUNC_SRF], |
| 12639 | nl80211_nan_srf_policy, |
| 12640 | info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12641 | if (err) |
| 12642 | goto out; |
| 12643 | |
| 12644 | func->srf_include = |
| 12645 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 12646 | |
| 12647 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 12648 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 12649 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 12650 | err = -EINVAL; |
| 12651 | goto out; |
| 12652 | } |
| 12653 | |
| 12654 | func->srf_bf_len = |
| 12655 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 12656 | func->srf_bf = |
| 12657 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 12658 | func->srf_bf_len, GFP_KERNEL); |
| 12659 | if (!func->srf_bf) { |
| 12660 | err = -ENOMEM; |
| 12661 | goto out; |
| 12662 | } |
| 12663 | |
| 12664 | func->srf_bf_idx = |
| 12665 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 12666 | } else { |
| 12667 | struct nlattr *attr, *mac_attr = |
| 12668 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 12669 | int n_entries, rem, i = 0; |
| 12670 | |
| 12671 | if (!mac_attr) { |
| 12672 | err = -EINVAL; |
| 12673 | goto out; |
| 12674 | } |
| 12675 | |
| 12676 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 12677 | if (n_entries <= 0) { |
| 12678 | err = -EINVAL; |
| 12679 | goto out; |
| 12680 | } |
| 12681 | |
| 12682 | func->srf_num_macs = n_entries; |
| 12683 | func->srf_macs = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 12684 | kcalloc(n_entries, sizeof(*func->srf_macs), |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12685 | GFP_KERNEL); |
| 12686 | if (!func->srf_macs) { |
| 12687 | err = -ENOMEM; |
| 12688 | goto out; |
| 12689 | } |
| 12690 | |
| 12691 | nla_for_each_nested(attr, mac_attr, rem) |
| 12692 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 12693 | sizeof(*func->srf_macs)); |
| 12694 | } |
| 12695 | } |
| 12696 | |
| 12697 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 12698 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 12699 | func, true); |
| 12700 | if (err) |
| 12701 | goto out; |
| 12702 | } |
| 12703 | |
| 12704 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 12705 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 12706 | func, false); |
| 12707 | if (err) |
| 12708 | goto out; |
| 12709 | } |
| 12710 | |
| 12711 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12712 | if (!msg) { |
| 12713 | err = -ENOMEM; |
| 12714 | goto out; |
| 12715 | } |
| 12716 | |
| 12717 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12718 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 12719 | /* This can't really happen - we just allocated 4KB */ |
| 12720 | if (WARN_ON(!hdr)) { |
| 12721 | err = -ENOMEM; |
| 12722 | goto out; |
| 12723 | } |
| 12724 | |
| 12725 | err = rdev_add_nan_func(rdev, wdev, func); |
| 12726 | out: |
| 12727 | if (err < 0) { |
| 12728 | cfg80211_free_nan_func(func); |
| 12729 | nlmsg_free(msg); |
| 12730 | return err; |
| 12731 | } |
| 12732 | |
| 12733 | /* propagate the instance id and cookie to userspace */ |
| 12734 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 12735 | NL80211_ATTR_PAD)) |
| 12736 | goto nla_put_failure; |
| 12737 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12738 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12739 | if (!func_attr) |
| 12740 | goto nla_put_failure; |
| 12741 | |
| 12742 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 12743 | func->instance_id)) |
| 12744 | goto nla_put_failure; |
| 12745 | |
| 12746 | nla_nest_end(msg, func_attr); |
| 12747 | |
| 12748 | genlmsg_end(msg, hdr); |
| 12749 | return genlmsg_reply(msg, info); |
| 12750 | |
| 12751 | nla_put_failure: |
| 12752 | nlmsg_free(msg); |
| 12753 | return -ENOBUFS; |
| 12754 | } |
| 12755 | |
| 12756 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 12757 | struct genl_info *info) |
| 12758 | { |
| 12759 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12760 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12761 | u64 cookie; |
| 12762 | |
| 12763 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12764 | return -EOPNOTSUPP; |
| 12765 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12766 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12767 | return -ENOTCONN; |
| 12768 | |
| 12769 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 12770 | return -EINVAL; |
| 12771 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12772 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 12773 | |
| 12774 | rdev_del_nan_func(rdev, wdev, cookie); |
| 12775 | |
| 12776 | return 0; |
| 12777 | } |
| 12778 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12779 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 12780 | struct genl_info *info) |
| 12781 | { |
| 12782 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12783 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12784 | struct cfg80211_nan_conf conf = {}; |
| 12785 | u32 changed = 0; |
| 12786 | |
| 12787 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12788 | return -EOPNOTSUPP; |
| 12789 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12790 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12791 | return -ENOTCONN; |
| 12792 | |
| 12793 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 12794 | conf.master_pref = |
| 12795 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 12796 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 12797 | return -EINVAL; |
| 12798 | |
| 12799 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 12800 | } |
| 12801 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 12802 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 12803 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 12804 | |
| 12805 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 12806 | return -EOPNOTSUPP; |
| 12807 | |
| 12808 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 12809 | return -EINVAL; |
| 12810 | |
| 12811 | conf.bands = bands; |
| 12812 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12813 | } |
| 12814 | |
| 12815 | if (!changed) |
| 12816 | return -EINVAL; |
| 12817 | |
| 12818 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 12819 | } |
| 12820 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 12821 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 12822 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 12823 | { |
| 12824 | struct wiphy *wiphy = wdev->wiphy; |
| 12825 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12826 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 12827 | struct sk_buff *msg; |
| 12828 | void *hdr; |
| 12829 | |
| 12830 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 12831 | return; |
| 12832 | |
| 12833 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12834 | if (!msg) |
| 12835 | return; |
| 12836 | |
| 12837 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 12838 | if (!hdr) { |
| 12839 | nlmsg_free(msg); |
| 12840 | return; |
| 12841 | } |
| 12842 | |
| 12843 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12844 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12845 | wdev->netdev->ifindex)) || |
| 12846 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12847 | NL80211_ATTR_PAD)) |
| 12848 | goto nla_put_failure; |
| 12849 | |
| 12850 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 12851 | NL80211_ATTR_PAD) || |
| 12852 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 12853 | goto nla_put_failure; |
| 12854 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12855 | match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 12856 | if (!match_attr) |
| 12857 | goto nla_put_failure; |
| 12858 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12859 | local_func_attr = nla_nest_start_noflag(msg, |
| 12860 | NL80211_NAN_MATCH_FUNC_LOCAL); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 12861 | if (!local_func_attr) |
| 12862 | goto nla_put_failure; |
| 12863 | |
| 12864 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 12865 | goto nla_put_failure; |
| 12866 | |
| 12867 | nla_nest_end(msg, local_func_attr); |
| 12868 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12869 | peer_func_attr = nla_nest_start_noflag(msg, |
| 12870 | NL80211_NAN_MATCH_FUNC_PEER); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 12871 | if (!peer_func_attr) |
| 12872 | goto nla_put_failure; |
| 12873 | |
| 12874 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 12875 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 12876 | goto nla_put_failure; |
| 12877 | |
| 12878 | if (match->info && match->info_len && |
| 12879 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 12880 | match->info)) |
| 12881 | goto nla_put_failure; |
| 12882 | |
| 12883 | nla_nest_end(msg, peer_func_attr); |
| 12884 | nla_nest_end(msg, match_attr); |
| 12885 | genlmsg_end(msg, hdr); |
| 12886 | |
| 12887 | if (!wdev->owner_nlportid) |
| 12888 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 12889 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 12890 | else |
| 12891 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 12892 | wdev->owner_nlportid); |
| 12893 | |
| 12894 | return; |
| 12895 | |
| 12896 | nla_put_failure: |
| 12897 | nlmsg_free(msg); |
| 12898 | } |
| 12899 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 12900 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 12901 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 12902 | u8 inst_id, |
| 12903 | enum nl80211_nan_func_term_reason reason, |
| 12904 | u64 cookie, gfp_t gfp) |
| 12905 | { |
| 12906 | struct wiphy *wiphy = wdev->wiphy; |
| 12907 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12908 | struct sk_buff *msg; |
| 12909 | struct nlattr *func_attr; |
| 12910 | void *hdr; |
| 12911 | |
| 12912 | if (WARN_ON(!inst_id)) |
| 12913 | return; |
| 12914 | |
| 12915 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12916 | if (!msg) |
| 12917 | return; |
| 12918 | |
| 12919 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 12920 | if (!hdr) { |
| 12921 | nlmsg_free(msg); |
| 12922 | return; |
| 12923 | } |
| 12924 | |
| 12925 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12926 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12927 | wdev->netdev->ifindex)) || |
| 12928 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12929 | NL80211_ATTR_PAD)) |
| 12930 | goto nla_put_failure; |
| 12931 | |
| 12932 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12933 | NL80211_ATTR_PAD)) |
| 12934 | goto nla_put_failure; |
| 12935 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12936 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 12937 | if (!func_attr) |
| 12938 | goto nla_put_failure; |
| 12939 | |
| 12940 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 12941 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 12942 | goto nla_put_failure; |
| 12943 | |
| 12944 | nla_nest_end(msg, func_attr); |
| 12945 | genlmsg_end(msg, hdr); |
| 12946 | |
| 12947 | if (!wdev->owner_nlportid) |
| 12948 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 12949 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 12950 | else |
| 12951 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 12952 | wdev->owner_nlportid); |
| 12953 | |
| 12954 | return; |
| 12955 | |
| 12956 | nla_put_failure: |
| 12957 | nlmsg_free(msg); |
| 12958 | } |
| 12959 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 12960 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 12961 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 12962 | struct genl_info *info) |
| 12963 | { |
| 12964 | void *hdr; |
| 12965 | struct sk_buff *msg; |
| 12966 | |
| 12967 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12968 | if (!msg) |
| 12969 | return -ENOMEM; |
| 12970 | |
| 12971 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12972 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 12973 | if (!hdr) |
| 12974 | goto nla_put_failure; |
| 12975 | |
| 12976 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 12977 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 12978 | goto nla_put_failure; |
| 12979 | |
| 12980 | genlmsg_end(msg, hdr); |
| 12981 | return genlmsg_reply(msg, info); |
| 12982 | |
| 12983 | nla_put_failure: |
| 12984 | kfree_skb(msg); |
| 12985 | return -ENOBUFS; |
| 12986 | } |
| 12987 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12988 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 12989 | { |
| 12990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12991 | struct cfg80211_update_ft_ies_params ft_params; |
| 12992 | struct net_device *dev = info->user_ptr[1]; |
| 12993 | |
| 12994 | if (!rdev->ops->update_ft_ies) |
| 12995 | return -EOPNOTSUPP; |
| 12996 | |
| 12997 | if (!info->attrs[NL80211_ATTR_MDID] || |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 12998 | !info->attrs[NL80211_ATTR_IE]) |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12999 | return -EINVAL; |
| 13000 | |
| 13001 | memset(&ft_params, 0, sizeof(ft_params)); |
| 13002 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 13003 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 13004 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 13005 | |
| 13006 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 13007 | } |
| 13008 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13009 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 13010 | struct genl_info *info) |
| 13011 | { |
| 13012 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13013 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13014 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 13015 | u16 duration; |
| 13016 | int ret; |
| 13017 | |
| 13018 | if (!rdev->ops->crit_proto_start) |
| 13019 | return -EOPNOTSUPP; |
| 13020 | |
| 13021 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 13022 | return -EINVAL; |
| 13023 | |
| 13024 | if (rdev->crit_proto_nlportid) |
| 13025 | return -EBUSY; |
| 13026 | |
| 13027 | /* determine protocol if provided */ |
| 13028 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 13029 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 13030 | |
| 13031 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 13032 | return -EINVAL; |
| 13033 | |
| 13034 | /* timeout must be provided */ |
| 13035 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 13036 | return -EINVAL; |
| 13037 | |
| 13038 | duration = |
| 13039 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 13040 | |
| 13041 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 13042 | return -ERANGE; |
| 13043 | |
| 13044 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 13045 | if (!ret) |
| 13046 | rdev->crit_proto_nlportid = info->snd_portid; |
| 13047 | |
| 13048 | return ret; |
| 13049 | } |
| 13050 | |
| 13051 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 13052 | struct genl_info *info) |
| 13053 | { |
| 13054 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13055 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13056 | |
| 13057 | if (!rdev->ops->crit_proto_stop) |
| 13058 | return -EOPNOTSUPP; |
| 13059 | |
| 13060 | if (rdev->crit_proto_nlportid) { |
| 13061 | rdev->crit_proto_nlportid = 0; |
| 13062 | rdev_crit_proto_stop(rdev, wdev); |
| 13063 | } |
| 13064 | return 0; |
| 13065 | } |
| 13066 | |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13067 | static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, |
| 13068 | struct nlattr *attr, |
| 13069 | struct netlink_ext_ack *extack) |
| 13070 | { |
| 13071 | if (vcmd->policy == VENDOR_CMD_RAW_DATA) { |
| 13072 | if (attr->nla_type & NLA_F_NESTED) { |
| 13073 | NL_SET_ERR_MSG_ATTR(extack, attr, |
| 13074 | "unexpected nested data"); |
| 13075 | return -EINVAL; |
| 13076 | } |
| 13077 | |
| 13078 | return 0; |
| 13079 | } |
| 13080 | |
| 13081 | if (!(attr->nla_type & NLA_F_NESTED)) { |
| 13082 | NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); |
| 13083 | return -EINVAL; |
| 13084 | } |
| 13085 | |
Michal Kubecek | 32d5109 | 2019-12-11 10:58:19 +0100 | [diff] [blame] | 13086 | return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13087 | } |
| 13088 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13089 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 13090 | { |
| 13091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13092 | struct wireless_dev *wdev = |
| 13093 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 13094 | int i, err; |
| 13095 | u32 vid, subcmd; |
| 13096 | |
| 13097 | if (!rdev->wiphy.vendor_commands) |
| 13098 | return -EOPNOTSUPP; |
| 13099 | |
| 13100 | if (IS_ERR(wdev)) { |
| 13101 | err = PTR_ERR(wdev); |
| 13102 | if (err != -EINVAL) |
| 13103 | return err; |
| 13104 | wdev = NULL; |
| 13105 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 13106 | return -EINVAL; |
| 13107 | } |
| 13108 | |
| 13109 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 13110 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 13111 | return -EINVAL; |
| 13112 | |
| 13113 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 13114 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 13115 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 13116 | const struct wiphy_vendor_command *vcmd; |
| 13117 | void *data = NULL; |
| 13118 | int len = 0; |
| 13119 | |
| 13120 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 13121 | |
| 13122 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13123 | continue; |
| 13124 | |
| 13125 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13126 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 13127 | if (!wdev) |
| 13128 | return -EINVAL; |
| 13129 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 13130 | !wdev->netdev) |
| 13131 | return -EINVAL; |
| 13132 | |
| 13133 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13134 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13135 | return -ENETDOWN; |
| 13136 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13137 | |
| 13138 | if (!vcmd->doit) |
| 13139 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13140 | } else { |
| 13141 | wdev = NULL; |
| 13142 | } |
| 13143 | |
| 13144 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 13145 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 13146 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13147 | |
| 13148 | err = nl80211_vendor_check_policy(vcmd, |
| 13149 | info->attrs[NL80211_ATTR_VENDOR_DATA], |
| 13150 | info->extack); |
| 13151 | if (err) |
| 13152 | return err; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13153 | } |
| 13154 | |
| 13155 | rdev->cur_cmd_info = info; |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13156 | err = vcmd->doit(&rdev->wiphy, wdev, data, len); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13157 | rdev->cur_cmd_info = NULL; |
| 13158 | return err; |
| 13159 | } |
| 13160 | |
| 13161 | return -EOPNOTSUPP; |
| 13162 | } |
| 13163 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13164 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 13165 | struct netlink_callback *cb, |
| 13166 | struct cfg80211_registered_device **rdev, |
| 13167 | struct wireless_dev **wdev) |
| 13168 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13169 | struct nlattr **attrbuf; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13170 | u32 vid, subcmd; |
| 13171 | unsigned int i; |
| 13172 | int vcmd_idx = -1; |
| 13173 | int err; |
| 13174 | void *data = NULL; |
| 13175 | unsigned int data_len = 0; |
| 13176 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13177 | if (cb->args[0]) { |
| 13178 | /* subtract the 1 again here */ |
| 13179 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 13180 | struct wireless_dev *tmp; |
| 13181 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13182 | if (!wiphy) |
| 13183 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13184 | *rdev = wiphy_to_rdev(wiphy); |
| 13185 | *wdev = NULL; |
| 13186 | |
| 13187 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 13188 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13189 | if (tmp->identifier == cb->args[1] - 1) { |
| 13190 | *wdev = tmp; |
| 13191 | break; |
| 13192 | } |
| 13193 | } |
| 13194 | } |
| 13195 | |
| 13196 | /* keep rtnl locked in successful case */ |
| 13197 | return 0; |
| 13198 | } |
| 13199 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13200 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 13201 | if (!attrbuf) |
| 13202 | return -ENOMEM; |
| 13203 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 13204 | err = nlmsg_parse_deprecated(cb->nlh, |
| 13205 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 13206 | attrbuf, nl80211_fam.maxattr, |
| 13207 | nl80211_policy, NULL); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13208 | if (err) |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13209 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13210 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13211 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13212 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 13213 | err = -EINVAL; |
| 13214 | goto out; |
| 13215 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13216 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13217 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13218 | if (IS_ERR(*wdev)) |
| 13219 | *wdev = NULL; |
| 13220 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13221 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13222 | if (IS_ERR(*rdev)) { |
| 13223 | err = PTR_ERR(*rdev); |
| 13224 | goto out; |
| 13225 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13226 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13227 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 13228 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13229 | |
| 13230 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 13231 | const struct wiphy_vendor_command *vcmd; |
| 13232 | |
| 13233 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 13234 | |
| 13235 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13236 | continue; |
| 13237 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13238 | if (!vcmd->dumpit) { |
| 13239 | err = -EOPNOTSUPP; |
| 13240 | goto out; |
| 13241 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13242 | |
| 13243 | vcmd_idx = i; |
| 13244 | break; |
| 13245 | } |
| 13246 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13247 | if (vcmd_idx < 0) { |
| 13248 | err = -EOPNOTSUPP; |
| 13249 | goto out; |
| 13250 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13251 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13252 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 13253 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 13254 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13255 | |
| 13256 | err = nl80211_vendor_check_policy( |
| 13257 | &(*rdev)->wiphy.vendor_commands[vcmd_idx], |
| 13258 | attrbuf[NL80211_ATTR_VENDOR_DATA], |
| 13259 | cb->extack); |
| 13260 | if (err) |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13261 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13262 | } |
| 13263 | |
| 13264 | /* 0 is the first index - add 1 to parse only once */ |
| 13265 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 13266 | /* add 1 to know if it was NULL */ |
| 13267 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 13268 | cb->args[2] = vcmd_idx; |
| 13269 | cb->args[3] = (unsigned long)data; |
| 13270 | cb->args[4] = data_len; |
| 13271 | |
| 13272 | /* keep rtnl locked in successful case */ |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13273 | err = 0; |
| 13274 | out: |
| 13275 | kfree(attrbuf); |
| 13276 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13277 | } |
| 13278 | |
| 13279 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 13280 | struct netlink_callback *cb) |
| 13281 | { |
| 13282 | struct cfg80211_registered_device *rdev; |
| 13283 | struct wireless_dev *wdev; |
| 13284 | unsigned int vcmd_idx; |
| 13285 | const struct wiphy_vendor_command *vcmd; |
| 13286 | void *data; |
| 13287 | int data_len; |
| 13288 | int err; |
| 13289 | struct nlattr *vendor_data; |
| 13290 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13291 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13292 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 13293 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13294 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13295 | |
| 13296 | vcmd_idx = cb->args[2]; |
| 13297 | data = (void *)cb->args[3]; |
| 13298 | data_len = cb->args[4]; |
| 13299 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 13300 | |
| 13301 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13302 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13303 | if (!wdev) { |
| 13304 | err = -EINVAL; |
| 13305 | goto out; |
| 13306 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13307 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13308 | !wdev->netdev) { |
| 13309 | err = -EINVAL; |
| 13310 | goto out; |
| 13311 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13312 | |
| 13313 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13314 | if (!wdev_running(wdev)) { |
| 13315 | err = -ENETDOWN; |
| 13316 | goto out; |
| 13317 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13318 | } |
| 13319 | } |
| 13320 | |
| 13321 | while (1) { |
| 13322 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 13323 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 13324 | NL80211_CMD_VENDOR); |
| 13325 | if (!hdr) |
| 13326 | break; |
| 13327 | |
| 13328 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13329 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 13330 | wdev_id(wdev), |
| 13331 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13332 | genlmsg_cancel(skb, hdr); |
| 13333 | break; |
| 13334 | } |
| 13335 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13336 | vendor_data = nla_nest_start_noflag(skb, |
| 13337 | NL80211_ATTR_VENDOR_DATA); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13338 | if (!vendor_data) { |
| 13339 | genlmsg_cancel(skb, hdr); |
| 13340 | break; |
| 13341 | } |
| 13342 | |
| 13343 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 13344 | (unsigned long *)&cb->args[5]); |
| 13345 | nla_nest_end(skb, vendor_data); |
| 13346 | |
| 13347 | if (err == -ENOBUFS || err == -ENOENT) { |
| 13348 | genlmsg_cancel(skb, hdr); |
| 13349 | break; |
| 13350 | } else if (err) { |
| 13351 | genlmsg_cancel(skb, hdr); |
| 13352 | goto out; |
| 13353 | } |
| 13354 | |
| 13355 | genlmsg_end(skb, hdr); |
| 13356 | } |
| 13357 | |
| 13358 | err = skb->len; |
| 13359 | out: |
| 13360 | rtnl_unlock(); |
| 13361 | return err; |
| 13362 | } |
| 13363 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13364 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 13365 | enum nl80211_commands cmd, |
| 13366 | enum nl80211_attrs attr, |
| 13367 | int approxlen) |
| 13368 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13369 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13370 | |
| 13371 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 13372 | return NULL; |
| 13373 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 13374 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13375 | rdev->cur_cmd_info->snd_portid, |
| 13376 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 13377 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13378 | } |
| 13379 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 13380 | |
| 13381 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 13382 | { |
| 13383 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 13384 | void *hdr = ((void **)skb->cb)[1]; |
| 13385 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 13386 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 13387 | /* clear CB data for netlink core to own from now on */ |
| 13388 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 13389 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13390 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 13391 | kfree_skb(skb); |
| 13392 | return -EINVAL; |
| 13393 | } |
| 13394 | |
| 13395 | nla_nest_end(skb, data); |
| 13396 | genlmsg_end(skb, hdr); |
| 13397 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 13398 | } |
| 13399 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 13400 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 13401 | unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) |
| 13402 | { |
| 13403 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13404 | |
| 13405 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 13406 | return 0; |
| 13407 | |
| 13408 | return rdev->cur_cmd_info->snd_portid; |
| 13409 | } |
| 13410 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); |
| 13411 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13412 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 13413 | struct genl_info *info) |
| 13414 | { |
| 13415 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13416 | struct cfg80211_qos_map *qos_map = NULL; |
| 13417 | struct net_device *dev = info->user_ptr[1]; |
| 13418 | u8 *pos, len, num_des, des_len, des; |
| 13419 | int ret; |
| 13420 | |
| 13421 | if (!rdev->ops->set_qos_map) |
| 13422 | return -EOPNOTSUPP; |
| 13423 | |
| 13424 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 13425 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 13426 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 13427 | |
| 13428 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 13429 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 13430 | return -EINVAL; |
| 13431 | |
| 13432 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 13433 | if (!qos_map) |
| 13434 | return -ENOMEM; |
| 13435 | |
| 13436 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 13437 | if (num_des) { |
| 13438 | des_len = num_des * |
| 13439 | sizeof(struct cfg80211_dscp_exception); |
| 13440 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 13441 | qos_map->num_des = num_des; |
| 13442 | for (des = 0; des < num_des; des++) { |
| 13443 | if (qos_map->dscp_exception[des].up > 7) { |
| 13444 | kfree(qos_map); |
| 13445 | return -EINVAL; |
| 13446 | } |
| 13447 | } |
| 13448 | pos += des_len; |
| 13449 | } |
| 13450 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 13451 | } |
| 13452 | |
| 13453 | wdev_lock(dev->ieee80211_ptr); |
| 13454 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 13455 | if (!ret) |
| 13456 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 13457 | wdev_unlock(dev->ieee80211_ptr); |
| 13458 | |
| 13459 | kfree(qos_map); |
| 13460 | return ret; |
| 13461 | } |
| 13462 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13463 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 13464 | { |
| 13465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13466 | struct net_device *dev = info->user_ptr[1]; |
| 13467 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13468 | const u8 *peer; |
| 13469 | u8 tsid, up; |
| 13470 | u16 admitted_time = 0; |
| 13471 | int err; |
| 13472 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13473 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13474 | return -EOPNOTSUPP; |
| 13475 | |
| 13476 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 13477 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 13478 | return -EINVAL; |
| 13479 | |
| 13480 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13481 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13482 | |
| 13483 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13484 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13485 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13486 | * need more attributes for that (e.g. BA session requirement); |
| 13487 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13488 | */ |
| 13489 | return -EINVAL; |
| 13490 | } |
| 13491 | |
| 13492 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13493 | |
| 13494 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 13495 | admitted_time = |
| 13496 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 13497 | if (!admitted_time) |
| 13498 | return -EINVAL; |
| 13499 | } |
| 13500 | |
| 13501 | wdev_lock(wdev); |
| 13502 | switch (wdev->iftype) { |
| 13503 | case NL80211_IFTYPE_STATION: |
| 13504 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13505 | if (wdev->current_bss) |
| 13506 | break; |
| 13507 | err = -ENOTCONN; |
| 13508 | goto out; |
| 13509 | default: |
| 13510 | err = -EOPNOTSUPP; |
| 13511 | goto out; |
| 13512 | } |
| 13513 | |
| 13514 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 13515 | |
| 13516 | out: |
| 13517 | wdev_unlock(wdev); |
| 13518 | return err; |
| 13519 | } |
| 13520 | |
| 13521 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 13522 | { |
| 13523 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13524 | struct net_device *dev = info->user_ptr[1]; |
| 13525 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13526 | const u8 *peer; |
| 13527 | u8 tsid; |
| 13528 | int err; |
| 13529 | |
| 13530 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 13531 | return -EINVAL; |
| 13532 | |
| 13533 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 13534 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13535 | |
| 13536 | wdev_lock(wdev); |
| 13537 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 13538 | wdev_unlock(wdev); |
| 13539 | |
| 13540 | return err; |
| 13541 | } |
| 13542 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13543 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 13544 | struct genl_info *info) |
| 13545 | { |
| 13546 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13547 | struct net_device *dev = info->user_ptr[1]; |
| 13548 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13549 | struct cfg80211_chan_def chandef = {}; |
| 13550 | const u8 *addr; |
| 13551 | u8 oper_class; |
| 13552 | int err; |
| 13553 | |
| 13554 | if (!rdev->ops->tdls_channel_switch || |
| 13555 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 13556 | return -EOPNOTSUPP; |
| 13557 | |
| 13558 | switch (dev->ieee80211_ptr->iftype) { |
| 13559 | case NL80211_IFTYPE_STATION: |
| 13560 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13561 | break; |
| 13562 | default: |
| 13563 | return -EOPNOTSUPP; |
| 13564 | } |
| 13565 | |
| 13566 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 13567 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 13568 | return -EINVAL; |
| 13569 | |
| 13570 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 13571 | if (err) |
| 13572 | return err; |
| 13573 | |
| 13574 | /* |
| 13575 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 13576 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 13577 | * specification is not defined for them. |
| 13578 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 13579 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13580 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 13581 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 13582 | return -EINVAL; |
| 13583 | |
| 13584 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 13585 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 13586 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13587 | return -EINVAL; |
| 13588 | |
| 13589 | /* don't allow switching to DFS channels */ |
| 13590 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 13591 | return -EINVAL; |
| 13592 | |
| 13593 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13594 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 13595 | |
| 13596 | wdev_lock(wdev); |
| 13597 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 13598 | wdev_unlock(wdev); |
| 13599 | |
| 13600 | return err; |
| 13601 | } |
| 13602 | |
| 13603 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 13604 | struct genl_info *info) |
| 13605 | { |
| 13606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13607 | struct net_device *dev = info->user_ptr[1]; |
| 13608 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13609 | const u8 *addr; |
| 13610 | |
| 13611 | if (!rdev->ops->tdls_channel_switch || |
| 13612 | !rdev->ops->tdls_cancel_channel_switch || |
| 13613 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 13614 | return -EOPNOTSUPP; |
| 13615 | |
| 13616 | switch (dev->ieee80211_ptr->iftype) { |
| 13617 | case NL80211_IFTYPE_STATION: |
| 13618 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13619 | break; |
| 13620 | default: |
| 13621 | return -EOPNOTSUPP; |
| 13622 | } |
| 13623 | |
| 13624 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 13625 | return -EINVAL; |
| 13626 | |
| 13627 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13628 | |
| 13629 | wdev_lock(wdev); |
| 13630 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 13631 | wdev_unlock(wdev); |
| 13632 | |
| 13633 | return 0; |
| 13634 | } |
| 13635 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13636 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 13637 | struct genl_info *info) |
| 13638 | { |
| 13639 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13640 | struct net_device *dev = info->user_ptr[1]; |
| 13641 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13642 | const struct nlattr *nla; |
| 13643 | bool enabled; |
| 13644 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13645 | if (!rdev->ops->set_multicast_to_unicast) |
| 13646 | return -EOPNOTSUPP; |
| 13647 | |
| 13648 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 13649 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 13650 | return -EOPNOTSUPP; |
| 13651 | |
| 13652 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 13653 | enabled = nla_get_flag(nla); |
| 13654 | |
| 13655 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 13656 | } |
| 13657 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 13658 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 13659 | { |
| 13660 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13661 | struct net_device *dev = info->user_ptr[1]; |
| 13662 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13663 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 13664 | int ret; |
| 13665 | |
| 13666 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 13667 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 13668 | return -EOPNOTSUPP; |
| 13669 | |
| 13670 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 13671 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 13672 | return -EOPNOTSUPP; |
| 13673 | |
| 13674 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 13675 | return -EINVAL; |
| 13676 | |
| 13677 | wdev_lock(wdev); |
| 13678 | if (!wdev->current_bss) { |
| 13679 | ret = -ENOTCONN; |
| 13680 | goto out; |
| 13681 | } |
| 13682 | |
| 13683 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13684 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 13685 | ret = -EINVAL; |
| 13686 | goto out; |
| 13687 | } |
| 13688 | |
| 13689 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 13690 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 13691 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 13692 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 13693 | ret = -EINVAL; |
| 13694 | goto out; |
| 13695 | } |
| 13696 | |
| 13697 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { |
| 13698 | int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 13699 | |
| 13700 | if (r0_name_len != WLAN_PMK_NAME_LEN) { |
| 13701 | ret = -EINVAL; |
| 13702 | goto out; |
| 13703 | } |
| 13704 | |
| 13705 | pmk_conf.pmk_r0_name = |
| 13706 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 13707 | } |
| 13708 | |
| 13709 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 13710 | out: |
| 13711 | wdev_unlock(wdev); |
| 13712 | return ret; |
| 13713 | } |
| 13714 | |
| 13715 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 13716 | { |
| 13717 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13718 | struct net_device *dev = info->user_ptr[1]; |
| 13719 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13720 | const u8 *aa; |
| 13721 | int ret; |
| 13722 | |
| 13723 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 13724 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 13725 | return -EOPNOTSUPP; |
| 13726 | |
| 13727 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 13728 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 13729 | return -EOPNOTSUPP; |
| 13730 | |
| 13731 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 13732 | return -EINVAL; |
| 13733 | |
| 13734 | wdev_lock(wdev); |
| 13735 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13736 | ret = rdev_del_pmk(rdev, dev, aa); |
| 13737 | wdev_unlock(wdev); |
| 13738 | |
| 13739 | return ret; |
| 13740 | } |
| 13741 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13742 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
| 13743 | { |
| 13744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13745 | struct net_device *dev = info->user_ptr[1]; |
| 13746 | struct cfg80211_external_auth_params params; |
| 13747 | |
Srinivas Dasari | db8d93a | 2018-02-02 11:15:27 +0200 | [diff] [blame] | 13748 | if (!rdev->ops->external_auth) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13749 | return -EOPNOTSUPP; |
| 13750 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 13751 | if (!info->attrs[NL80211_ATTR_SSID] && |
| 13752 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 13753 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13754 | return -EINVAL; |
| 13755 | |
| 13756 | if (!info->attrs[NL80211_ATTR_BSSID]) |
| 13757 | return -EINVAL; |
| 13758 | |
| 13759 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) |
| 13760 | return -EINVAL; |
| 13761 | |
| 13762 | memset(¶ms, 0, sizeof(params)); |
| 13763 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 13764 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 13765 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 13766 | if (params.ssid.ssid_len == 0 || |
| 13767 | params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 13768 | return -EINVAL; |
| 13769 | memcpy(params.ssid.ssid, |
| 13770 | nla_data(info->attrs[NL80211_ATTR_SSID]), |
| 13771 | params.ssid.ssid_len); |
| 13772 | } |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13773 | |
| 13774 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), |
| 13775 | ETH_ALEN); |
| 13776 | |
| 13777 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 13778 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 13779 | if (info->attrs[NL80211_ATTR_PMKID]) |
| 13780 | params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 13781 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13782 | return rdev_external_auth(rdev, dev, ¶ms); |
| 13783 | } |
| 13784 | |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 13785 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) |
| 13786 | { |
| 13787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13788 | struct net_device *dev = info->user_ptr[1]; |
| 13789 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13790 | const u8 *buf; |
| 13791 | size_t len; |
| 13792 | u8 *dest; |
| 13793 | u16 proto; |
| 13794 | bool noencrypt; |
| 13795 | int err; |
| 13796 | |
| 13797 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 13798 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 13799 | return -EOPNOTSUPP; |
| 13800 | |
| 13801 | if (!rdev->ops->tx_control_port) |
| 13802 | return -EOPNOTSUPP; |
| 13803 | |
| 13804 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 13805 | !info->attrs[NL80211_ATTR_MAC] || |
| 13806 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 13807 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); |
| 13808 | return -EINVAL; |
| 13809 | } |
| 13810 | |
| 13811 | wdev_lock(wdev); |
| 13812 | |
| 13813 | switch (wdev->iftype) { |
| 13814 | case NL80211_IFTYPE_AP: |
| 13815 | case NL80211_IFTYPE_P2P_GO: |
| 13816 | case NL80211_IFTYPE_MESH_POINT: |
| 13817 | break; |
| 13818 | case NL80211_IFTYPE_ADHOC: |
| 13819 | case NL80211_IFTYPE_STATION: |
| 13820 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13821 | if (wdev->current_bss) |
| 13822 | break; |
| 13823 | err = -ENOTCONN; |
| 13824 | goto out; |
| 13825 | default: |
| 13826 | err = -EOPNOTSUPP; |
| 13827 | goto out; |
| 13828 | } |
| 13829 | |
| 13830 | wdev_unlock(wdev); |
| 13831 | |
| 13832 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 13833 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 13834 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13835 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 13836 | noencrypt = |
| 13837 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); |
| 13838 | |
| 13839 | return rdev_tx_control_port(rdev, dev, buf, len, |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 13840 | dest, cpu_to_be16(proto), noencrypt); |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 13841 | |
| 13842 | out: |
| 13843 | wdev_unlock(wdev); |
| 13844 | return err; |
| 13845 | } |
| 13846 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 13847 | static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, |
| 13848 | struct genl_info *info) |
| 13849 | { |
| 13850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13851 | struct net_device *dev = info->user_ptr[1]; |
| 13852 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13853 | struct cfg80211_ftm_responder_stats ftm_stats = {}; |
| 13854 | struct sk_buff *msg; |
| 13855 | void *hdr; |
| 13856 | struct nlattr *ftm_stats_attr; |
| 13857 | int err; |
| 13858 | |
| 13859 | if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) |
| 13860 | return -EOPNOTSUPP; |
| 13861 | |
| 13862 | err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); |
| 13863 | if (err) |
| 13864 | return err; |
| 13865 | |
| 13866 | if (!ftm_stats.filled) |
| 13867 | return -ENODATA; |
| 13868 | |
| 13869 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13870 | if (!msg) |
| 13871 | return -ENOMEM; |
| 13872 | |
| 13873 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13874 | NL80211_CMD_GET_FTM_RESPONDER_STATS); |
| 13875 | if (!hdr) |
Navid Emamdoost | 1399c59 | 2019-10-04 14:42:19 -0500 | [diff] [blame] | 13876 | goto nla_put_failure; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 13877 | |
| 13878 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 13879 | goto nla_put_failure; |
| 13880 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13881 | ftm_stats_attr = nla_nest_start_noflag(msg, |
| 13882 | NL80211_ATTR_FTM_RESPONDER_STATS); |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 13883 | if (!ftm_stats_attr) |
| 13884 | goto nla_put_failure; |
| 13885 | |
| 13886 | #define SET_FTM(field, name, type) \ |
| 13887 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 13888 | nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ |
| 13889 | ftm_stats.field)) \ |
| 13890 | goto nla_put_failure; } while (0) |
| 13891 | #define SET_FTM_U64(field, name) \ |
| 13892 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 13893 | nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ |
| 13894 | ftm_stats.field, NL80211_FTM_STATS_PAD)) \ |
| 13895 | goto nla_put_failure; } while (0) |
| 13896 | |
| 13897 | SET_FTM(success_num, SUCCESS_NUM, u32); |
| 13898 | SET_FTM(partial_num, PARTIAL_NUM, u32); |
| 13899 | SET_FTM(failed_num, FAILED_NUM, u32); |
| 13900 | SET_FTM(asap_num, ASAP_NUM, u32); |
| 13901 | SET_FTM(non_asap_num, NON_ASAP_NUM, u32); |
| 13902 | SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); |
| 13903 | SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); |
| 13904 | SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); |
| 13905 | SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); |
| 13906 | #undef SET_FTM |
| 13907 | |
| 13908 | nla_nest_end(msg, ftm_stats_attr); |
| 13909 | |
| 13910 | genlmsg_end(msg, hdr); |
| 13911 | return genlmsg_reply(msg, info); |
| 13912 | |
| 13913 | nla_put_failure: |
| 13914 | nlmsg_free(msg); |
| 13915 | return -ENOBUFS; |
| 13916 | } |
| 13917 | |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 13918 | static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) |
| 13919 | { |
| 13920 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13921 | struct cfg80211_update_owe_info owe_info; |
| 13922 | struct net_device *dev = info->user_ptr[1]; |
| 13923 | |
| 13924 | if (!rdev->ops->update_owe_info) |
| 13925 | return -EOPNOTSUPP; |
| 13926 | |
| 13927 | if (!info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 13928 | !info->attrs[NL80211_ATTR_MAC]) |
| 13929 | return -EINVAL; |
| 13930 | |
| 13931 | memset(&owe_info, 0, sizeof(owe_info)); |
| 13932 | owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 13933 | nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); |
| 13934 | |
| 13935 | if (info->attrs[NL80211_ATTR_IE]) { |
| 13936 | owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 13937 | owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 13938 | } |
| 13939 | |
| 13940 | return rdev_update_owe_info(rdev, dev, &owe_info); |
| 13941 | } |
| 13942 | |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 13943 | static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) |
| 13944 | { |
| 13945 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13946 | struct net_device *dev = info->user_ptr[1]; |
| 13947 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13948 | struct station_info sinfo = {}; |
| 13949 | const u8 *buf; |
| 13950 | size_t len; |
| 13951 | u8 *dest; |
| 13952 | int err; |
| 13953 | |
| 13954 | if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) |
| 13955 | return -EOPNOTSUPP; |
| 13956 | |
| 13957 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 13958 | !info->attrs[NL80211_ATTR_FRAME]) { |
| 13959 | GENL_SET_ERR_MSG(info, "Frame or MAC missing"); |
| 13960 | return -EINVAL; |
| 13961 | } |
| 13962 | |
| 13963 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 13964 | return -EOPNOTSUPP; |
| 13965 | |
| 13966 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13967 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 13968 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 13969 | |
| 13970 | if (len < sizeof(struct ethhdr)) |
| 13971 | return -EINVAL; |
| 13972 | |
| 13973 | if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || |
| 13974 | !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) |
| 13975 | return -EINVAL; |
| 13976 | |
| 13977 | err = rdev_get_station(rdev, dev, dest, &sinfo); |
| 13978 | if (err) |
| 13979 | return err; |
| 13980 | |
Felix Fietkau | 2a279b34 | 2020-01-08 18:06:29 +0100 | [diff] [blame] | 13981 | cfg80211_sinfo_release_content(&sinfo); |
| 13982 | |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 13983 | return rdev_probe_mesh_link(rdev, dev, dest, buf, len); |
| 13984 | } |
| 13985 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 13986 | static int parse_tid_conf(struct cfg80211_registered_device *rdev, |
| 13987 | struct nlattr *attrs[], struct net_device *dev, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 13988 | struct cfg80211_tid_cfg *tid_conf, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 13989 | struct genl_info *info, const u8 *peer) |
| 13990 | { |
| 13991 | struct netlink_ext_ack *extack = info->extack; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 13992 | u64 mask; |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 13993 | int err; |
| 13994 | |
| 13995 | if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) |
| 13996 | return -EINVAL; |
| 13997 | |
| 13998 | tid_conf->config_override = |
| 13999 | nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 14000 | tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14001 | |
| 14002 | if (tid_conf->config_override) { |
| 14003 | if (rdev->ops->reset_tid_config) { |
| 14004 | err = rdev_reset_tid_config(rdev, dev, peer, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 14005 | tid_conf->tids); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14006 | /* If peer is there no other configuration will be |
| 14007 | * allowed |
| 14008 | */ |
| 14009 | if (err || peer) |
| 14010 | return err; |
| 14011 | } else { |
| 14012 | return -EINVAL; |
| 14013 | } |
| 14014 | } |
| 14015 | |
| 14016 | if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 14017 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14018 | tid_conf->noack = |
| 14019 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); |
| 14020 | } |
| 14021 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 14022 | if (peer) |
| 14023 | mask = rdev->wiphy.tid_config_support.peer; |
| 14024 | else |
| 14025 | mask = rdev->wiphy.tid_config_support.vif; |
| 14026 | |
| 14027 | if (tid_conf->mask & ~mask) { |
| 14028 | NL_SET_ERR_MSG(extack, "unsupported TID configuration"); |
| 14029 | return -ENOTSUPP; |
| 14030 | } |
| 14031 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14032 | return 0; |
| 14033 | } |
| 14034 | |
| 14035 | static int nl80211_set_tid_config(struct sk_buff *skb, |
| 14036 | struct genl_info *info) |
| 14037 | { |
| 14038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14039 | struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; |
| 14040 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame^] | 14041 | struct cfg80211_tid_config *tid_config; |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14042 | struct nlattr *tid; |
| 14043 | int conf_idx = 0, rem_conf; |
| 14044 | int ret = -EINVAL; |
| 14045 | u32 num_conf = 0; |
| 14046 | |
| 14047 | if (!info->attrs[NL80211_ATTR_TID_CONFIG]) |
| 14048 | return -EINVAL; |
| 14049 | |
| 14050 | if (!rdev->ops->set_tid_config) |
| 14051 | return -EOPNOTSUPP; |
| 14052 | |
| 14053 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14054 | rem_conf) |
| 14055 | num_conf++; |
| 14056 | |
| 14057 | tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), |
| 14058 | GFP_KERNEL); |
| 14059 | if (!tid_config) |
| 14060 | return -ENOMEM; |
| 14061 | |
| 14062 | tid_config->n_tid_conf = num_conf; |
| 14063 | |
| 14064 | if (info->attrs[NL80211_ATTR_MAC]) |
| 14065 | tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14066 | |
| 14067 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14068 | rem_conf) { |
| 14069 | ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, |
| 14070 | tid, NULL, NULL); |
| 14071 | |
| 14072 | if (ret) |
| 14073 | goto bad_tid_conf; |
| 14074 | |
| 14075 | ret = parse_tid_conf(rdev, attrs, dev, |
| 14076 | &tid_config->tid_conf[conf_idx], |
| 14077 | info, tid_config->peer); |
| 14078 | if (ret) |
| 14079 | goto bad_tid_conf; |
| 14080 | |
| 14081 | conf_idx++; |
| 14082 | } |
| 14083 | |
| 14084 | ret = rdev_set_tid_config(rdev, dev, tid_config); |
| 14085 | |
| 14086 | bad_tid_conf: |
| 14087 | kfree(tid_config); |
| 14088 | return ret; |
| 14089 | } |
| 14090 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14091 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 14092 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 14093 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14094 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 14095 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 14096 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14097 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14098 | /* If a netdev is associated, it must be UP, P2P must be started */ |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14099 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 14100 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14101 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14102 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 14103 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14104 | struct genl_info *info) |
| 14105 | { |
| 14106 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14107 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14108 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14109 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 14110 | |
| 14111 | if (rtnl) |
| 14112 | rtnl_lock(); |
| 14113 | |
| 14114 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 14115 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14116 | if (IS_ERR(rdev)) { |
| 14117 | if (rtnl) |
| 14118 | rtnl_unlock(); |
| 14119 | return PTR_ERR(rdev); |
| 14120 | } |
| 14121 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14122 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 14123 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14124 | ASSERT_RTNL(); |
| 14125 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14126 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 14127 | info->attrs); |
| 14128 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14129 | if (rtnl) |
| 14130 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14131 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14132 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14133 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14134 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14135 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14136 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14137 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 14138 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14139 | if (rtnl) |
| 14140 | rtnl_unlock(); |
| 14141 | return -EINVAL; |
| 14142 | } |
| 14143 | |
| 14144 | info->user_ptr[1] = dev; |
| 14145 | } else { |
| 14146 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14147 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14148 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 14149 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 14150 | !wdev_running(wdev)) { |
| 14151 | if (rtnl) |
| 14152 | rtnl_unlock(); |
| 14153 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14154 | } |
| 14155 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 14156 | if (dev) |
| 14157 | dev_hold(dev); |
| 14158 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14159 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14160 | } |
| 14161 | |
| 14162 | return 0; |
| 14163 | } |
| 14164 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 14165 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14166 | struct genl_info *info) |
| 14167 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14168 | if (info->user_ptr[1]) { |
| 14169 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 14170 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 14171 | |
| 14172 | if (wdev->netdev) |
| 14173 | dev_put(wdev->netdev); |
| 14174 | } else { |
| 14175 | dev_put(info->user_ptr[1]); |
| 14176 | } |
| 14177 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14178 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14179 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 14180 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14181 | |
| 14182 | /* If needed, clear the netlink message payload from the SKB |
| 14183 | * as it might contain key data that shouldn't stick around on |
| 14184 | * the heap after the SKB is freed. The netlink message header |
| 14185 | * is still needed for further processing, so leave it intact. |
| 14186 | */ |
| 14187 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 14188 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 14189 | |
| 14190 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 14191 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14192 | } |
| 14193 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 14194 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14195 | { |
| 14196 | .cmd = NL80211_CMD_GET_WIPHY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14197 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14198 | .doit = nl80211_get_wiphy, |
| 14199 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 14200 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14201 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14202 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14203 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14204 | }, |
| 14205 | { |
| 14206 | .cmd = NL80211_CMD_SET_WIPHY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14207 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14208 | .doit = nl80211_set_wiphy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14209 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14210 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14211 | }, |
| 14212 | { |
| 14213 | .cmd = NL80211_CMD_GET_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14214 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14215 | .doit = nl80211_get_interface, |
| 14216 | .dumpit = nl80211_dump_interface, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14217 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14218 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 14219 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14220 | }, |
| 14221 | { |
| 14222 | .cmd = NL80211_CMD_SET_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14223 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14224 | .doit = nl80211_set_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14225 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14226 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14227 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14228 | }, |
| 14229 | { |
| 14230 | .cmd = NL80211_CMD_NEW_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14231 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14232 | .doit = nl80211_new_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14233 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14234 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14235 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14236 | }, |
| 14237 | { |
| 14238 | .cmd = NL80211_CMD_DEL_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14239 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14240 | .doit = nl80211_del_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14241 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 14242 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14243 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14244 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14245 | { |
| 14246 | .cmd = NL80211_CMD_GET_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14247 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14248 | .doit = nl80211_get_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14249 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14250 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14251 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14252 | }, |
| 14253 | { |
| 14254 | .cmd = NL80211_CMD_SET_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14255 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14256 | .doit = nl80211_set_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14257 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14258 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14259 | NL80211_FLAG_NEED_RTNL | |
| 14260 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14261 | }, |
| 14262 | { |
| 14263 | .cmd = NL80211_CMD_NEW_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14264 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14265 | .doit = nl80211_new_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14266 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14267 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14268 | NL80211_FLAG_NEED_RTNL | |
| 14269 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14270 | }, |
| 14271 | { |
| 14272 | .cmd = NL80211_CMD_DEL_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14273 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14274 | .doit = nl80211_del_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14275 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14276 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14277 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14278 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14279 | { |
| 14280 | .cmd = NL80211_CMD_SET_BEACON, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14281 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14282 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14283 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14284 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14285 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14286 | }, |
| 14287 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14288 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14289 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14290 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14291 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14292 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14293 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14294 | }, |
| 14295 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14296 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14297 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14298 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14299 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14300 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14301 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14302 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14303 | { |
| 14304 | .cmd = NL80211_CMD_GET_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14305 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14306 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14307 | .dumpit = nl80211_dump_station, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14308 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14309 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14310 | }, |
| 14311 | { |
| 14312 | .cmd = NL80211_CMD_SET_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14313 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14314 | .doit = nl80211_set_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14315 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14316 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14317 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14318 | }, |
| 14319 | { |
| 14320 | .cmd = NL80211_CMD_NEW_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14321 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14322 | .doit = nl80211_new_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14323 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14324 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14325 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14326 | }, |
| 14327 | { |
| 14328 | .cmd = NL80211_CMD_DEL_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14329 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14330 | .doit = nl80211_del_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14331 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14332 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14333 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14334 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14335 | { |
| 14336 | .cmd = NL80211_CMD_GET_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14337 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14338 | .doit = nl80211_get_mpath, |
| 14339 | .dumpit = nl80211_dump_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14340 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14341 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14342 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14343 | }, |
| 14344 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14345 | .cmd = NL80211_CMD_GET_MPP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14346 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14347 | .doit = nl80211_get_mpp, |
| 14348 | .dumpit = nl80211_dump_mpp, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14349 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14350 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14351 | NL80211_FLAG_NEED_RTNL, |
| 14352 | }, |
| 14353 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14354 | .cmd = NL80211_CMD_SET_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14355 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14356 | .doit = nl80211_set_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14357 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14358 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14359 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14360 | }, |
| 14361 | { |
| 14362 | .cmd = NL80211_CMD_NEW_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14363 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14364 | .doit = nl80211_new_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14365 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14366 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14367 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14368 | }, |
| 14369 | { |
| 14370 | .cmd = NL80211_CMD_DEL_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14371 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14372 | .doit = nl80211_del_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14373 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14374 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14375 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14376 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14377 | { |
| 14378 | .cmd = NL80211_CMD_SET_BSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14379 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14380 | .doit = nl80211_set_bss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14381 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14382 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14383 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14384 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14385 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14386 | .cmd = NL80211_CMD_GET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14387 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 14388 | .doit = nl80211_get_reg_do, |
| 14389 | .dumpit = nl80211_get_reg_dump, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14390 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14391 | /* can be retrieved by unprivileged users */ |
| 14392 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 14393 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14394 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14395 | .cmd = NL80211_CMD_SET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14396 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14397 | .doit = nl80211_set_reg, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14398 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14399 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14400 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 14401 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14402 | { |
| 14403 | .cmd = NL80211_CMD_REQ_SET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14404 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14405 | .doit = nl80211_req_set_reg, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14406 | .flags = GENL_ADMIN_PERM, |
| 14407 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14408 | { |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14409 | .cmd = NL80211_CMD_RELOAD_REGDB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14410 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14411 | .doit = nl80211_reload_regdb, |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14412 | .flags = GENL_ADMIN_PERM, |
| 14413 | }, |
| 14414 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14415 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14416 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14417 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14418 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14419 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14420 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14421 | }, |
| 14422 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14423 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14424 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14425 | .doit = nl80211_update_mesh_config, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14426 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14427 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14428 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14429 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 14430 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14431 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14432 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14433 | .doit = nl80211_trigger_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14434 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 14435 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14436 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14437 | }, |
| 14438 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14439 | .cmd = NL80211_CMD_ABORT_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14440 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14441 | .doit = nl80211_abort_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14442 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14443 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14444 | NL80211_FLAG_NEED_RTNL, |
| 14445 | }, |
| 14446 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14447 | .cmd = NL80211_CMD_GET_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14448 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14449 | .dumpit = nl80211_dump_scan, |
| 14450 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14451 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14452 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14453 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14454 | .doit = nl80211_start_sched_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14455 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14456 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14457 | NL80211_FLAG_NEED_RTNL, |
| 14458 | }, |
| 14459 | { |
| 14460 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14461 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14462 | .doit = nl80211_stop_sched_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14463 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14464 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14465 | NL80211_FLAG_NEED_RTNL, |
| 14466 | }, |
| 14467 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14468 | .cmd = NL80211_CMD_AUTHENTICATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14469 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14470 | .doit = nl80211_authenticate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14471 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14472 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14473 | NL80211_FLAG_NEED_RTNL | |
| 14474 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14475 | }, |
| 14476 | { |
| 14477 | .cmd = NL80211_CMD_ASSOCIATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14478 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14479 | .doit = nl80211_associate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14480 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14481 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14482 | NL80211_FLAG_NEED_RTNL | |
| 14483 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14484 | }, |
| 14485 | { |
| 14486 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14487 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14488 | .doit = nl80211_deauthenticate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14489 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14490 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14491 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14492 | }, |
| 14493 | { |
| 14494 | .cmd = NL80211_CMD_DISASSOCIATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14495 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14496 | .doit = nl80211_disassociate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14497 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14498 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14499 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14500 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14501 | { |
| 14502 | .cmd = NL80211_CMD_JOIN_IBSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14503 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14504 | .doit = nl80211_join_ibss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14505 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14506 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14507 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14508 | }, |
| 14509 | { |
| 14510 | .cmd = NL80211_CMD_LEAVE_IBSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14511 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14512 | .doit = nl80211_leave_ibss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14513 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14514 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14515 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14516 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14517 | #ifdef CONFIG_NL80211_TESTMODE |
| 14518 | { |
| 14519 | .cmd = NL80211_CMD_TESTMODE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14520 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14521 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 14522 | .dumpit = nl80211_testmode_dump, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14523 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14524 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14525 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14526 | }, |
| 14527 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14528 | { |
| 14529 | .cmd = NL80211_CMD_CONNECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14530 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14531 | .doit = nl80211_connect, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14532 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14533 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14534 | NL80211_FLAG_NEED_RTNL | |
| 14535 | NL80211_FLAG_CLEAR_SKB, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14536 | }, |
| 14537 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14538 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14539 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14540 | .doit = nl80211_update_connect_params, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14541 | .flags = GENL_ADMIN_PERM, |
| 14542 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14543 | NL80211_FLAG_NEED_RTNL | |
| 14544 | NL80211_FLAG_CLEAR_SKB, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14545 | }, |
| 14546 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14547 | .cmd = NL80211_CMD_DISCONNECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14548 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14549 | .doit = nl80211_disconnect, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14550 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14551 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14552 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14553 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14554 | { |
| 14555 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14556 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14557 | .doit = nl80211_wiphy_netns, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14558 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14559 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14560 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14561 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 14562 | { |
| 14563 | .cmd = NL80211_CMD_GET_SURVEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14564 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 14565 | .dumpit = nl80211_dump_survey, |
| 14566 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14567 | { |
| 14568 | .cmd = NL80211_CMD_SET_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14569 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14570 | .doit = nl80211_setdel_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14571 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14572 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14573 | NL80211_FLAG_NEED_RTNL | |
| 14574 | NL80211_FLAG_CLEAR_SKB, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14575 | }, |
| 14576 | { |
| 14577 | .cmd = NL80211_CMD_DEL_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14578 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14579 | .doit = nl80211_setdel_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14580 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14581 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14582 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14583 | }, |
| 14584 | { |
| 14585 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14586 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14587 | .doit = nl80211_flush_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14588 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14589 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14590 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14591 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14592 | { |
| 14593 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14594 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14595 | .doit = nl80211_remain_on_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14596 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14597 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14598 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14599 | }, |
| 14600 | { |
| 14601 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14602 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14603 | .doit = nl80211_cancel_remain_on_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14604 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14605 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14606 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14607 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 14608 | { |
| 14609 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14610 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 14611 | .doit = nl80211_set_tx_bitrate_mask, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14612 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14613 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14614 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 14615 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14616 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14617 | .cmd = NL80211_CMD_REGISTER_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14618 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14619 | .doit = nl80211_register_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14620 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14621 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14622 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14623 | }, |
| 14624 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14625 | .cmd = NL80211_CMD_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14626 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14627 | .doit = nl80211_tx_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14628 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14629 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14630 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14631 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14632 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 14633 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14634 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 14635 | .doit = nl80211_tx_mgmt_cancel_wait, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14636 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14637 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 14638 | NL80211_FLAG_NEED_RTNL, |
| 14639 | }, |
| 14640 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14641 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14642 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14643 | .doit = nl80211_set_power_save, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14644 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14645 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14646 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14647 | }, |
| 14648 | { |
| 14649 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14650 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14651 | .doit = nl80211_get_power_save, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14652 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14653 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14654 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14655 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14656 | { |
| 14657 | .cmd = NL80211_CMD_SET_CQM, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14658 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14659 | .doit = nl80211_set_cqm, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14660 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14661 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14662 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14663 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 14664 | { |
| 14665 | .cmd = NL80211_CMD_SET_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14666 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 14667 | .doit = nl80211_set_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14668 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14669 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14670 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 14671 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 14672 | { |
| 14673 | .cmd = NL80211_CMD_SET_WDS_PEER, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14674 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 14675 | .doit = nl80211_set_wds_peer, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14676 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 14677 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14678 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 14679 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14680 | { |
| 14681 | .cmd = NL80211_CMD_JOIN_MESH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14682 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14683 | .doit = nl80211_join_mesh, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14684 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14685 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14686 | NL80211_FLAG_NEED_RTNL, |
| 14687 | }, |
| 14688 | { |
| 14689 | .cmd = NL80211_CMD_LEAVE_MESH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14690 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14691 | .doit = nl80211_leave_mesh, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14692 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14693 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14694 | NL80211_FLAG_NEED_RTNL, |
| 14695 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 14696 | { |
| 14697 | .cmd = NL80211_CMD_JOIN_OCB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14698 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 14699 | .doit = nl80211_join_ocb, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14700 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 14701 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14702 | NL80211_FLAG_NEED_RTNL, |
| 14703 | }, |
| 14704 | { |
| 14705 | .cmd = NL80211_CMD_LEAVE_OCB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14706 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 14707 | .doit = nl80211_leave_ocb, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14708 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 14709 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14710 | NL80211_FLAG_NEED_RTNL, |
| 14711 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 14712 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 14713 | { |
| 14714 | .cmd = NL80211_CMD_GET_WOWLAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14715 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 14716 | .doit = nl80211_get_wowlan, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 14717 | /* can be retrieved by unprivileged users */ |
| 14718 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14719 | NL80211_FLAG_NEED_RTNL, |
| 14720 | }, |
| 14721 | { |
| 14722 | .cmd = NL80211_CMD_SET_WOWLAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14723 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 14724 | .doit = nl80211_set_wowlan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14725 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 14726 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14727 | NL80211_FLAG_NEED_RTNL, |
| 14728 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 14729 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14730 | { |
| 14731 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14732 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14733 | .doit = nl80211_set_rekey_data, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14734 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14735 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14736 | NL80211_FLAG_NEED_RTNL | |
| 14737 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14738 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 14739 | { |
| 14740 | .cmd = NL80211_CMD_TDLS_MGMT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14741 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 14742 | .doit = nl80211_tdls_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14743 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 14744 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14745 | NL80211_FLAG_NEED_RTNL, |
| 14746 | }, |
| 14747 | { |
| 14748 | .cmd = NL80211_CMD_TDLS_OPER, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14749 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 14750 | .doit = nl80211_tdls_oper, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14751 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 14752 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14753 | NL80211_FLAG_NEED_RTNL, |
| 14754 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14755 | { |
| 14756 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14757 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14758 | .doit = nl80211_register_unexpected_frame, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14759 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14760 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14761 | NL80211_FLAG_NEED_RTNL, |
| 14762 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14763 | { |
| 14764 | .cmd = NL80211_CMD_PROBE_CLIENT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14765 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14766 | .doit = nl80211_probe_client, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14767 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14768 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14769 | NL80211_FLAG_NEED_RTNL, |
| 14770 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14771 | { |
| 14772 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14773 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14774 | .doit = nl80211_register_beacons, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14775 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14776 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14777 | NL80211_FLAG_NEED_RTNL, |
| 14778 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 14779 | { |
| 14780 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14781 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 14782 | .doit = nl80211_set_noack_map, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14783 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 14784 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14785 | NL80211_FLAG_NEED_RTNL, |
| 14786 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14787 | { |
| 14788 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14789 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14790 | .doit = nl80211_start_p2p_device, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14791 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14792 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 14793 | NL80211_FLAG_NEED_RTNL, |
| 14794 | }, |
| 14795 | { |
| 14796 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14797 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14798 | .doit = nl80211_stop_p2p_device, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14799 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14800 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14801 | NL80211_FLAG_NEED_RTNL, |
| 14802 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 14803 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 14804 | .cmd = NL80211_CMD_START_NAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14805 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 14806 | .doit = nl80211_start_nan, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 14807 | .flags = GENL_ADMIN_PERM, |
| 14808 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 14809 | NL80211_FLAG_NEED_RTNL, |
| 14810 | }, |
| 14811 | { |
| 14812 | .cmd = NL80211_CMD_STOP_NAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14813 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 14814 | .doit = nl80211_stop_nan, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 14815 | .flags = GENL_ADMIN_PERM, |
| 14816 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14817 | NL80211_FLAG_NEED_RTNL, |
| 14818 | }, |
| 14819 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 14820 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14821 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 14822 | .doit = nl80211_nan_add_func, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 14823 | .flags = GENL_ADMIN_PERM, |
| 14824 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14825 | NL80211_FLAG_NEED_RTNL, |
| 14826 | }, |
| 14827 | { |
| 14828 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14829 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 14830 | .doit = nl80211_nan_del_func, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 14831 | .flags = GENL_ADMIN_PERM, |
| 14832 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14833 | NL80211_FLAG_NEED_RTNL, |
| 14834 | }, |
| 14835 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 14836 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14837 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 14838 | .doit = nl80211_nan_change_config, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 14839 | .flags = GENL_ADMIN_PERM, |
| 14840 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14841 | NL80211_FLAG_NEED_RTNL, |
| 14842 | }, |
| 14843 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 14844 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14845 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 14846 | .doit = nl80211_set_mcast_rate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14847 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 14848 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14849 | NL80211_FLAG_NEED_RTNL, |
| 14850 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 14851 | { |
| 14852 | .cmd = NL80211_CMD_SET_MAC_ACL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14853 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 14854 | .doit = nl80211_set_mac_acl, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14855 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 14856 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14857 | NL80211_FLAG_NEED_RTNL, |
| 14858 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14859 | { |
| 14860 | .cmd = NL80211_CMD_RADAR_DETECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14861 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14862 | .doit = nl80211_start_radar_detection, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14863 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14864 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14865 | NL80211_FLAG_NEED_RTNL, |
| 14866 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 14867 | { |
| 14868 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14869 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 14870 | .doit = nl80211_get_protocol_features, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 14871 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14872 | { |
| 14873 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14874 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14875 | .doit = nl80211_update_ft_ies, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14876 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14877 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14878 | NL80211_FLAG_NEED_RTNL, |
| 14879 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14880 | { |
| 14881 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14882 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14883 | .doit = nl80211_crit_protocol_start, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14884 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14885 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14886 | NL80211_FLAG_NEED_RTNL, |
| 14887 | }, |
| 14888 | { |
| 14889 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14890 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14891 | .doit = nl80211_crit_protocol_stop, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14892 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14893 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14894 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 14895 | }, |
| 14896 | { |
| 14897 | .cmd = NL80211_CMD_GET_COALESCE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14898 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 14899 | .doit = nl80211_get_coalesce, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 14900 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14901 | NL80211_FLAG_NEED_RTNL, |
| 14902 | }, |
| 14903 | { |
| 14904 | .cmd = NL80211_CMD_SET_COALESCE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14905 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 14906 | .doit = nl80211_set_coalesce, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14907 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 14908 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14909 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 14910 | }, |
| 14911 | { |
| 14912 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14913 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 14914 | .doit = nl80211_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14915 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 14916 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14917 | NL80211_FLAG_NEED_RTNL, |
| 14918 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14919 | { |
| 14920 | .cmd = NL80211_CMD_VENDOR, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14921 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14922 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14923 | .dumpit = nl80211_vendor_cmd_dump, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14924 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14925 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14926 | NL80211_FLAG_NEED_RTNL | |
| 14927 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14928 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 14929 | { |
| 14930 | .cmd = NL80211_CMD_SET_QOS_MAP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14931 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 14932 | .doit = nl80211_set_qos_map, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14933 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 14934 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14935 | NL80211_FLAG_NEED_RTNL, |
| 14936 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14937 | { |
| 14938 | .cmd = NL80211_CMD_ADD_TX_TS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14939 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14940 | .doit = nl80211_add_tx_ts, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14941 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14942 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14943 | NL80211_FLAG_NEED_RTNL, |
| 14944 | }, |
| 14945 | { |
| 14946 | .cmd = NL80211_CMD_DEL_TX_TS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14947 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14948 | .doit = nl80211_del_tx_ts, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14949 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14950 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14951 | NL80211_FLAG_NEED_RTNL, |
| 14952 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14953 | { |
| 14954 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14955 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14956 | .doit = nl80211_tdls_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14957 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14958 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14959 | NL80211_FLAG_NEED_RTNL, |
| 14960 | }, |
| 14961 | { |
| 14962 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14963 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14964 | .doit = nl80211_tdls_cancel_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14965 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14966 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14967 | NL80211_FLAG_NEED_RTNL, |
| 14968 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 14969 | { |
| 14970 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14971 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 14972 | .doit = nl80211_set_multicast_to_unicast, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 14973 | .flags = GENL_UNS_ADMIN_PERM, |
| 14974 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14975 | NL80211_FLAG_NEED_RTNL, |
| 14976 | }, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14977 | { |
| 14978 | .cmd = NL80211_CMD_SET_PMK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14979 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14980 | .doit = nl80211_set_pmk, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14981 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14982 | NL80211_FLAG_NEED_RTNL | |
| 14983 | NL80211_FLAG_CLEAR_SKB, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14984 | }, |
| 14985 | { |
| 14986 | .cmd = NL80211_CMD_DEL_PMK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14987 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14988 | .doit = nl80211_del_pmk, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14989 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14990 | NL80211_FLAG_NEED_RTNL, |
| 14991 | }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14992 | { |
| 14993 | .cmd = NL80211_CMD_EXTERNAL_AUTH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14994 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14995 | .doit = nl80211_external_auth, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14996 | .flags = GENL_ADMIN_PERM, |
| 14997 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14998 | NL80211_FLAG_NEED_RTNL, |
| 14999 | }, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15000 | { |
| 15001 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15002 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15003 | .doit = nl80211_tx_control_port, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15004 | .flags = GENL_UNS_ADMIN_PERM, |
| 15005 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15006 | NL80211_FLAG_NEED_RTNL, |
| 15007 | }, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15008 | { |
| 15009 | .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15010 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15011 | .doit = nl80211_get_ftm_responder_stats, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15012 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15013 | NL80211_FLAG_NEED_RTNL, |
| 15014 | }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15015 | { |
| 15016 | .cmd = NL80211_CMD_PEER_MEASUREMENT_START, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15017 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15018 | .doit = nl80211_pmsr_start, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15019 | .flags = GENL_UNS_ADMIN_PERM, |
| 15020 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15021 | NL80211_FLAG_NEED_RTNL, |
| 15022 | }, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15023 | { |
| 15024 | .cmd = NL80211_CMD_NOTIFY_RADAR, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15025 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15026 | .doit = nl80211_notify_radar_detection, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15027 | .flags = GENL_UNS_ADMIN_PERM, |
| 15028 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15029 | NL80211_FLAG_NEED_RTNL, |
| 15030 | }, |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 15031 | { |
| 15032 | .cmd = NL80211_CMD_UPDATE_OWE_INFO, |
| 15033 | .doit = nl80211_update_owe_info, |
| 15034 | .flags = GENL_ADMIN_PERM, |
| 15035 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15036 | NL80211_FLAG_NEED_RTNL, |
| 15037 | }, |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 15038 | { |
| 15039 | .cmd = NL80211_CMD_PROBE_MESH_LINK, |
| 15040 | .doit = nl80211_probe_mesh_link, |
| 15041 | .flags = GENL_UNS_ADMIN_PERM, |
| 15042 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15043 | NL80211_FLAG_NEED_RTNL, |
| 15044 | }, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 15045 | { |
| 15046 | .cmd = NL80211_CMD_SET_TID_CONFIG, |
| 15047 | .doit = nl80211_set_tid_config, |
| 15048 | .flags = GENL_UNS_ADMIN_PERM, |
| 15049 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15050 | NL80211_FLAG_NEED_RTNL, |
| 15051 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15052 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15053 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 15054 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15055 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 15056 | .hdrsize = 0, /* no private header */ |
| 15057 | .version = 1, /* no particular meaning now */ |
| 15058 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 3b0f31f | 2019-03-21 22:51:02 +0100 | [diff] [blame] | 15059 | .policy = nl80211_policy, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15060 | .netnsok = true, |
| 15061 | .pre_doit = nl80211_pre_doit, |
| 15062 | .post_doit = nl80211_post_doit, |
| 15063 | .module = THIS_MODULE, |
| 15064 | .ops = nl80211_ops, |
| 15065 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| 15066 | .mcgrps = nl80211_mcgrps, |
| 15067 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 15068 | .parallel_ops = true, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15069 | }; |
| 15070 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15071 | /* notification functions */ |
| 15072 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15073 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 15074 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15075 | { |
| 15076 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 15077 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15078 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15079 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 15080 | cmd != NL80211_CMD_DEL_WIPHY); |
| 15081 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15082 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15083 | if (!msg) |
| 15084 | return; |
| 15085 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15086 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15087 | nlmsg_free(msg); |
| 15088 | return; |
| 15089 | } |
| 15090 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15091 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15092 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15093 | } |
| 15094 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15095 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 15096 | struct wireless_dev *wdev, |
| 15097 | enum nl80211_commands cmd) |
| 15098 | { |
| 15099 | struct sk_buff *msg; |
| 15100 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15101 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15102 | if (!msg) |
| 15103 | return; |
| 15104 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 15105 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15106 | nlmsg_free(msg); |
| 15107 | return; |
| 15108 | } |
| 15109 | |
| 15110 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15111 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 15112 | } |
| 15113 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15114 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 15115 | struct cfg80211_registered_device *rdev) |
| 15116 | { |
| 15117 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 15118 | struct nlattr *nest; |
| 15119 | int i; |
| 15120 | |
| 15121 | if (WARN_ON(!req)) |
| 15122 | return 0; |
| 15123 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15124 | nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15125 | if (!nest) |
| 15126 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15127 | for (i = 0; i < req->n_ssids; i++) { |
| 15128 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 15129 | goto nla_put_failure; |
| 15130 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15131 | nla_nest_end(msg, nest); |
| 15132 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15133 | nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15134 | if (!nest) |
| 15135 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15136 | for (i = 0; i < req->n_channels; i++) { |
| 15137 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 15138 | goto nla_put_failure; |
| 15139 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15140 | nla_nest_end(msg, nest); |
| 15141 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15142 | if (req->ie && |
| 15143 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 15144 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15145 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15146 | if (req->flags && |
| 15147 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 15148 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 15149 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 15150 | if (req->info.scan_start_tsf && |
| 15151 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 15152 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 15153 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 15154 | req->info.tsf_bssid))) |
| 15155 | goto nla_put_failure; |
| 15156 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15157 | return 0; |
| 15158 | nla_put_failure: |
| 15159 | return -ENOBUFS; |
| 15160 | } |
| 15161 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15162 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15163 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15164 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15165 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15166 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15167 | { |
| 15168 | void *hdr; |
| 15169 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15170 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15171 | if (!hdr) |
| 15172 | return -1; |
| 15173 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15174 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15175 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15176 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15177 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15178 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15179 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15180 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15181 | /* ignore errors and send incomplete event anyway */ |
| 15182 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15183 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 15184 | genlmsg_end(msg, hdr); |
| 15185 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15186 | |
| 15187 | nla_put_failure: |
| 15188 | genlmsg_cancel(msg, hdr); |
| 15189 | return -EMSGSIZE; |
| 15190 | } |
| 15191 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15192 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15193 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15194 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15195 | { |
| 15196 | void *hdr; |
| 15197 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15198 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15199 | if (!hdr) |
| 15200 | return -1; |
| 15201 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15202 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 15203 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 15204 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 15205 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 15206 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15207 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15208 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 15209 | genlmsg_end(msg, hdr); |
| 15210 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15211 | |
| 15212 | nla_put_failure: |
| 15213 | genlmsg_cancel(msg, hdr); |
| 15214 | return -EMSGSIZE; |
| 15215 | } |
| 15216 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15217 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15218 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15219 | { |
| 15220 | struct sk_buff *msg; |
| 15221 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15222 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15223 | if (!msg) |
| 15224 | return; |
| 15225 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15226 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15227 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 15228 | nlmsg_free(msg); |
| 15229 | return; |
| 15230 | } |
| 15231 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15232 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15233 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15234 | } |
| 15235 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15236 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 15237 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15238 | { |
| 15239 | struct sk_buff *msg; |
| 15240 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15241 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15242 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15243 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15244 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15245 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15246 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 15247 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15248 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15249 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15250 | } |
| 15251 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15252 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15253 | } |
| 15254 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15255 | /* send message created by nl80211_build_scan_msg() */ |
| 15256 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 15257 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15258 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15259 | if (!msg) |
| 15260 | return; |
| 15261 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15262 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15263 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15264 | } |
| 15265 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15266 | void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15267 | { |
| 15268 | struct sk_buff *msg; |
| 15269 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15270 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15271 | if (!msg) |
| 15272 | return; |
| 15273 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15274 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15275 | nlmsg_free(msg); |
| 15276 | return; |
| 15277 | } |
| 15278 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15279 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15280 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15281 | } |
| 15282 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15283 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 15284 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15285 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15286 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15287 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 15288 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15289 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15290 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 15291 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15292 | NL80211_REGDOM_TYPE_WORLD)) |
| 15293 | goto nla_put_failure; |
| 15294 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 15295 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15296 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 15297 | goto nla_put_failure; |
| 15298 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 15299 | request->intersect) { |
| 15300 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15301 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 15302 | goto nla_put_failure; |
| 15303 | } else { |
| 15304 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15305 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 15306 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 15307 | request->alpha2)) |
| 15308 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15309 | } |
| 15310 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 15311 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 15312 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 15313 | |
| 15314 | if (wiphy && |
| 15315 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 15316 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 15317 | |
| 15318 | if (wiphy && |
| 15319 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 15320 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 15321 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 15322 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15323 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15324 | return true; |
| 15325 | |
| 15326 | nla_put_failure: |
| 15327 | return false; |
| 15328 | } |
| 15329 | |
| 15330 | /* |
| 15331 | * This can happen on global regulatory changes or device specific settings |
| 15332 | * based on custom regulatory domains. |
| 15333 | */ |
| 15334 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 15335 | struct regulatory_request *request) |
| 15336 | { |
| 15337 | struct sk_buff *msg; |
| 15338 | void *hdr; |
| 15339 | |
| 15340 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15341 | if (!msg) |
| 15342 | return; |
| 15343 | |
| 15344 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
zhong jiang | 24f6d76 | 2019-09-05 12:25:37 +0800 | [diff] [blame] | 15345 | if (!hdr) |
| 15346 | goto nla_put_failure; |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15347 | |
zhong jiang | 24f6d76 | 2019-09-05 12:25:37 +0800 | [diff] [blame] | 15348 | if (!nl80211_reg_change_event_fill(msg, request)) |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15349 | goto nla_put_failure; |
| 15350 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15351 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15352 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 15353 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15354 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15355 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 15356 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15357 | |
| 15358 | return; |
| 15359 | |
| 15360 | nla_put_failure: |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15361 | nlmsg_free(msg); |
| 15362 | } |
| 15363 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15364 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 15365 | struct net_device *netdev, |
| 15366 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15367 | enum nl80211_commands cmd, gfp_t gfp, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15368 | int uapsd_queues, const u8 *req_ies, |
| 15369 | size_t req_ies_len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15370 | { |
| 15371 | struct sk_buff *msg; |
| 15372 | void *hdr; |
| 15373 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15374 | msg = nlmsg_new(100 + len + req_ies_len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15375 | if (!msg) |
| 15376 | return; |
| 15377 | |
| 15378 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15379 | if (!hdr) { |
| 15380 | nlmsg_free(msg); |
| 15381 | return; |
| 15382 | } |
| 15383 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15384 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15385 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15386 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 15387 | (req_ies && |
| 15388 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15389 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15390 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15391 | if (uapsd_queues >= 0) { |
| 15392 | struct nlattr *nla_wmm = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15393 | nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15394 | if (!nla_wmm) |
| 15395 | goto nla_put_failure; |
| 15396 | |
| 15397 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 15398 | uapsd_queues)) |
| 15399 | goto nla_put_failure; |
| 15400 | |
| 15401 | nla_nest_end(msg, nla_wmm); |
| 15402 | } |
| 15403 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15404 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15405 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15406 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15407 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15408 | return; |
| 15409 | |
| 15410 | nla_put_failure: |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15411 | nlmsg_free(msg); |
| 15412 | } |
| 15413 | |
| 15414 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15415 | struct net_device *netdev, const u8 *buf, |
| 15416 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15417 | { |
| 15418 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15419 | NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15420 | } |
| 15421 | |
| 15422 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 15423 | struct net_device *netdev, const u8 *buf, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15424 | size_t len, gfp_t gfp, int uapsd_queues, |
| 15425 | const u8 *req_ies, size_t req_ies_len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15426 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15427 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15428 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues, |
| 15429 | req_ies, req_ies_len); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15430 | } |
| 15431 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 15432 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15433 | struct net_device *netdev, const u8 *buf, |
| 15434 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15435 | { |
| 15436 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15437 | NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15438 | } |
| 15439 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 15440 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 15441 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15442 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15443 | { |
| 15444 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15445 | NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15446 | } |
| 15447 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15448 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 15449 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15450 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15451 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15452 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15453 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15454 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 15455 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15456 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15457 | if (WARN_ON(len < 2)) |
| 15458 | return; |
| 15459 | |
| 15460 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 15461 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 15462 | else |
| 15463 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 15464 | |
| 15465 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15466 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, |
| 15467 | NULL, 0); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15468 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15469 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15470 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 15471 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 15472 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15473 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15474 | { |
| 15475 | struct sk_buff *msg; |
| 15476 | void *hdr; |
| 15477 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15479 | if (!msg) |
| 15480 | return; |
| 15481 | |
| 15482 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15483 | if (!hdr) { |
| 15484 | nlmsg_free(msg); |
| 15485 | return; |
| 15486 | } |
| 15487 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15488 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15489 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15490 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 15491 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 15492 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15493 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15494 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15495 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15496 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15497 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15498 | return; |
| 15499 | |
| 15500 | nla_put_failure: |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15501 | nlmsg_free(msg); |
| 15502 | } |
| 15503 | |
| 15504 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15505 | struct net_device *netdev, const u8 *addr, |
| 15506 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15507 | { |
| 15508 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15509 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15510 | } |
| 15511 | |
| 15512 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15513 | struct net_device *netdev, const u8 *addr, |
| 15514 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15515 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15516 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 15517 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15518 | } |
| 15519 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15520 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15521 | struct net_device *netdev, |
| 15522 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 15523 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15524 | { |
| 15525 | struct sk_buff *msg; |
| 15526 | void *hdr; |
| 15527 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15528 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15529 | cr->fils.kek_len + cr->fils.pmk_len + |
| 15530 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15531 | if (!msg) |
| 15532 | return; |
| 15533 | |
| 15534 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 15535 | if (!hdr) { |
| 15536 | nlmsg_free(msg); |
| 15537 | return; |
| 15538 | } |
| 15539 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15540 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15541 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15542 | (cr->bssid && |
| 15543 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 15544 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15545 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 15546 | cr->status) || |
| 15547 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 15548 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15549 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 15550 | cr->timeout_reason))) || |
| 15551 | (cr->req_ie && |
| 15552 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 15553 | (cr->resp_ie && |
| 15554 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15555 | cr->resp_ie)) || |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15556 | (cr->fils.update_erp_next_seq_num && |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15557 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15558 | cr->fils.erp_next_seq_num)) || |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15559 | (cr->status == WLAN_STATUS_SUCCESS && |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15560 | ((cr->fils.kek && |
| 15561 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, |
| 15562 | cr->fils.kek)) || |
| 15563 | (cr->fils.pmk && |
| 15564 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || |
| 15565 | (cr->fils.pmkid && |
| 15566 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15567 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15568 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15569 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15570 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15571 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15572 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15573 | return; |
| 15574 | |
| 15575 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15576 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15577 | } |
| 15578 | |
| 15579 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 15580 | struct net_device *netdev, |
| 15581 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15582 | { |
| 15583 | struct sk_buff *msg; |
| 15584 | void *hdr; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 15585 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15586 | |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 15587 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + |
| 15588 | info->fils.kek_len + info->fils.pmk_len + |
| 15589 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15590 | if (!msg) |
| 15591 | return; |
| 15592 | |
| 15593 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 15594 | if (!hdr) { |
| 15595 | nlmsg_free(msg); |
| 15596 | return; |
| 15597 | } |
| 15598 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15599 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15600 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15601 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 15602 | (info->req_ie && |
| 15603 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 15604 | info->req_ie)) || |
| 15605 | (info->resp_ie && |
| 15606 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 15607 | info->resp_ie)) || |
| 15608 | (info->fils.update_erp_next_seq_num && |
| 15609 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 15610 | info->fils.erp_next_seq_num)) || |
| 15611 | (info->fils.kek && |
| 15612 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, |
| 15613 | info->fils.kek)) || |
| 15614 | (info->fils.pmk && |
| 15615 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || |
| 15616 | (info->fils.pmkid && |
| 15617 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15618 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15619 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15620 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15621 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15622 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15623 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15624 | return; |
| 15625 | |
| 15626 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15627 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15628 | } |
| 15629 | |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 15630 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, |
| 15631 | struct net_device *netdev, const u8 *bssid) |
| 15632 | { |
| 15633 | struct sk_buff *msg; |
| 15634 | void *hdr; |
| 15635 | |
| 15636 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15637 | if (!msg) |
| 15638 | return; |
| 15639 | |
| 15640 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); |
| 15641 | if (!hdr) { |
| 15642 | nlmsg_free(msg); |
| 15643 | return; |
| 15644 | } |
| 15645 | |
Chung-Hsien Hsu | f4d7599 | 2019-05-09 09:48:25 +0000 | [diff] [blame] | 15646 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15647 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15648 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 15649 | goto nla_put_failure; |
| 15650 | |
| 15651 | genlmsg_end(msg, hdr); |
| 15652 | |
| 15653 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15654 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 15655 | return; |
| 15656 | |
| 15657 | nla_put_failure: |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 15658 | nlmsg_free(msg); |
| 15659 | } |
| 15660 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15661 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 15662 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 15663 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15664 | { |
| 15665 | struct sk_buff *msg; |
| 15666 | void *hdr; |
| 15667 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 15668 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15669 | if (!msg) |
| 15670 | return; |
| 15671 | |
| 15672 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 15673 | if (!hdr) { |
| 15674 | nlmsg_free(msg); |
| 15675 | return; |
| 15676 | } |
| 15677 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15678 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15679 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
David Spinadel | 86b6c46 | 2017-12-18 12:14:05 +0200 | [diff] [blame] | 15680 | (reason && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15681 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 15682 | (from_ap && |
| 15683 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 15684 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 15685 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15686 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15687 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15688 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15689 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15690 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15691 | return; |
| 15692 | |
| 15693 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15694 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15695 | } |
| 15696 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15697 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 15698 | struct net_device *netdev, const u8 *bssid, |
| 15699 | gfp_t gfp) |
| 15700 | { |
| 15701 | struct sk_buff *msg; |
| 15702 | void *hdr; |
| 15703 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15705 | if (!msg) |
| 15706 | return; |
| 15707 | |
| 15708 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 15709 | if (!hdr) { |
| 15710 | nlmsg_free(msg); |
| 15711 | return; |
| 15712 | } |
| 15713 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15714 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15715 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15716 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 15717 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15718 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15719 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15720 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15721 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15722 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15723 | return; |
| 15724 | |
| 15725 | nla_put_failure: |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15726 | nlmsg_free(msg); |
| 15727 | } |
| 15728 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15729 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
Bob Copeland | ecbc12a | 2018-10-26 10:03:50 -0400 | [diff] [blame] | 15730 | const u8 *ie, u8 ie_len, |
| 15731 | int sig_dbm, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15732 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15733 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15734 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15735 | struct sk_buff *msg; |
| 15736 | void *hdr; |
| 15737 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15738 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 15739 | return; |
| 15740 | |
| 15741 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 15742 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 15743 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15744 | if (!msg) |
| 15745 | return; |
| 15746 | |
| 15747 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 15748 | if (!hdr) { |
| 15749 | nlmsg_free(msg); |
| 15750 | return; |
| 15751 | } |
| 15752 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15753 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15754 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15755 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15756 | (ie_len && ie && |
Bob Copeland | ecbc12a | 2018-10-26 10:03:50 -0400 | [diff] [blame] | 15757 | nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || |
| 15758 | (sig_dbm && |
| 15759 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15760 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15761 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15762 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15763 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15764 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15765 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15766 | return; |
| 15767 | |
| 15768 | nla_put_failure: |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15769 | nlmsg_free(msg); |
| 15770 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15771 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15772 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15773 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 15774 | struct net_device *netdev, const u8 *addr, |
| 15775 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15776 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15777 | { |
| 15778 | struct sk_buff *msg; |
| 15779 | void *hdr; |
| 15780 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15781 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15782 | if (!msg) |
| 15783 | return; |
| 15784 | |
| 15785 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 15786 | if (!hdr) { |
| 15787 | nlmsg_free(msg); |
| 15788 | return; |
| 15789 | } |
| 15790 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15791 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15792 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15793 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 15794 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 15795 | (key_id != -1 && |
| 15796 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 15797 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 15798 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15799 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15800 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15801 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15802 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15803 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15804 | return; |
| 15805 | |
| 15806 | nla_put_failure: |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15807 | nlmsg_free(msg); |
| 15808 | } |
| 15809 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15810 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 15811 | struct ieee80211_channel *channel_before, |
| 15812 | struct ieee80211_channel *channel_after) |
| 15813 | { |
| 15814 | struct sk_buff *msg; |
| 15815 | void *hdr; |
| 15816 | struct nlattr *nl_freq; |
| 15817 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15818 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15819 | if (!msg) |
| 15820 | return; |
| 15821 | |
| 15822 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 15823 | if (!hdr) { |
| 15824 | nlmsg_free(msg); |
| 15825 | return; |
| 15826 | } |
| 15827 | |
| 15828 | /* |
| 15829 | * Since we are applying the beacon hint to a wiphy we know its |
| 15830 | * wiphy_idx is valid |
| 15831 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15832 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 15833 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15834 | |
| 15835 | /* Before */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15836 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15837 | if (!nl_freq) |
| 15838 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 15839 | |
| 15840 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15841 | goto nla_put_failure; |
| 15842 | nla_nest_end(msg, nl_freq); |
| 15843 | |
| 15844 | /* After */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15845 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15846 | if (!nl_freq) |
| 15847 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 15848 | |
| 15849 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15850 | goto nla_put_failure; |
| 15851 | nla_nest_end(msg, nl_freq); |
| 15852 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15853 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15854 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 15855 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15856 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15857 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 15858 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15859 | |
| 15860 | return; |
| 15861 | |
| 15862 | nla_put_failure: |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15863 | nlmsg_free(msg); |
| 15864 | } |
| 15865 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15866 | static void nl80211_send_remain_on_chan_event( |
| 15867 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15868 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15869 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15870 | unsigned int duration, gfp_t gfp) |
| 15871 | { |
| 15872 | struct sk_buff *msg; |
| 15873 | void *hdr; |
| 15874 | |
| 15875 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15876 | if (!msg) |
| 15877 | return; |
| 15878 | |
| 15879 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15880 | if (!hdr) { |
| 15881 | nlmsg_free(msg); |
| 15882 | return; |
| 15883 | } |
| 15884 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15885 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15886 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15887 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15888 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15889 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15890 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 15891 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 15892 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15893 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 15894 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15895 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15896 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15897 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 15898 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 15899 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15900 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15901 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15902 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15903 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15904 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15905 | return; |
| 15906 | |
| 15907 | nla_put_failure: |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15908 | nlmsg_free(msg); |
| 15909 | } |
| 15910 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15911 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 15912 | struct ieee80211_channel *chan, |
| 15913 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15914 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15915 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15916 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15917 | |
| 15918 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15919 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15920 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 15921 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15922 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15923 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15924 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15925 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 15926 | struct ieee80211_channel *chan, |
| 15927 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15928 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15929 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15930 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15931 | |
| 15932 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15933 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 15934 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15935 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15936 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15937 | |
James Prestwood | 1c38c7f | 2019-06-12 12:35:09 -0700 | [diff] [blame] | 15938 | void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, |
| 15939 | struct ieee80211_channel *chan, |
| 15940 | gfp_t gfp) |
| 15941 | { |
| 15942 | struct wiphy *wiphy = wdev->wiphy; |
| 15943 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 15944 | |
| 15945 | trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); |
| 15946 | nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, |
| 15947 | rdev, wdev, cookie, chan, 0, gfp); |
| 15948 | } |
| 15949 | EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); |
| 15950 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15951 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 15952 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15953 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15954 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15955 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15956 | struct sk_buff *msg; |
| 15957 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15958 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 15959 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15960 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15961 | if (!msg) |
| 15962 | return; |
| 15963 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 15964 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 15965 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15966 | nlmsg_free(msg); |
| 15967 | return; |
| 15968 | } |
| 15969 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15970 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15971 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15972 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15973 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15974 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 15975 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 15976 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15977 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15978 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15979 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15980 | struct sk_buff *msg; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 15981 | struct station_info empty_sinfo = {}; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 15982 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 15983 | if (!sinfo) |
| 15984 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15985 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15986 | trace_cfg80211_del_sta(dev, mac_addr); |
| 15987 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15988 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 15989 | if (!msg) { |
| 15990 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 15991 | return; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 15992 | } |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15993 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 15994 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 15995 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15996 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 15997 | return; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15998 | } |
| 15999 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16000 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16001 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16002 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16003 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16004 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16005 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 16006 | enum nl80211_connect_failed_reason reason, |
| 16007 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16008 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16009 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16010 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16011 | struct sk_buff *msg; |
| 16012 | void *hdr; |
| 16013 | |
| 16014 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 16015 | if (!msg) |
| 16016 | return; |
| 16017 | |
| 16018 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 16019 | if (!hdr) { |
| 16020 | nlmsg_free(msg); |
| 16021 | return; |
| 16022 | } |
| 16023 | |
| 16024 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16025 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 16026 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 16027 | goto nla_put_failure; |
| 16028 | |
| 16029 | genlmsg_end(msg, hdr); |
| 16030 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16031 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16032 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16033 | return; |
| 16034 | |
| 16035 | nla_put_failure: |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16036 | nlmsg_free(msg); |
| 16037 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16038 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16039 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16040 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 16041 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16042 | { |
| 16043 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16044 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16045 | struct sk_buff *msg; |
| 16046 | void *hdr; |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 16047 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16048 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16049 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16050 | return false; |
| 16051 | |
| 16052 | msg = nlmsg_new(100, gfp); |
| 16053 | if (!msg) |
| 16054 | return true; |
| 16055 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16056 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16057 | if (!hdr) { |
| 16058 | nlmsg_free(msg); |
| 16059 | return true; |
| 16060 | } |
| 16061 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16062 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16063 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16064 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 16065 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16066 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16067 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16068 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16069 | return true; |
| 16070 | |
| 16071 | nla_put_failure: |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16072 | nlmsg_free(msg); |
| 16073 | return true; |
| 16074 | } |
| 16075 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16076 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 16077 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16078 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16079 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16080 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16081 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16082 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 16083 | |
| 16084 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 16085 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 16086 | trace_cfg80211_return_bool(false); |
| 16087 | return false; |
| 16088 | } |
| 16089 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 16090 | addr, gfp); |
| 16091 | trace_cfg80211_return_bool(ret); |
| 16092 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16093 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16094 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 16095 | |
| 16096 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 16097 | const u8 *addr, gfp_t gfp) |
| 16098 | { |
| 16099 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16100 | bool ret; |
| 16101 | |
| 16102 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 16103 | |
| 16104 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 16105 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 16106 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 16107 | trace_cfg80211_return_bool(false); |
| 16108 | return false; |
| 16109 | } |
| 16110 | ret = __nl80211_unexpected_frame(dev, |
| 16111 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 16112 | addr, gfp); |
| 16113 | trace_cfg80211_return_bool(ret); |
| 16114 | return ret; |
| 16115 | } |
| 16116 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16117 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 16118 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16119 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 16120 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 16121 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16122 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16123 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16124 | struct sk_buff *msg; |
| 16125 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16126 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16127 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16128 | if (!msg) |
| 16129 | return -ENOMEM; |
| 16130 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 16131 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16132 | if (!hdr) { |
| 16133 | nlmsg_free(msg); |
| 16134 | return -ENOMEM; |
| 16135 | } |
| 16136 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16137 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16138 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16139 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16140 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16141 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16142 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 16143 | (sig_dbm && |
| 16144 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 16145 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 16146 | (flags && |
| 16147 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16148 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16149 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16150 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16151 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16152 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16153 | |
| 16154 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16155 | nlmsg_free(msg); |
| 16156 | return -ENOBUFS; |
| 16157 | } |
| 16158 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16159 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16160 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16161 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16162 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16163 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16164 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16165 | struct sk_buff *msg; |
| 16166 | void *hdr; |
| 16167 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16168 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 16169 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16170 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16171 | if (!msg) |
| 16172 | return; |
| 16173 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 16174 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16175 | if (!hdr) { |
| 16176 | nlmsg_free(msg); |
| 16177 | return; |
| 16178 | } |
| 16179 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16180 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16181 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16182 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16183 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16184 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16185 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16186 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16187 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16188 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 16189 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16190 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16191 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16192 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16193 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16194 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16195 | return; |
| 16196 | |
| 16197 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16198 | nlmsg_free(msg); |
| 16199 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16200 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16201 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16202 | static int __nl80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16203 | struct sk_buff *skb, |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16204 | bool unencrypted, gfp_t gfp) |
| 16205 | { |
| 16206 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16207 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16208 | struct ethhdr *ehdr = eth_hdr(skb); |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 16209 | const u8 *addr = ehdr->h_source; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16210 | u16 proto = be16_to_cpu(skb->protocol); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16211 | struct sk_buff *msg; |
| 16212 | void *hdr; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16213 | struct nlattr *frame; |
| 16214 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16215 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); |
| 16216 | |
| 16217 | if (!nlportid) |
| 16218 | return -ENOENT; |
| 16219 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16220 | msg = nlmsg_new(100 + skb->len, gfp); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16221 | if (!msg) |
| 16222 | return -ENOMEM; |
| 16223 | |
| 16224 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 16225 | if (!hdr) { |
| 16226 | nlmsg_free(msg); |
| 16227 | return -ENOBUFS; |
| 16228 | } |
| 16229 | |
| 16230 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16231 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16232 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16233 | NL80211_ATTR_PAD) || |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 16234 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16235 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 16236 | (unencrypted && nla_put_flag(msg, |
| 16237 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 16238 | goto nla_put_failure; |
| 16239 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16240 | frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); |
| 16241 | if (!frame) |
| 16242 | goto nla_put_failure; |
| 16243 | |
| 16244 | skb_copy_bits(skb, 0, nla_data(frame), skb->len); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16245 | genlmsg_end(msg, hdr); |
| 16246 | |
| 16247 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 16248 | |
| 16249 | nla_put_failure: |
| 16250 | nlmsg_free(msg); |
| 16251 | return -ENOBUFS; |
| 16252 | } |
| 16253 | |
| 16254 | bool cfg80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16255 | struct sk_buff *skb, bool unencrypted) |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16256 | { |
| 16257 | int ret; |
| 16258 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16259 | trace_cfg80211_rx_control_port(dev, skb, unencrypted); |
| 16260 | ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16261 | trace_cfg80211_return_bool(ret == 0); |
| 16262 | return ret == 0; |
| 16263 | } |
| 16264 | EXPORT_SYMBOL(cfg80211_rx_control_port); |
| 16265 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16266 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 16267 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16268 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16269 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16270 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16271 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16272 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16273 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16274 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16275 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16276 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16277 | cb = (void **)msg->cb; |
| 16278 | |
| 16279 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 16280 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16281 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16282 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16283 | } |
| 16284 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16285 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16286 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16287 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16288 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16289 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16290 | goto nla_put_failure; |
| 16291 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16292 | cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16293 | if (!cb[1]) |
| 16294 | goto nla_put_failure; |
| 16295 | |
| 16296 | cb[2] = rdev; |
| 16297 | |
| 16298 | return msg; |
| 16299 | nla_put_failure: |
| 16300 | nlmsg_free(msg); |
| 16301 | return NULL; |
| 16302 | } |
| 16303 | |
| 16304 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 16305 | { |
| 16306 | void **cb = (void **)msg->cb; |
| 16307 | struct cfg80211_registered_device *rdev = cb[2]; |
| 16308 | |
| 16309 | nla_nest_end(msg, cb[1]); |
| 16310 | genlmsg_end(msg, cb[0]); |
| 16311 | |
| 16312 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 16313 | |
| 16314 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16315 | NL80211_MCGRP_MLME, gfp); |
| 16316 | } |
| 16317 | |
| 16318 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 16319 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16320 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16321 | { |
| 16322 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 16323 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16324 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16325 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16326 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16327 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 16328 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 16329 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 16330 | return; |
| 16331 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 16332 | if (wdev->cqm_config) { |
| 16333 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 16334 | |
| 16335 | cfg80211_cqm_rssi_update(rdev, dev); |
| 16336 | |
| 16337 | if (rssi_level == 0) |
| 16338 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 16339 | } |
| 16340 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16341 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 16342 | if (!msg) |
| 16343 | return; |
| 16344 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16345 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 16346 | rssi_event)) |
| 16347 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16348 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16349 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 16350 | rssi_level)) |
| 16351 | goto nla_put_failure; |
| 16352 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16353 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16354 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16355 | return; |
| 16356 | |
| 16357 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16358 | nlmsg_free(msg); |
| 16359 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16360 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16361 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16362 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 16363 | const u8 *peer, u32 num_packets, |
| 16364 | u32 rate, u32 intvl, gfp_t gfp) |
| 16365 | { |
| 16366 | struct sk_buff *msg; |
| 16367 | |
| 16368 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 16369 | if (!msg) |
| 16370 | return; |
| 16371 | |
| 16372 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 16373 | goto nla_put_failure; |
| 16374 | |
| 16375 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 16376 | goto nla_put_failure; |
| 16377 | |
| 16378 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 16379 | goto nla_put_failure; |
| 16380 | |
| 16381 | cfg80211_send_cqm(msg, gfp); |
| 16382 | return; |
| 16383 | |
| 16384 | nla_put_failure: |
| 16385 | nlmsg_free(msg); |
| 16386 | } |
| 16387 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 16388 | |
| 16389 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 16390 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 16391 | { |
| 16392 | struct sk_buff *msg; |
| 16393 | |
| 16394 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 16395 | |
| 16396 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 16397 | if (!msg) |
| 16398 | return; |
| 16399 | |
| 16400 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 16401 | goto nla_put_failure; |
| 16402 | |
| 16403 | cfg80211_send_cqm(msg, gfp); |
| 16404 | return; |
| 16405 | |
| 16406 | nla_put_failure: |
| 16407 | nlmsg_free(msg); |
| 16408 | } |
| 16409 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 16410 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 16411 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 16412 | { |
| 16413 | struct sk_buff *msg; |
| 16414 | |
| 16415 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 16416 | if (!msg) |
| 16417 | return; |
| 16418 | |
| 16419 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 16420 | goto nla_put_failure; |
| 16421 | |
| 16422 | cfg80211_send_cqm(msg, gfp); |
| 16423 | return; |
| 16424 | |
| 16425 | nla_put_failure: |
| 16426 | nlmsg_free(msg); |
| 16427 | } |
| 16428 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 16429 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16430 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 16431 | struct net_device *netdev, const u8 *bssid, |
| 16432 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16433 | { |
| 16434 | struct sk_buff *msg; |
| 16435 | struct nlattr *rekey_attr; |
| 16436 | void *hdr; |
| 16437 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16438 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16439 | if (!msg) |
| 16440 | return; |
| 16441 | |
| 16442 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 16443 | if (!hdr) { |
| 16444 | nlmsg_free(msg); |
| 16445 | return; |
| 16446 | } |
| 16447 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16448 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16449 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16450 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 16451 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16452 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16453 | rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16454 | if (!rekey_attr) |
| 16455 | goto nla_put_failure; |
| 16456 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16457 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 16458 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 16459 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16460 | |
| 16461 | nla_nest_end(msg, rekey_attr); |
| 16462 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16463 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16464 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16465 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16466 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16467 | return; |
| 16468 | |
| 16469 | nla_put_failure: |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16470 | nlmsg_free(msg); |
| 16471 | } |
| 16472 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16473 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 16474 | const u8 *replay_ctr, gfp_t gfp) |
| 16475 | { |
| 16476 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16477 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16478 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16479 | |
| 16480 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 16481 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 16482 | } |
| 16483 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 16484 | |
| 16485 | static void |
| 16486 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 16487 | struct net_device *netdev, int index, |
| 16488 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16489 | { |
| 16490 | struct sk_buff *msg; |
| 16491 | struct nlattr *attr; |
| 16492 | void *hdr; |
| 16493 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16494 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16495 | if (!msg) |
| 16496 | return; |
| 16497 | |
| 16498 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 16499 | if (!hdr) { |
| 16500 | nlmsg_free(msg); |
| 16501 | return; |
| 16502 | } |
| 16503 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16504 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16505 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 16506 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16507 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16508 | attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16509 | if (!attr) |
| 16510 | goto nla_put_failure; |
| 16511 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16512 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 16513 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 16514 | (preauth && |
| 16515 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 16516 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16517 | |
| 16518 | nla_nest_end(msg, attr); |
| 16519 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16520 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16521 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16522 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16523 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16524 | return; |
| 16525 | |
| 16526 | nla_put_failure: |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16527 | nlmsg_free(msg); |
| 16528 | } |
| 16529 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16530 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 16531 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 16532 | { |
| 16533 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16534 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16535 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16536 | |
| 16537 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 16538 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 16539 | } |
| 16540 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 16541 | |
| 16542 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 16543 | struct net_device *netdev, |
| 16544 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16545 | gfp_t gfp, |
| 16546 | enum nl80211_commands notif, |
| 16547 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16548 | { |
| 16549 | struct sk_buff *msg; |
| 16550 | void *hdr; |
| 16551 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16552 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16553 | if (!msg) |
| 16554 | return; |
| 16555 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16556 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16557 | if (!hdr) { |
| 16558 | nlmsg_free(msg); |
| 16559 | return; |
| 16560 | } |
| 16561 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 16562 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 16563 | goto nla_put_failure; |
| 16564 | |
| 16565 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 16566 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16567 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16568 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 16569 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 16570 | goto nla_put_failure; |
| 16571 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16572 | genlmsg_end(msg, hdr); |
| 16573 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16574 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16575 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16576 | return; |
| 16577 | |
| 16578 | nla_put_failure: |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16579 | nlmsg_free(msg); |
| 16580 | } |
| 16581 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16582 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 16583 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 16584 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16585 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16586 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16587 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16588 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 16589 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16590 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 16591 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16592 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 16593 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 16594 | wdev->preset_chandef = *chandef; |
Sergey Matyukevich | 5dc8cdc | 2019-03-26 09:27:37 +0000 | [diff] [blame] | 16595 | |
| 16596 | if (wdev->iftype == NL80211_IFTYPE_STATION && |
| 16597 | !WARN_ON(!wdev->current_bss)) |
Sergey Matyukevich | 0afd425 | 2019-07-26 16:39:34 +0000 | [diff] [blame] | 16598 | cfg80211_update_assoc_bss_entry(wdev, chandef->chan); |
Sergey Matyukevich | 5dc8cdc | 2019-03-26 09:27:37 +0000 | [diff] [blame] | 16599 | |
Michael Vassernis | d34990b | 2019-07-29 06:01:16 +0000 | [diff] [blame] | 16600 | cfg80211_sched_dfs_chan_update(rdev); |
| 16601 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16602 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 16603 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16604 | } |
| 16605 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 16606 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16607 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 16608 | struct cfg80211_chan_def *chandef, |
| 16609 | u8 count) |
| 16610 | { |
| 16611 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16612 | struct wiphy *wiphy = wdev->wiphy; |
| 16613 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16614 | |
| 16615 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 16616 | |
| 16617 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 16618 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 16619 | } |
| 16620 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 16621 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 16622 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16623 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 16624 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16625 | enum nl80211_radar_event event, |
| 16626 | struct net_device *netdev, gfp_t gfp) |
| 16627 | { |
| 16628 | struct sk_buff *msg; |
| 16629 | void *hdr; |
| 16630 | |
| 16631 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16632 | if (!msg) |
| 16633 | return; |
| 16634 | |
| 16635 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 16636 | if (!hdr) { |
| 16637 | nlmsg_free(msg); |
| 16638 | return; |
| 16639 | } |
| 16640 | |
| 16641 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 16642 | goto nla_put_failure; |
| 16643 | |
| 16644 | /* NOP and radar events don't need a netdev parameter */ |
| 16645 | if (netdev) { |
| 16646 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 16647 | |
| 16648 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16649 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16650 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16651 | goto nla_put_failure; |
| 16652 | } |
| 16653 | |
| 16654 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 16655 | goto nla_put_failure; |
| 16656 | |
| 16657 | if (nl80211_send_chandef(msg, chandef)) |
| 16658 | goto nla_put_failure; |
| 16659 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16660 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16661 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16662 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16663 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16664 | return; |
| 16665 | |
| 16666 | nla_put_failure: |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16667 | nlmsg_free(msg); |
| 16668 | } |
| 16669 | |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 16670 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, |
| 16671 | struct sta_opmode_info *sta_opmode, |
| 16672 | gfp_t gfp) |
| 16673 | { |
| 16674 | struct sk_buff *msg; |
| 16675 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16676 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16677 | void *hdr; |
| 16678 | |
| 16679 | if (WARN_ON(!mac)) |
| 16680 | return; |
| 16681 | |
| 16682 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16683 | if (!msg) |
| 16684 | return; |
| 16685 | |
| 16686 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); |
| 16687 | if (!hdr) { |
| 16688 | nlmsg_free(msg); |
| 16689 | return; |
| 16690 | } |
| 16691 | |
| 16692 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 16693 | goto nla_put_failure; |
| 16694 | |
| 16695 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 16696 | goto nla_put_failure; |
| 16697 | |
| 16698 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
| 16699 | goto nla_put_failure; |
| 16700 | |
| 16701 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && |
| 16702 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) |
| 16703 | goto nla_put_failure; |
| 16704 | |
| 16705 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && |
| 16706 | nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) |
| 16707 | goto nla_put_failure; |
| 16708 | |
| 16709 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && |
| 16710 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) |
| 16711 | goto nla_put_failure; |
| 16712 | |
| 16713 | genlmsg_end(msg, hdr); |
| 16714 | |
| 16715 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16716 | NL80211_MCGRP_MLME, gfp); |
| 16717 | |
| 16718 | return; |
| 16719 | |
| 16720 | nla_put_failure: |
| 16721 | nlmsg_free(msg); |
| 16722 | } |
| 16723 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); |
| 16724 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16725 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 16726 | u64 cookie, bool acked, s32 ack_signal, |
| 16727 | bool is_valid_ack_signal, gfp_t gfp) |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16728 | { |
| 16729 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16730 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16731 | struct sk_buff *msg; |
| 16732 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16733 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 16734 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 16735 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 16737 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16738 | if (!msg) |
| 16739 | return; |
| 16740 | |
| 16741 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 16742 | if (!hdr) { |
| 16743 | nlmsg_free(msg); |
| 16744 | return; |
| 16745 | } |
| 16746 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16747 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16748 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16749 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16750 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16751 | NL80211_ATTR_PAD) || |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 16752 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
| 16753 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, |
| 16754 | ack_signal))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16755 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16756 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16757 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16758 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16759 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16760 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16761 | return; |
| 16762 | |
| 16763 | nla_put_failure: |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16764 | nlmsg_free(msg); |
| 16765 | } |
| 16766 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 16767 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16768 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 16769 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16770 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16771 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16772 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16773 | struct sk_buff *msg; |
| 16774 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16775 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16776 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 16777 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 16778 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16779 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 16780 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 16781 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 16782 | if (!msg) { |
| 16783 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 16784 | return; |
| 16785 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16786 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16787 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 16788 | if (!hdr) |
| 16789 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16790 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16791 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16792 | (freq && |
| 16793 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 16794 | (sig_dbm && |
| 16795 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 16796 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 16797 | goto nla_put_failure; |
| 16798 | |
| 16799 | genlmsg_end(msg, hdr); |
| 16800 | |
| 16801 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16802 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16803 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16804 | return; |
| 16805 | |
| 16806 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16807 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16808 | nlmsg_free(msg); |
| 16809 | } |
| 16810 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 16811 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16812 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 16813 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 16814 | struct cfg80211_wowlan_wakeup *wakeup) |
| 16815 | { |
| 16816 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 16817 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 16818 | int i, j; |
| 16819 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16820 | nl_results = nla_nest_start_noflag(msg, |
| 16821 | NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 16822 | if (!nl_results) |
| 16823 | return -EMSGSIZE; |
| 16824 | |
| 16825 | for (i = 0; i < nd->n_matches; i++) { |
| 16826 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 16827 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16828 | nl_match = nla_nest_start_noflag(msg, i); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 16829 | if (!nl_match) |
| 16830 | break; |
| 16831 | |
| 16832 | /* The SSID attribute is optional in nl80211, but for |
| 16833 | * simplicity reasons it's always present in the |
| 16834 | * cfg80211 structure. If a driver can't pass the |
| 16835 | * SSID, that needs to be changed. A zero length SSID |
| 16836 | * is still a valid SSID (wildcard), so it cannot be |
| 16837 | * used for this purpose. |
| 16838 | */ |
| 16839 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 16840 | match->ssid.ssid)) { |
| 16841 | nla_nest_cancel(msg, nl_match); |
| 16842 | goto out; |
| 16843 | } |
| 16844 | |
| 16845 | if (match->n_channels) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16846 | nl_freqs = nla_nest_start_noflag(msg, |
| 16847 | NL80211_ATTR_SCAN_FREQUENCIES); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 16848 | if (!nl_freqs) { |
| 16849 | nla_nest_cancel(msg, nl_match); |
| 16850 | goto out; |
| 16851 | } |
| 16852 | |
| 16853 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 16854 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 16855 | nla_nest_cancel(msg, nl_freqs); |
| 16856 | nla_nest_cancel(msg, nl_match); |
| 16857 | goto out; |
| 16858 | } |
| 16859 | } |
| 16860 | |
| 16861 | nla_nest_end(msg, nl_freqs); |
| 16862 | } |
| 16863 | |
| 16864 | nla_nest_end(msg, nl_match); |
| 16865 | } |
| 16866 | |
| 16867 | out: |
| 16868 | nla_nest_end(msg, nl_results); |
| 16869 | return 0; |
| 16870 | } |
| 16871 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16872 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 16873 | struct cfg80211_wowlan_wakeup *wakeup, |
| 16874 | gfp_t gfp) |
| 16875 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16876 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16877 | struct sk_buff *msg; |
| 16878 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16879 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16880 | |
| 16881 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 16882 | |
| 16883 | if (wakeup) |
| 16884 | size += wakeup->packet_present_len; |
| 16885 | |
| 16886 | msg = nlmsg_new(size, gfp); |
| 16887 | if (!msg) |
| 16888 | return; |
| 16889 | |
| 16890 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 16891 | if (!hdr) |
| 16892 | goto free_msg; |
| 16893 | |
| 16894 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16895 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16896 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16897 | goto free_msg; |
| 16898 | |
| 16899 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16900 | wdev->netdev->ifindex)) |
| 16901 | goto free_msg; |
| 16902 | |
| 16903 | if (wakeup) { |
| 16904 | struct nlattr *reasons; |
| 16905 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16906 | reasons = nla_nest_start_noflag(msg, |
| 16907 | NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 16908 | if (!reasons) |
| 16909 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16910 | |
| 16911 | if (wakeup->disconnect && |
| 16912 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 16913 | goto free_msg; |
| 16914 | if (wakeup->magic_pkt && |
| 16915 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 16916 | goto free_msg; |
| 16917 | if (wakeup->gtk_rekey_failure && |
| 16918 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 16919 | goto free_msg; |
| 16920 | if (wakeup->eap_identity_req && |
| 16921 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 16922 | goto free_msg; |
| 16923 | if (wakeup->four_way_handshake && |
| 16924 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 16925 | goto free_msg; |
| 16926 | if (wakeup->rfkill_release && |
| 16927 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 16928 | goto free_msg; |
| 16929 | |
| 16930 | if (wakeup->pattern_idx >= 0 && |
| 16931 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 16932 | wakeup->pattern_idx)) |
| 16933 | goto free_msg; |
| 16934 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 16935 | if (wakeup->tcp_match && |
| 16936 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 16937 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 16938 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 16939 | if (wakeup->tcp_connlost && |
| 16940 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 16941 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 16942 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 16943 | if (wakeup->tcp_nomoretokens && |
| 16944 | nla_put_flag(msg, |
| 16945 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 16946 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 16947 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16948 | if (wakeup->packet) { |
| 16949 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 16950 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 16951 | |
| 16952 | if (!wakeup->packet_80211) { |
| 16953 | pkt_attr = |
| 16954 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 16955 | len_attr = |
| 16956 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 16957 | } |
| 16958 | |
| 16959 | if (wakeup->packet_len && |
| 16960 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 16961 | goto free_msg; |
| 16962 | |
| 16963 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 16964 | wakeup->packet)) |
| 16965 | goto free_msg; |
| 16966 | } |
| 16967 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 16968 | if (wakeup->net_detect && |
| 16969 | cfg80211_net_detect_results(msg, wakeup)) |
| 16970 | goto free_msg; |
| 16971 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16972 | nla_nest_end(msg, reasons); |
| 16973 | } |
| 16974 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16975 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16976 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16977 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16978 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16979 | return; |
| 16980 | |
| 16981 | free_msg: |
| 16982 | nlmsg_free(msg); |
| 16983 | } |
| 16984 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 16985 | #endif |
| 16986 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 16987 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 16988 | enum nl80211_tdls_operation oper, |
| 16989 | u16 reason_code, gfp_t gfp) |
| 16990 | { |
| 16991 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16992 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 16993 | struct sk_buff *msg; |
| 16994 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 16995 | |
| 16996 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 16997 | reason_code); |
| 16998 | |
| 16999 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17000 | if (!msg) |
| 17001 | return; |
| 17002 | |
| 17003 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 17004 | if (!hdr) { |
| 17005 | nlmsg_free(msg); |
| 17006 | return; |
| 17007 | } |
| 17008 | |
| 17009 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17010 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17011 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 17012 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 17013 | (reason_code > 0 && |
| 17014 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 17015 | goto nla_put_failure; |
| 17016 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17017 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17018 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17019 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17020 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17021 | return; |
| 17022 | |
| 17023 | nla_put_failure: |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17024 | nlmsg_free(msg); |
| 17025 | } |
| 17026 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 17027 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17028 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 17029 | unsigned long state, |
| 17030 | void *_notify) |
| 17031 | { |
| 17032 | struct netlink_notify *notify = _notify; |
| 17033 | struct cfg80211_registered_device *rdev; |
| 17034 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17035 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17036 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 17037 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17038 | return NOTIFY_DONE; |
| 17039 | |
| 17040 | rcu_read_lock(); |
| 17041 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17042 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17043 | struct cfg80211_sched_scan_request *sched_scan_req; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 17044 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17045 | list_for_each_entry_rcu(sched_scan_req, |
| 17046 | &rdev->sched_scan_req_list, |
| 17047 | list) { |
| 17048 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 17049 | sched_scan_req->nl_owner_dead = true; |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 17050 | schedule_work(&rdev->sched_scan_stop_wk); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17051 | } |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 17052 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 17053 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 17054 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 17055 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17056 | |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 17057 | if (wdev->owner_nlportid == notify->portid) { |
| 17058 | wdev->nl_owner_dead = true; |
| 17059 | schedule_work(&rdev->destroy_work); |
| 17060 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 17061 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 17062 | } |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 17063 | |
| 17064 | cfg80211_release_pmsr(wdev, notify->portid); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 17065 | } |
| 17066 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17067 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 17068 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 17069 | list) { |
| 17070 | if (reg->nlportid == notify->portid) { |
| 17071 | list_del(®->list); |
| 17072 | kfree(reg); |
| 17073 | break; |
| 17074 | } |
| 17075 | } |
| 17076 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17077 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17078 | |
| 17079 | rcu_read_unlock(); |
| 17080 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 17081 | /* |
| 17082 | * It is possible that the user space process that is controlling the |
| 17083 | * indoor setting disappeared, so notify the regulatory core. |
| 17084 | */ |
| 17085 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 17086 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17087 | } |
| 17088 | |
| 17089 | static struct notifier_block nl80211_netlink_notifier = { |
| 17090 | .notifier_call = nl80211_netlink_notify, |
| 17091 | }; |
| 17092 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17093 | void cfg80211_ft_event(struct net_device *netdev, |
| 17094 | struct cfg80211_ft_event_params *ft_event) |
| 17095 | { |
| 17096 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17097 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17098 | struct sk_buff *msg; |
| 17099 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17100 | |
| 17101 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 17102 | |
| 17103 | if (!ft_event->target_ap) |
| 17104 | return; |
| 17105 | |
Dedy Lansky | 1039d08 | 2018-05-17 16:25:03 +0300 | [diff] [blame] | 17106 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
| 17107 | GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17108 | if (!msg) |
| 17109 | return; |
| 17110 | |
| 17111 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17112 | if (!hdr) |
| 17113 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17114 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17115 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17116 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17117 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 17118 | goto out; |
| 17119 | |
| 17120 | if (ft_event->ies && |
| 17121 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 17122 | goto out; |
| 17123 | if (ft_event->ric_ies && |
| 17124 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 17125 | ft_event->ric_ies)) |
| 17126 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17127 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17128 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17129 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17130 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17131 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17132 | return; |
| 17133 | out: |
| 17134 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17135 | } |
| 17136 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 17137 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17138 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 17139 | { |
| 17140 | struct cfg80211_registered_device *rdev; |
| 17141 | struct sk_buff *msg; |
| 17142 | void *hdr; |
| 17143 | u32 nlportid; |
| 17144 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17145 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17146 | if (!rdev->crit_proto_nlportid) |
| 17147 | return; |
| 17148 | |
| 17149 | nlportid = rdev->crit_proto_nlportid; |
| 17150 | rdev->crit_proto_nlportid = 0; |
| 17151 | |
| 17152 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17153 | if (!msg) |
| 17154 | return; |
| 17155 | |
| 17156 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 17157 | if (!hdr) |
| 17158 | goto nla_put_failure; |
| 17159 | |
| 17160 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17161 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17162 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17163 | goto nla_put_failure; |
| 17164 | |
| 17165 | genlmsg_end(msg, hdr); |
| 17166 | |
| 17167 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 17168 | return; |
| 17169 | |
| 17170 | nla_put_failure: |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17171 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17172 | } |
| 17173 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 17174 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17175 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 17176 | { |
| 17177 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17178 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17179 | struct sk_buff *msg; |
| 17180 | void *hdr; |
| 17181 | |
| 17182 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 17183 | if (!msg) |
| 17184 | return; |
| 17185 | |
| 17186 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 17187 | if (!hdr) |
| 17188 | goto out; |
| 17189 | |
| 17190 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17191 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17192 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17193 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17194 | goto out; |
| 17195 | |
| 17196 | genlmsg_end(msg, hdr); |
| 17197 | |
| 17198 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 17199 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 17200 | return; |
| 17201 | out: |
| 17202 | nlmsg_free(msg); |
| 17203 | } |
| 17204 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 17205 | int cfg80211_external_auth_request(struct net_device *dev, |
| 17206 | struct cfg80211_external_auth_params *params, |
| 17207 | gfp_t gfp) |
| 17208 | { |
| 17209 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17210 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17211 | struct sk_buff *msg; |
| 17212 | void *hdr; |
| 17213 | |
| 17214 | if (!wdev->conn_owner_nlportid) |
| 17215 | return -EINVAL; |
| 17216 | |
| 17217 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17218 | if (!msg) |
| 17219 | return -ENOMEM; |
| 17220 | |
| 17221 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 17222 | if (!hdr) |
| 17223 | goto nla_put_failure; |
| 17224 | |
| 17225 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17226 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17227 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || |
| 17228 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, |
| 17229 | params->action) || |
| 17230 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || |
| 17231 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, |
| 17232 | params->ssid.ssid)) |
| 17233 | goto nla_put_failure; |
| 17234 | |
| 17235 | genlmsg_end(msg, hdr); |
| 17236 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 17237 | wdev->conn_owner_nlportid); |
| 17238 | return 0; |
| 17239 | |
| 17240 | nla_put_failure: |
| 17241 | nlmsg_free(msg); |
| 17242 | return -ENOBUFS; |
| 17243 | } |
| 17244 | EXPORT_SYMBOL(cfg80211_external_auth_request); |
| 17245 | |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 17246 | void cfg80211_update_owe_info_event(struct net_device *netdev, |
| 17247 | struct cfg80211_update_owe_info *owe_info, |
| 17248 | gfp_t gfp) |
| 17249 | { |
| 17250 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 17251 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17252 | struct sk_buff *msg; |
| 17253 | void *hdr; |
| 17254 | |
| 17255 | trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); |
| 17256 | |
| 17257 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17258 | if (!msg) |
| 17259 | return; |
| 17260 | |
| 17261 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); |
| 17262 | if (!hdr) |
| 17263 | goto nla_put_failure; |
| 17264 | |
| 17265 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17266 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17267 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) |
| 17268 | goto nla_put_failure; |
| 17269 | |
| 17270 | if (!owe_info->ie_len || |
| 17271 | nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) |
| 17272 | goto nla_put_failure; |
| 17273 | |
| 17274 | genlmsg_end(msg, hdr); |
| 17275 | |
| 17276 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17277 | NL80211_MCGRP_MLME, gfp); |
| 17278 | return; |
| 17279 | |
| 17280 | nla_put_failure: |
| 17281 | genlmsg_cancel(msg, hdr); |
| 17282 | nlmsg_free(msg); |
| 17283 | } |
| 17284 | EXPORT_SYMBOL(cfg80211_update_owe_info_event); |
| 17285 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17286 | /* initialisation/exit functions */ |
| 17287 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 17288 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17289 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 17290 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17291 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 17292 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17293 | if (err) |
| 17294 | return err; |
| 17295 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17296 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 17297 | if (err) |
| 17298 | goto err_out; |
| 17299 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17300 | return 0; |
| 17301 | err_out: |
| 17302 | genl_unregister_family(&nl80211_fam); |
| 17303 | return err; |
| 17304 | } |
| 17305 | |
| 17306 | void nl80211_exit(void) |
| 17307 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17308 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17309 | genl_unregister_family(&nl80211_fam); |
| 17310 | } |