Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 2740f0c | 2014-09-03 15:24:58 +0300 | [diff] [blame] | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 6 | * Copyright 2015-2017 Intel Deutschland GmbH |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 7 | * Copyright (C) 2018 Intel Corporation |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/if.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14 | #include <linux/list.h> |
| 15 | #include <linux/if_ether.h> |
| 16 | #include <linux/ieee80211.h> |
| 17 | #include <linux/nl80211.h> |
| 18 | #include <linux/rtnetlink.h> |
| 19 | #include <linux/netlink.h> |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 20 | #include <linux/nospec.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 21 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 22 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include <net/genetlink.h> |
| 24 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 25 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 26 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | #include "core.h" |
| 28 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 29 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 30 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 31 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 32 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 33 | struct genl_info *info, |
| 34 | struct cfg80211_crypto_settings *settings, |
| 35 | int cipher_limit); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 38 | static struct genl_family nl80211_fam; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 39 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 40 | /* multicast groups */ |
| 41 | enum nl80211_multicast_groups { |
| 42 | NL80211_MCGRP_CONFIG, |
| 43 | NL80211_MCGRP_SCAN, |
| 44 | NL80211_MCGRP_REGULATORY, |
| 45 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 46 | NL80211_MCGRP_VENDOR, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 47 | NL80211_MCGRP_NAN, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 48 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 49 | }; |
| 50 | |
| 51 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 52 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 53 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 54 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 55 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 56 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 57 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 58 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 59 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 60 | #endif |
| 61 | }; |
| 62 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 63 | /* returns ERR_PTR values */ |
| 64 | static struct wireless_dev * |
| 65 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | struct cfg80211_registered_device *rdev; |
| 68 | struct wireless_dev *result = NULL; |
| 69 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 70 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 71 | u64 wdev_id; |
| 72 | int wiphy_idx = -1; |
| 73 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 74 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 75 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 77 | if (!have_ifidx && !have_wdev_id) |
| 78 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 79 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 80 | if (have_ifidx) |
| 81 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 82 | if (have_wdev_id) { |
| 83 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 84 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 85 | } |
| 86 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 87 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 88 | struct wireless_dev *wdev; |
| 89 | |
| 90 | if (wiphy_net(&rdev->wiphy) != netns) |
| 91 | continue; |
| 92 | |
| 93 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 94 | continue; |
| 95 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 96 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 97 | if (have_ifidx && wdev->netdev && |
| 98 | wdev->netdev->ifindex == ifidx) { |
| 99 | result = wdev; |
| 100 | break; |
| 101 | } |
| 102 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 103 | result = wdev; |
| 104 | break; |
| 105 | } |
| 106 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 107 | |
| 108 | if (result) |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | if (result) |
| 113 | return result; |
| 114 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 117 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 118 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 119 | { |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 120 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 121 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 123 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 124 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 125 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 126 | !attrs[NL80211_ATTR_IFINDEX] && |
| 127 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 128 | return ERR_PTR(-EINVAL); |
| 129 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 130 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 131 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 132 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 133 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 134 | if (attrs[NL80211_ATTR_WDEV]) { |
| 135 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 136 | struct wireless_dev *wdev; |
| 137 | bool found = false; |
| 138 | |
| 139 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 140 | if (tmp) { |
| 141 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 142 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 143 | if (wdev->identifier != (u32)wdev_id) |
| 144 | continue; |
| 145 | found = true; |
| 146 | break; |
| 147 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 148 | |
| 149 | if (!found) |
| 150 | tmp = NULL; |
| 151 | |
| 152 | if (rdev && tmp != rdev) |
| 153 | return ERR_PTR(-EINVAL); |
| 154 | rdev = tmp; |
| 155 | } |
| 156 | } |
| 157 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 158 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 159 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 160 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 161 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 162 | if (netdev) { |
| 163 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 164 | tmp = wiphy_to_rdev( |
| 165 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 166 | else |
| 167 | tmp = NULL; |
| 168 | |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 169 | /* not wireless device -- return error */ |
| 170 | if (!tmp) |
| 171 | return ERR_PTR(-EINVAL); |
| 172 | |
| 173 | /* mismatch -- return error */ |
| 174 | if (rdev && tmp != rdev) |
| 175 | return ERR_PTR(-EINVAL); |
| 176 | |
| 177 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 178 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 179 | } |
| 180 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 181 | if (!rdev) |
| 182 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 183 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 184 | if (netns != wiphy_net(&rdev->wiphy)) |
| 185 | return ERR_PTR(-ENODEV); |
| 186 | |
| 187 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* |
| 191 | * This function returns a pointer to the driver |
| 192 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 193 | * |
| 194 | * The result of this can be a PTR_ERR and hence must |
| 195 | * be checked with IS_ERR() for errors. |
| 196 | */ |
| 197 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 198 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 199 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 200 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 203 | static int validate_ie_attr(const struct nlattr *attr, |
| 204 | struct netlink_ext_ack *extack) |
| 205 | { |
| 206 | const u8 *pos; |
| 207 | int len; |
| 208 | |
| 209 | pos = nla_data(attr); |
| 210 | len = nla_len(attr); |
| 211 | |
| 212 | while (len) { |
| 213 | u8 elemlen; |
| 214 | |
| 215 | if (len < 2) |
| 216 | goto error; |
| 217 | len -= 2; |
| 218 | |
| 219 | elemlen = pos[1]; |
| 220 | if (elemlen > len) |
| 221 | goto error; |
| 222 | |
| 223 | len -= elemlen; |
| 224 | pos += 2 + elemlen; |
| 225 | } |
| 226 | |
| 227 | return 0; |
| 228 | error: |
| 229 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); |
| 230 | return -EINVAL; |
| 231 | } |
| 232 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 233 | /* policy for the attributes */ |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 234 | static const struct nla_policy |
| 235 | nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { |
| 236 | [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, |
| 237 | [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, |
| 238 | .len = U8_MAX }, |
| 239 | [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, |
| 240 | .len = U8_MAX }, |
| 241 | }; |
| 242 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 243 | static const struct nla_policy |
| 244 | nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { |
| 245 | [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, |
| 246 | [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, |
| 247 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = |
| 248 | NLA_POLICY_MAX(NLA_U8, 15), |
| 249 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, |
| 250 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = |
| 251 | NLA_POLICY_MAX(NLA_U8, 15), |
| 252 | [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = |
| 253 | NLA_POLICY_MAX(NLA_U8, 15), |
| 254 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, |
| 255 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, |
| 256 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, |
| 257 | }; |
| 258 | |
| 259 | static const struct nla_policy |
| 260 | nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { |
| 261 | [NL80211_PMSR_TYPE_FTM] = |
| 262 | NLA_POLICY_NESTED(NL80211_PMSR_FTM_REQ_ATTR_MAX, |
| 263 | nl80211_pmsr_ftm_req_attr_policy), |
| 264 | }; |
| 265 | |
| 266 | static const struct nla_policy |
| 267 | nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { |
| 268 | [NL80211_PMSR_REQ_ATTR_DATA] = |
| 269 | NLA_POLICY_NESTED(NL80211_PMSR_TYPE_MAX, |
| 270 | nl80211_pmsr_req_data_policy), |
| 271 | [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, |
| 272 | }; |
| 273 | |
| 274 | static const struct nla_policy |
| 275 | nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { |
| 276 | [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, |
| 277 | /* |
| 278 | * we could specify this again to be the top-level policy, |
| 279 | * but that would open us up to recursion problems ... |
| 280 | */ |
| 281 | [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_NESTED }, |
| 282 | [NL80211_PMSR_PEER_ATTR_REQ] = |
| 283 | NLA_POLICY_NESTED(NL80211_PMSR_REQ_ATTR_MAX, |
| 284 | nl80211_pmsr_req_attr_policy), |
| 285 | [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, |
| 286 | }; |
| 287 | |
| 288 | static const struct nla_policy |
| 289 | nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { |
| 290 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, |
| 291 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, |
| 292 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, |
| 293 | [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, |
| 294 | [NL80211_PMSR_ATTR_PEERS] = |
| 295 | NLA_POLICY_NESTED_ARRAY(NL80211_PMSR_PEER_ATTR_MAX, |
| 296 | nl80211_psmr_peer_attr_policy), |
| 297 | }; |
| 298 | |
| 299 | const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 300 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 301 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 302 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 304 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 305 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 306 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 307 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 308 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 309 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 310 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 312 | [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 314 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 315 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 317 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 319 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 320 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 321 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 323 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 324 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 325 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 326 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 327 | .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 328 | [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 5), |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 330 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 331 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_KEY_TYPE] = |
| 333 | NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 334 | |
| 335 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 336 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 337 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 338 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 339 | [NL80211_ATTR_BEACON_TAIL] = |
| 340 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 341 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 342 | [NL80211_ATTR_STA_AID] = |
| 343 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 344 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 345 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 346 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 347 | .len = NL80211_MAX_SUPP_RATES }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_STA_PLINK_ACTION] = |
| 349 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 350 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 352 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 353 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 354 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 355 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 356 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 357 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 358 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 359 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 360 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 361 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 362 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 363 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 364 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 365 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 366 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 367 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 368 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 369 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 370 | |
| 371 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 372 | [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, |
| 373 | validate_ie_attr, |
| 374 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 375 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 376 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 377 | |
| 378 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 379 | .len = IEEE80211_MAX_SSID_LEN }, |
| 380 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 381 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 382 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 383 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 384 | [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, |
| 385 | NL80211_MFP_NO, |
| 386 | NL80211_MFP_OPTIONAL), |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 387 | [NL80211_ATTR_STA_FLAGS2] = { |
| 388 | .len = sizeof(struct nl80211_sta_flag_update), |
| 389 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 390 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 391 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 392 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 393 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 394 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 395 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 396 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 397 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 398 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Srinivas Dasari | 9361df1 | 2017-07-07 01:43:39 +0300 | [diff] [blame] | 399 | [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 400 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 401 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 402 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 403 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 404 | .len = IEEE80211_MAX_DATA_LEN }, |
| 405 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 406 | [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, |
| 407 | NL80211_PS_DISABLED, |
| 408 | NL80211_PS_ENABLED), |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 409 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 410 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 411 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 412 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 413 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 414 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 415 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 416 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 417 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 418 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 419 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 420 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 421 | [NL80211_ATTR_STA_PLINK_STATE] = |
| 422 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), |
| 423 | [NL80211_ATTR_MESH_PEER_AID] = |
| 424 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 425 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 426 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 427 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 428 | [NL80211_ATTR_HIDDEN_SSID] = |
| 429 | NLA_POLICY_RANGE(NLA_U32, |
| 430 | NL80211_HIDDEN_SSID_NOT_IN_USE, |
| 431 | NL80211_HIDDEN_SSID_ZERO_CONTENTS), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 432 | [NL80211_ATTR_IE_PROBE_RESP] = |
| 433 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 434 | IEEE80211_MAX_DATA_LEN), |
| 435 | [NL80211_ATTR_IE_ASSOC_RESP] = |
| 436 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 437 | IEEE80211_MAX_DATA_LEN), |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 438 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 439 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 440 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 441 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 442 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 443 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 444 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 445 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 446 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 447 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 448 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 449 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 450 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 451 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 452 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 453 | .len = NL80211_HT_CAPABILITY_LEN |
| 454 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 455 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 456 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 457 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 458 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 459 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 460 | [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 461 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 462 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 463 | [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), |
| 464 | [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 465 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = |
| 466 | NLA_POLICY_RANGE(NLA_U32, |
| 467 | NL80211_MESH_POWER_UNKNOWN + 1, |
| 468 | NL80211_MESH_POWER_MAX), |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 469 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 470 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 471 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 472 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 473 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 474 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 475 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 476 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 477 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 478 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 479 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 480 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 481 | [NL80211_ATTR_PEER_AID] = |
| 482 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 483 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 484 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 485 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 486 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 487 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 488 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 489 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 490 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 491 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 492 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 493 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 494 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 495 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 496 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 497 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 498 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 499 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 500 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 501 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 502 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 503 | [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), |
| 504 | [NL80211_ATTR_USER_PRIO] = |
| 505 | NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 506 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 507 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 508 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 509 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 510 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 511 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 512 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 513 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 514 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 515 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = |
| 516 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 517 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 518 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 519 | }, |
| 520 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 521 | [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 522 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 523 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 524 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 525 | .len = FILS_MAX_KEK_LEN }, |
| 526 | [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 527 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 528 | [NL80211_ATTR_BSSID] = { .len = ETH_ALEN }, |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 529 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 530 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 531 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 532 | }, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 533 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 534 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 535 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 536 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 537 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 538 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 539 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 540 | .len = FILS_ERP_MAX_RRK_LEN }, |
| 541 | [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 }, |
| 542 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 543 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 544 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 545 | |
| 546 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, |
| 547 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, |
| 548 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 549 | [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY, |
| 550 | .len = NL80211_HE_MAX_CAPABILITY_LEN }, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 551 | |
| 552 | [NL80211_ATTR_FTM_RESPONDER] = { |
| 553 | .type = NLA_NESTED, |
| 554 | .validation_data = nl80211_ftm_responder_policy, |
| 555 | }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 556 | [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), |
| 557 | [NL80211_ATTR_PEER_MEASUREMENTS] = |
| 558 | NLA_POLICY_NESTED(NL80211_PMSR_FTM_REQ_ATTR_MAX, |
| 559 | nl80211_pmsr_attr_policy), |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 560 | [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 561 | }; |
| 562 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 563 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 564 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 565 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 566 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 567 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 568 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 569 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 570 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 571 | [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 572 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 573 | }; |
| 574 | |
| 575 | /* policy for the key default flags */ |
| 576 | static const struct nla_policy |
| 577 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 578 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 579 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 580 | }; |
| 581 | |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 582 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 583 | /* policy for WoWLAN attributes */ |
| 584 | static const struct nla_policy |
| 585 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 586 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 587 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 588 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 589 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 590 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 591 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 592 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 593 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 594 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 595 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 596 | }; |
| 597 | |
| 598 | static const struct nla_policy |
| 599 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 600 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 601 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 602 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 603 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 604 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 605 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 606 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 607 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 608 | }, |
| 609 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 610 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 611 | }, |
| 612 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 613 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 614 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 615 | }; |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 616 | #endif /* CONFIG_PM */ |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 617 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 618 | /* policy for coalesce rule attributes */ |
| 619 | static const struct nla_policy |
| 620 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 621 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 622 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = |
| 623 | NLA_POLICY_RANGE(NLA_U32, |
| 624 | NL80211_COALESCE_CONDITION_MATCH, |
| 625 | NL80211_COALESCE_CONDITION_NO_MATCH), |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 626 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 627 | }; |
| 628 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 629 | /* policy for GTK rekey offload attributes */ |
| 630 | static const struct nla_policy |
| 631 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 632 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 633 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 634 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 635 | }; |
| 636 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 637 | static const struct nla_policy |
| 638 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 639 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 640 | .len = IEEE80211_MAX_SSID_LEN }, |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 641 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 642 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 643 | }; |
| 644 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 645 | static const struct nla_policy |
| 646 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 647 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 648 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 649 | }; |
| 650 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 651 | static const struct nla_policy |
| 652 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 653 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 654 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 655 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 656 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 657 | }, |
| 658 | }; |
| 659 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 660 | /* policy for NAN function attributes */ |
| 661 | static const struct nla_policy |
| 662 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
| 663 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, |
Srinivas Dasari | 0a27844 | 2017-07-07 01:43:40 +0300 | [diff] [blame] | 664 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 665 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 666 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 667 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 668 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 669 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 670 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
| 671 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN }, |
| 672 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 673 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 674 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 675 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 676 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 677 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 678 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 679 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 680 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 681 | }; |
| 682 | |
| 683 | /* policy for Service Response Filter attributes */ |
| 684 | static const struct nla_policy |
| 685 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 686 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 687 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 688 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 689 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 690 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 691 | }; |
| 692 | |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 693 | /* policy for packet pattern attributes */ |
| 694 | static const struct nla_policy |
| 695 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { |
| 696 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, |
| 697 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, |
| 698 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, |
| 699 | }; |
| 700 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 701 | int nl80211_prepare_wdev_dump(struct netlink_callback *cb, |
| 702 | struct cfg80211_registered_device **rdev, |
| 703 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 704 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 705 | int err; |
| 706 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 707 | if (!cb->args[0]) { |
| 708 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 709 | genl_family_attrbuf(&nl80211_fam), |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 710 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 711 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 712 | return err; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 713 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 714 | *wdev = __cfg80211_wdev_from_attrs( |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 715 | sock_net(cb->skb->sk), |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 716 | genl_family_attrbuf(&nl80211_fam)); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 717 | if (IS_ERR(*wdev)) |
| 718 | return PTR_ERR(*wdev); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 719 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 720 | /* 0 is the first index - add 1 to parse only once */ |
| 721 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 722 | cb->args[1] = (*wdev)->identifier; |
| 723 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 724 | /* subtract the 1 again here */ |
| 725 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 726 | struct wireless_dev *tmp; |
| 727 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 728 | if (!wiphy) |
| 729 | return -ENODEV; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 730 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 731 | *wdev = NULL; |
| 732 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 733 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 734 | if (tmp->identifier == cb->args[1]) { |
| 735 | *wdev = tmp; |
| 736 | break; |
| 737 | } |
| 738 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 739 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 740 | if (!*wdev) |
| 741 | return -ENODEV; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 742 | } |
| 743 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 744 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 745 | } |
| 746 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 747 | /* message building helper */ |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 748 | void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
| 749 | int flags, u8 cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 750 | { |
| 751 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 752 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 753 | } |
| 754 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 755 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, |
| 756 | const struct ieee80211_reg_rule *rule) |
| 757 | { |
| 758 | int j; |
| 759 | struct nlattr *nl_wmm_rules = |
| 760 | nla_nest_start(msg, NL80211_FREQUENCY_ATTR_WMM); |
| 761 | |
| 762 | if (!nl_wmm_rules) |
| 763 | goto nla_put_failure; |
| 764 | |
| 765 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { |
| 766 | struct nlattr *nl_wmm_rule = nla_nest_start(msg, j); |
| 767 | |
| 768 | if (!nl_wmm_rule) |
| 769 | goto nla_put_failure; |
| 770 | |
| 771 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 772 | rule->wmm_rule.client[j].cw_min) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 773 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 774 | rule->wmm_rule.client[j].cw_max) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 775 | nla_put_u8(msg, NL80211_WMMR_AIFSN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 776 | rule->wmm_rule.client[j].aifsn) || |
Haim Dreyfuss | d3c89bb | 2018-08-21 09:22:19 +0300 | [diff] [blame] | 777 | nla_put_u16(msg, NL80211_WMMR_TXOP, |
| 778 | rule->wmm_rule.client[j].cot)) |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 779 | goto nla_put_failure; |
| 780 | |
| 781 | nla_nest_end(msg, nl_wmm_rule); |
| 782 | } |
| 783 | nla_nest_end(msg, nl_wmm_rules); |
| 784 | |
| 785 | return 0; |
| 786 | |
| 787 | nla_put_failure: |
| 788 | return -ENOBUFS; |
| 789 | } |
| 790 | |
| 791 | 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] | 792 | struct ieee80211_channel *chan, |
| 793 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 794 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 795 | /* Some channels must be completely excluded from the |
| 796 | * list to protect old user-space tools from breaking |
| 797 | */ |
| 798 | if (!large && chan->flags & |
| 799 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 800 | return 0; |
| 801 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 802 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 803 | chan->center_freq)) |
| 804 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 805 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 806 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 807 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 808 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 809 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 810 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 811 | goto nla_put_failure; |
| 812 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 813 | goto nla_put_failure; |
| 814 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 815 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 816 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 817 | goto nla_put_failure; |
| 818 | if (large) { |
| 819 | u32 time; |
| 820 | |
| 821 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 822 | |
| 823 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 824 | chan->dfs_state)) |
| 825 | goto nla_put_failure; |
| 826 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 827 | time)) |
| 828 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 829 | if (nla_put_u32(msg, |
| 830 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 831 | chan->dfs_cac_ms)) |
| 832 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 833 | } |
| 834 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 835 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 836 | if (large) { |
| 837 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 838 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 839 | goto nla_put_failure; |
| 840 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 841 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 842 | goto nla_put_failure; |
| 843 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 844 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 845 | goto nla_put_failure; |
| 846 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 847 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 848 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 849 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 850 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 851 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 852 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 853 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 854 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 855 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 856 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 857 | goto nla_put_failure; |
| 858 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 859 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 860 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 861 | } |
| 862 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 863 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 864 | DBM_TO_MBM(chan->max_power))) |
| 865 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 866 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 867 | if (large) { |
| 868 | const struct ieee80211_reg_rule *rule = |
Haim Dreyfuss | b88d26d | 2018-08-21 09:22:20 +0300 | [diff] [blame] | 869 | freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 870 | |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 871 | if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 872 | if (nl80211_msg_put_wmm_rules(msg, rule)) |
| 873 | goto nla_put_failure; |
| 874 | } |
| 875 | } |
| 876 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 877 | return 0; |
| 878 | |
| 879 | nla_put_failure: |
| 880 | return -ENOBUFS; |
| 881 | } |
| 882 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 883 | static bool nl80211_put_txq_stats(struct sk_buff *msg, |
| 884 | struct cfg80211_txq_stats *txqstats, |
| 885 | int attrtype) |
| 886 | { |
| 887 | struct nlattr *txqattr; |
| 888 | |
| 889 | #define PUT_TXQVAL_U32(attr, memb) do { \ |
| 890 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ |
| 891 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ |
| 892 | return false; \ |
| 893 | } while (0) |
| 894 | |
| 895 | txqattr = nla_nest_start(msg, attrtype); |
| 896 | if (!txqattr) |
| 897 | return false; |
| 898 | |
| 899 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); |
| 900 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); |
| 901 | PUT_TXQVAL_U32(FLOWS, flows); |
| 902 | PUT_TXQVAL_U32(DROPS, drops); |
| 903 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); |
| 904 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); |
| 905 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); |
| 906 | PUT_TXQVAL_U32(COLLISIONS, collisions); |
| 907 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); |
| 908 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); |
| 909 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); |
| 910 | nla_nest_end(msg, txqattr); |
| 911 | |
| 912 | #undef PUT_TXQVAL_U32 |
| 913 | return true; |
| 914 | } |
| 915 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 916 | /* netlink command implementations */ |
| 917 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 918 | struct key_parse { |
| 919 | struct key_params p; |
| 920 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 921 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 922 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 923 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 924 | }; |
| 925 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 926 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
| 927 | struct key_parse *k) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 928 | { |
| 929 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 930 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 931 | nl80211_key_policy, info->extack); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 932 | if (err) |
| 933 | return err; |
| 934 | |
| 935 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 936 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 937 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 938 | if (k->def) { |
| 939 | k->def_uni = true; |
| 940 | k->def_multi = true; |
| 941 | } |
| 942 | if (k->defmgmt) |
| 943 | k->def_multi = true; |
| 944 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 945 | if (tb[NL80211_KEY_IDX]) |
| 946 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 947 | |
| 948 | if (tb[NL80211_KEY_DATA]) { |
| 949 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 950 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 951 | } |
| 952 | |
| 953 | if (tb[NL80211_KEY_SEQ]) { |
| 954 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 955 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 956 | } |
| 957 | |
| 958 | if (tb[NL80211_KEY_CIPHER]) |
| 959 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 960 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 961 | if (tb[NL80211_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 962 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 963 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 964 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 965 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 966 | |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 967 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 968 | tb[NL80211_KEY_DEFAULT_TYPES], |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 969 | nl80211_key_default_policy, |
| 970 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 971 | if (err) |
| 972 | return err; |
| 973 | |
| 974 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 975 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 976 | } |
| 977 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 978 | return 0; |
| 979 | } |
| 980 | |
| 981 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 982 | { |
| 983 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 984 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 985 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 986 | } |
| 987 | |
| 988 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 989 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 990 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 991 | } |
| 992 | |
| 993 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 994 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 995 | |
| 996 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 997 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 998 | |
| 999 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 1000 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 1001 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1002 | if (k->def) { |
| 1003 | k->def_uni = true; |
| 1004 | k->def_multi = true; |
| 1005 | } |
| 1006 | if (k->defmgmt) |
| 1007 | k->def_multi = true; |
| 1008 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1009 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1010 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1011 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1012 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 1013 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 1014 | int err = nla_parse_nested(kdt, |
| 1015 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1016 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 1017 | nl80211_key_default_policy, |
| 1018 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1019 | if (err) |
| 1020 | return err; |
| 1021 | |
| 1022 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1023 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1024 | } |
| 1025 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 1030 | { |
| 1031 | int err; |
| 1032 | |
| 1033 | memset(k, 0, sizeof(*k)); |
| 1034 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1035 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1036 | |
| 1037 | if (info->attrs[NL80211_ATTR_KEY]) |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1038 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1039 | else |
| 1040 | err = nl80211_parse_key_old(info, k); |
| 1041 | |
| 1042 | if (err) |
| 1043 | return err; |
| 1044 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1045 | if (k->def && k->defmgmt) { |
| 1046 | GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1047 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1048 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1049 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1050 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1051 | if (k->def_uni || !k->def_multi) { |
| 1052 | GENL_SET_ERR_MSG(info, "defmgmt key must be mcast"); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1053 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1054 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1057 | if (k->idx != -1) { |
| 1058 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1059 | if (k->idx < 4 || k->idx > 5) { |
| 1060 | GENL_SET_ERR_MSG(info, |
| 1061 | "defmgmt key idx not 4 or 5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1062 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1063 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1064 | } else if (k->def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1065 | if (k->idx < 0 || k->idx > 3) { |
| 1066 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1067 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1068 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1069 | } else { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1070 | if (k->idx < 0 || k->idx > 5) { |
| 1071 | GENL_SET_ERR_MSG(info, "key idx not 0-5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1072 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1073 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1080 | static struct cfg80211_cached_keys * |
| 1081 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1082 | struct genl_info *info, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1083 | { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1084 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1085 | struct key_parse parse; |
| 1086 | struct nlattr *key; |
| 1087 | struct cfg80211_cached_keys *result; |
| 1088 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1089 | bool have_key = false; |
| 1090 | |
| 1091 | nla_for_each_nested(key, keys, rem) { |
| 1092 | have_key = true; |
| 1093 | break; |
| 1094 | } |
| 1095 | |
| 1096 | if (!have_key) |
| 1097 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1098 | |
| 1099 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 1100 | if (!result) |
| 1101 | return ERR_PTR(-ENOMEM); |
| 1102 | |
| 1103 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1104 | |
| 1105 | nla_for_each_nested(key, keys, rem) { |
| 1106 | memset(&parse, 0, sizeof(parse)); |
| 1107 | parse.idx = -1; |
| 1108 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1109 | err = nl80211_parse_key_new(info, key, &parse); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1110 | if (err) |
| 1111 | goto error; |
| 1112 | err = -EINVAL; |
| 1113 | if (!parse.p.key) |
| 1114 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1115 | if (parse.idx < 0 || parse.idx > 3) { |
| 1116 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1117 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1118 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1119 | if (parse.def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1120 | if (def) { |
| 1121 | GENL_SET_ERR_MSG(info, |
| 1122 | "only one key can be default"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1123 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1124 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1125 | def = 1; |
| 1126 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1127 | if (!parse.def_uni || !parse.def_multi) |
| 1128 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1129 | } else if (parse.defmgmt) |
| 1130 | goto error; |
| 1131 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1132 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1133 | if (err) |
| 1134 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1135 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1136 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1137 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1138 | err = -EINVAL; |
| 1139 | goto error; |
| 1140 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1141 | result->params[parse.idx].cipher = parse.p.cipher; |
| 1142 | result->params[parse.idx].key_len = parse.p.key_len; |
| 1143 | result->params[parse.idx].key = result->data[parse.idx]; |
| 1144 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 1145 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1146 | /* must be WEP key if we got here */ |
| 1147 | if (no_ht) |
| 1148 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1149 | } |
| 1150 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1151 | if (result->def < 0) { |
| 1152 | err = -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1153 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1154 | goto error; |
| 1155 | } |
| 1156 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1157 | return result; |
| 1158 | error: |
| 1159 | kfree(result); |
| 1160 | return ERR_PTR(err); |
| 1161 | } |
| 1162 | |
| 1163 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 1164 | { |
| 1165 | ASSERT_WDEV_LOCK(wdev); |
| 1166 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1167 | switch (wdev->iftype) { |
| 1168 | case NL80211_IFTYPE_AP: |
| 1169 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1170 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 1171 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1172 | break; |
| 1173 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1174 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1175 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1176 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1177 | return -ENOLINK; |
| 1178 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1179 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 1180 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1181 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 1182 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1183 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1184 | case NL80211_IFTYPE_WDS: |
| 1185 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1186 | return -EINVAL; |
| 1187 | } |
| 1188 | |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1192 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 1193 | struct nlattr *tb) |
| 1194 | { |
| 1195 | struct ieee80211_channel *chan; |
| 1196 | |
| 1197 | if (tb == NULL) |
| 1198 | return NULL; |
| 1199 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 1200 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1201 | return NULL; |
| 1202 | return chan; |
| 1203 | } |
| 1204 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1205 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1206 | { |
| 1207 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 1208 | int i; |
| 1209 | |
| 1210 | if (!nl_modes) |
| 1211 | goto nla_put_failure; |
| 1212 | |
| 1213 | i = 0; |
| 1214 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1215 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1216 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1217 | ifmodes >>= 1; |
| 1218 | i++; |
| 1219 | } |
| 1220 | |
| 1221 | nla_nest_end(msg, nl_modes); |
| 1222 | return 0; |
| 1223 | |
| 1224 | nla_put_failure: |
| 1225 | return -ENOBUFS; |
| 1226 | } |
| 1227 | |
| 1228 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1229 | struct sk_buff *msg, |
| 1230 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1231 | { |
| 1232 | struct nlattr *nl_combis; |
| 1233 | int i, j; |
| 1234 | |
| 1235 | nl_combis = nla_nest_start(msg, |
| 1236 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 1237 | if (!nl_combis) |
| 1238 | goto nla_put_failure; |
| 1239 | |
| 1240 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1241 | const struct ieee80211_iface_combination *c; |
| 1242 | struct nlattr *nl_combi, *nl_limits; |
| 1243 | |
| 1244 | c = &wiphy->iface_combinations[i]; |
| 1245 | |
| 1246 | nl_combi = nla_nest_start(msg, i + 1); |
| 1247 | if (!nl_combi) |
| 1248 | goto nla_put_failure; |
| 1249 | |
| 1250 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 1251 | if (!nl_limits) |
| 1252 | goto nla_put_failure; |
| 1253 | |
| 1254 | for (j = 0; j < c->n_limits; j++) { |
| 1255 | struct nlattr *nl_limit; |
| 1256 | |
| 1257 | nl_limit = nla_nest_start(msg, j + 1); |
| 1258 | if (!nl_limit) |
| 1259 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1260 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1261 | c->limits[j].max)) |
| 1262 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1263 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1264 | c->limits[j].types)) |
| 1265 | goto nla_put_failure; |
| 1266 | nla_nest_end(msg, nl_limit); |
| 1267 | } |
| 1268 | |
| 1269 | nla_nest_end(msg, nl_limits); |
| 1270 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1271 | if (c->beacon_int_infra_match && |
| 1272 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1273 | goto nla_put_failure; |
| 1274 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1275 | c->num_different_channels) || |
| 1276 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1277 | c->max_interfaces)) |
| 1278 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1279 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1280 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1281 | c->radar_detect_widths) || |
| 1282 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1283 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1284 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1285 | if (c->beacon_int_min_gcd && |
| 1286 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1287 | c->beacon_int_min_gcd)) |
| 1288 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1289 | |
| 1290 | nla_nest_end(msg, nl_combi); |
| 1291 | } |
| 1292 | |
| 1293 | nla_nest_end(msg, nl_combis); |
| 1294 | |
| 1295 | return 0; |
| 1296 | nla_put_failure: |
| 1297 | return -ENOBUFS; |
| 1298 | } |
| 1299 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1300 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1301 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1302 | struct sk_buff *msg) |
| 1303 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1304 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1305 | struct nlattr *nl_tcp; |
| 1306 | |
| 1307 | if (!tcp) |
| 1308 | return 0; |
| 1309 | |
| 1310 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1311 | if (!nl_tcp) |
| 1312 | return -ENOBUFS; |
| 1313 | |
| 1314 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1315 | tcp->data_payload_max)) |
| 1316 | return -ENOBUFS; |
| 1317 | |
| 1318 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1319 | tcp->data_payload_max)) |
| 1320 | return -ENOBUFS; |
| 1321 | |
| 1322 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1323 | return -ENOBUFS; |
| 1324 | |
| 1325 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1326 | sizeof(*tcp->tok), tcp->tok)) |
| 1327 | return -ENOBUFS; |
| 1328 | |
| 1329 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1330 | tcp->data_interval_max)) |
| 1331 | return -ENOBUFS; |
| 1332 | |
| 1333 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1334 | tcp->wake_payload_max)) |
| 1335 | return -ENOBUFS; |
| 1336 | |
| 1337 | nla_nest_end(msg, nl_tcp); |
| 1338 | return 0; |
| 1339 | } |
| 1340 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1341 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1342 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1343 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1344 | { |
| 1345 | struct nlattr *nl_wowlan; |
| 1346 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1347 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1348 | return 0; |
| 1349 | |
| 1350 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1351 | if (!nl_wowlan) |
| 1352 | return -ENOBUFS; |
| 1353 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1354 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1355 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1356 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1358 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1359 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1360 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1361 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1362 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1363 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1364 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1365 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1366 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1368 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1369 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1370 | return -ENOBUFS; |
| 1371 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1372 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1373 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1374 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1375 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1376 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1377 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1378 | }; |
| 1379 | |
| 1380 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1381 | sizeof(pat), &pat)) |
| 1382 | return -ENOBUFS; |
| 1383 | } |
| 1384 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1385 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1386 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1387 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1388 | return -ENOBUFS; |
| 1389 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1390 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1391 | return -ENOBUFS; |
| 1392 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1393 | nla_nest_end(msg, nl_wowlan); |
| 1394 | |
| 1395 | return 0; |
| 1396 | } |
| 1397 | #endif |
| 1398 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1399 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1400 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1401 | { |
| 1402 | struct nl80211_coalesce_rule_support rule; |
| 1403 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1404 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1405 | return 0; |
| 1406 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1407 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1408 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1409 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1410 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1411 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1412 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1413 | |
| 1414 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1415 | return -ENOBUFS; |
| 1416 | |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1420 | static int |
| 1421 | nl80211_send_iftype_data(struct sk_buff *msg, |
| 1422 | const struct ieee80211_sband_iftype_data *iftdata) |
| 1423 | { |
| 1424 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; |
| 1425 | |
| 1426 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, |
| 1427 | iftdata->types_mask)) |
| 1428 | return -ENOBUFS; |
| 1429 | |
| 1430 | if (he_cap->has_he) { |
| 1431 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, |
| 1432 | sizeof(he_cap->he_cap_elem.mac_cap_info), |
| 1433 | he_cap->he_cap_elem.mac_cap_info) || |
| 1434 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, |
| 1435 | sizeof(he_cap->he_cap_elem.phy_cap_info), |
| 1436 | he_cap->he_cap_elem.phy_cap_info) || |
| 1437 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, |
| 1438 | sizeof(he_cap->he_mcs_nss_supp), |
| 1439 | &he_cap->he_mcs_nss_supp) || |
| 1440 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, |
| 1441 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) |
| 1442 | return -ENOBUFS; |
| 1443 | } |
| 1444 | |
| 1445 | return 0; |
| 1446 | } |
| 1447 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1448 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1449 | struct ieee80211_supported_band *sband) |
| 1450 | { |
| 1451 | struct nlattr *nl_rates, *nl_rate; |
| 1452 | struct ieee80211_rate *rate; |
| 1453 | int i; |
| 1454 | |
| 1455 | /* add HT info */ |
| 1456 | if (sband->ht_cap.ht_supported && |
| 1457 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1458 | sizeof(sband->ht_cap.mcs), |
| 1459 | &sband->ht_cap.mcs) || |
| 1460 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1461 | sband->ht_cap.cap) || |
| 1462 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1463 | sband->ht_cap.ampdu_factor) || |
| 1464 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1465 | sband->ht_cap.ampdu_density))) |
| 1466 | return -ENOBUFS; |
| 1467 | |
| 1468 | /* add VHT info */ |
| 1469 | if (sband->vht_cap.vht_supported && |
| 1470 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1471 | sizeof(sband->vht_cap.vht_mcs), |
| 1472 | &sband->vht_cap.vht_mcs) || |
| 1473 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1474 | sband->vht_cap.cap))) |
| 1475 | return -ENOBUFS; |
| 1476 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1477 | if (sband->n_iftype_data) { |
| 1478 | struct nlattr *nl_iftype_data = |
| 1479 | nla_nest_start(msg, NL80211_BAND_ATTR_IFTYPE_DATA); |
| 1480 | int err; |
| 1481 | |
| 1482 | if (!nl_iftype_data) |
| 1483 | return -ENOBUFS; |
| 1484 | |
| 1485 | for (i = 0; i < sband->n_iftype_data; i++) { |
| 1486 | struct nlattr *iftdata; |
| 1487 | |
| 1488 | iftdata = nla_nest_start(msg, i + 1); |
| 1489 | if (!iftdata) |
| 1490 | return -ENOBUFS; |
| 1491 | |
| 1492 | err = nl80211_send_iftype_data(msg, |
| 1493 | &sband->iftype_data[i]); |
| 1494 | if (err) |
| 1495 | return err; |
| 1496 | |
| 1497 | nla_nest_end(msg, iftdata); |
| 1498 | } |
| 1499 | |
| 1500 | nla_nest_end(msg, nl_iftype_data); |
| 1501 | } |
| 1502 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | /* add bitrates */ |
| 1504 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1505 | if (!nl_rates) |
| 1506 | return -ENOBUFS; |
| 1507 | |
| 1508 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1509 | nl_rate = nla_nest_start(msg, i); |
| 1510 | if (!nl_rate) |
| 1511 | return -ENOBUFS; |
| 1512 | |
| 1513 | rate = &sband->bitrates[i]; |
| 1514 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1515 | rate->bitrate)) |
| 1516 | return -ENOBUFS; |
| 1517 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1518 | nla_put_flag(msg, |
| 1519 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1520 | return -ENOBUFS; |
| 1521 | |
| 1522 | nla_nest_end(msg, nl_rate); |
| 1523 | } |
| 1524 | |
| 1525 | nla_nest_end(msg, nl_rates); |
| 1526 | |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | static int |
| 1531 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1532 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1533 | { |
| 1534 | u16 stypes; |
| 1535 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1536 | enum nl80211_iftype ift; |
| 1537 | int i; |
| 1538 | |
| 1539 | if (!mgmt_stypes) |
| 1540 | return 0; |
| 1541 | |
| 1542 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1543 | if (!nl_ifs) |
| 1544 | return -ENOBUFS; |
| 1545 | |
| 1546 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1547 | nl_ftypes = nla_nest_start(msg, ift); |
| 1548 | if (!nl_ftypes) |
| 1549 | return -ENOBUFS; |
| 1550 | i = 0; |
| 1551 | stypes = mgmt_stypes[ift].tx; |
| 1552 | while (stypes) { |
| 1553 | if ((stypes & 1) && |
| 1554 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1555 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1556 | return -ENOBUFS; |
| 1557 | stypes >>= 1; |
| 1558 | i++; |
| 1559 | } |
| 1560 | nla_nest_end(msg, nl_ftypes); |
| 1561 | } |
| 1562 | |
| 1563 | nla_nest_end(msg, nl_ifs); |
| 1564 | |
| 1565 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1566 | if (!nl_ifs) |
| 1567 | return -ENOBUFS; |
| 1568 | |
| 1569 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1570 | nl_ftypes = nla_nest_start(msg, ift); |
| 1571 | if (!nl_ftypes) |
| 1572 | return -ENOBUFS; |
| 1573 | i = 0; |
| 1574 | stypes = mgmt_stypes[ift].rx; |
| 1575 | while (stypes) { |
| 1576 | if ((stypes & 1) && |
| 1577 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1578 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1579 | return -ENOBUFS; |
| 1580 | stypes >>= 1; |
| 1581 | i++; |
| 1582 | } |
| 1583 | nla_nest_end(msg, nl_ftypes); |
| 1584 | } |
| 1585 | nla_nest_end(msg, nl_ifs); |
| 1586 | |
| 1587 | return 0; |
| 1588 | } |
| 1589 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1590 | #define CMD(op, n) \ |
| 1591 | do { \ |
| 1592 | if (rdev->ops->op) { \ |
| 1593 | i++; \ |
| 1594 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1595 | goto nla_put_failure; \ |
| 1596 | } \ |
| 1597 | } while (0) |
| 1598 | |
| 1599 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1600 | struct sk_buff *msg) |
| 1601 | { |
| 1602 | int i = 0; |
| 1603 | |
| 1604 | /* |
| 1605 | * do *NOT* add anything into this function, new things need to be |
| 1606 | * advertised only to new versions of userspace that can deal with |
| 1607 | * the split (and they can't possibly care about new features... |
| 1608 | */ |
| 1609 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1610 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1611 | CMD(add_key, NEW_KEY); |
| 1612 | CMD(start_ap, START_AP); |
| 1613 | CMD(add_station, NEW_STATION); |
| 1614 | CMD(add_mpath, NEW_MPATH); |
| 1615 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1616 | CMD(change_bss, SET_BSS); |
| 1617 | CMD(auth, AUTHENTICATE); |
| 1618 | CMD(assoc, ASSOCIATE); |
| 1619 | CMD(deauth, DEAUTHENTICATE); |
| 1620 | CMD(disassoc, DISASSOCIATE); |
| 1621 | CMD(join_ibss, JOIN_IBSS); |
| 1622 | CMD(join_mesh, JOIN_MESH); |
| 1623 | CMD(set_pmksa, SET_PMKSA); |
| 1624 | CMD(del_pmksa, DEL_PMKSA); |
| 1625 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1626 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1627 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1628 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1629 | CMD(mgmt_tx, FRAME); |
| 1630 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1631 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1632 | i++; |
| 1633 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1634 | goto nla_put_failure; |
| 1635 | } |
| 1636 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1637 | rdev->ops->join_mesh) { |
| 1638 | i++; |
| 1639 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1640 | goto nla_put_failure; |
| 1641 | } |
| 1642 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1643 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1644 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1645 | CMD(tdls_oper, TDLS_OPER); |
| 1646 | } |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1647 | if (rdev->wiphy.max_sched_scan_reqs) |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1648 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1649 | CMD(probe_client, PROBE_CLIENT); |
| 1650 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1651 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1652 | i++; |
| 1653 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1654 | goto nla_put_failure; |
| 1655 | } |
| 1656 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1657 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1658 | #ifdef CONFIG_NL80211_TESTMODE |
| 1659 | CMD(testmode_cmd, TESTMODE); |
| 1660 | #endif |
| 1661 | |
| 1662 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1663 | i++; |
| 1664 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1665 | goto nla_put_failure; |
| 1666 | } |
| 1667 | |
| 1668 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1669 | i++; |
| 1670 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1671 | goto nla_put_failure; |
| 1672 | } |
| 1673 | |
| 1674 | return i; |
| 1675 | nla_put_failure: |
| 1676 | return -ENOBUFS; |
| 1677 | } |
| 1678 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1679 | static int |
| 1680 | nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, |
| 1681 | struct sk_buff *msg) |
| 1682 | { |
| 1683 | struct nlattr *ftm; |
| 1684 | |
| 1685 | if (!cap->ftm.supported) |
| 1686 | return 0; |
| 1687 | |
| 1688 | ftm = nla_nest_start(msg, NL80211_PMSR_TYPE_FTM); |
| 1689 | if (!ftm) |
| 1690 | return -ENOBUFS; |
| 1691 | |
| 1692 | if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) |
| 1693 | return -ENOBUFS; |
| 1694 | if (cap->ftm.non_asap && |
| 1695 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) |
| 1696 | return -ENOBUFS; |
| 1697 | if (cap->ftm.request_lci && |
| 1698 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) |
| 1699 | return -ENOBUFS; |
| 1700 | if (cap->ftm.request_civicloc && |
| 1701 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) |
| 1702 | return -ENOBUFS; |
| 1703 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, |
| 1704 | cap->ftm.preambles)) |
| 1705 | return -ENOBUFS; |
| 1706 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, |
| 1707 | cap->ftm.bandwidths)) |
| 1708 | return -ENOBUFS; |
| 1709 | if (cap->ftm.max_bursts_exponent >= 0 && |
| 1710 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, |
| 1711 | cap->ftm.max_bursts_exponent)) |
| 1712 | return -ENOBUFS; |
| 1713 | if (cap->ftm.max_ftms_per_burst && |
| 1714 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, |
| 1715 | cap->ftm.max_ftms_per_burst)) |
| 1716 | return -ENOBUFS; |
| 1717 | |
| 1718 | nla_nest_end(msg, ftm); |
| 1719 | return 0; |
| 1720 | } |
| 1721 | |
| 1722 | static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, |
| 1723 | struct sk_buff *msg) |
| 1724 | { |
| 1725 | const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; |
| 1726 | struct nlattr *pmsr, *caps; |
| 1727 | |
| 1728 | if (!cap) |
| 1729 | return 0; |
| 1730 | |
| 1731 | /* |
| 1732 | * we don't need to clean up anything here since the caller |
| 1733 | * will genlmsg_cancel() if we fail |
| 1734 | */ |
| 1735 | |
| 1736 | pmsr = nla_nest_start(msg, NL80211_ATTR_PEER_MEASUREMENTS); |
| 1737 | if (!pmsr) |
| 1738 | return -ENOBUFS; |
| 1739 | |
| 1740 | if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) |
| 1741 | return -ENOBUFS; |
| 1742 | |
| 1743 | if (cap->report_ap_tsf && |
| 1744 | nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) |
| 1745 | return -ENOBUFS; |
| 1746 | |
| 1747 | if (cap->randomize_mac_addr && |
| 1748 | nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) |
| 1749 | return -ENOBUFS; |
| 1750 | |
| 1751 | caps = nla_nest_start(msg, NL80211_PMSR_ATTR_TYPE_CAPA); |
| 1752 | if (!caps) |
| 1753 | return -ENOBUFS; |
| 1754 | |
| 1755 | if (nl80211_send_pmsr_ftm_capa(cap, msg)) |
| 1756 | return -ENOBUFS; |
| 1757 | |
| 1758 | nla_nest_end(msg, caps); |
| 1759 | nla_nest_end(msg, pmsr); |
| 1760 | |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1764 | struct nl80211_dump_wiphy_state { |
| 1765 | s64 filter_wiphy; |
| 1766 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1767 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1768 | bool split; |
| 1769 | }; |
| 1770 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1771 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1772 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1773 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1774 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1775 | { |
| 1776 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1777 | struct nlattr *nl_bands, *nl_band; |
| 1778 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1779 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1780 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1781 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1782 | int i; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1783 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1784 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1785 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1786 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1787 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1788 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1789 | return -ENOBUFS; |
| 1790 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1791 | if (WARN_ON(!state)) |
| 1792 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1793 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1794 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1795 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1796 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1797 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1798 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1799 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1800 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1801 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1802 | goto finish; |
| 1803 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1804 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1805 | case 0: |
| 1806 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1807 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1808 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1809 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1810 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1811 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1812 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1813 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1814 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1815 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1816 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1817 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1818 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1819 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1820 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1821 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1822 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1823 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1824 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1825 | rdev->wiphy.max_match_sets) || |
| 1826 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1827 | rdev->wiphy.max_sched_scan_plans) || |
| 1828 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1829 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1830 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1831 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1832 | goto nla_put_failure; |
| 1833 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1834 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1835 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1836 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1837 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1838 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1839 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1840 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1841 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1842 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1843 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1844 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1845 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1846 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1847 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1848 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1849 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1850 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1851 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1852 | state->split_start++; |
| 1853 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1854 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 1855 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1856 | case 1: |
| 1857 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1858 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1859 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1860 | goto nla_put_failure; |
| 1861 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1862 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1863 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1864 | goto nla_put_failure; |
| 1865 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1866 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1867 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1868 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1869 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1870 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1871 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1872 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1873 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1874 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1875 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1876 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1877 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1878 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1879 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1880 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1881 | if ((rdev->wiphy.available_antennas_tx || |
| 1882 | rdev->wiphy.available_antennas_rx) && |
| 1883 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1884 | u32 tx_ant = 0, rx_ant = 0; |
| 1885 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1886 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1887 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1888 | if (!res) { |
| 1889 | if (nla_put_u32(msg, |
| 1890 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1891 | tx_ant) || |
| 1892 | nla_put_u32(msg, |
| 1893 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1894 | rx_ant)) |
| 1895 | goto nla_put_failure; |
| 1896 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1897 | } |
| 1898 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1899 | state->split_start++; |
| 1900 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1901 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 1902 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1903 | case 2: |
| 1904 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1905 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1906 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1907 | state->split_start++; |
| 1908 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1909 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 1910 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1911 | case 3: |
| 1912 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1913 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1914 | goto nla_put_failure; |
| 1915 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1916 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1917 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1918 | struct ieee80211_supported_band *sband; |
| 1919 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1920 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1921 | |
| 1922 | if (!sband) |
| 1923 | continue; |
| 1924 | |
| 1925 | nl_band = nla_nest_start(msg, band); |
| 1926 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1927 | goto nla_put_failure; |
| 1928 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1929 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1930 | case 0: |
| 1931 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1932 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1933 | state->chan_start++; |
| 1934 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1935 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 1936 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1937 | default: |
| 1938 | /* add frequencies */ |
| 1939 | nl_freqs = nla_nest_start( |
| 1940 | msg, NL80211_BAND_ATTR_FREQS); |
| 1941 | if (!nl_freqs) |
| 1942 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1943 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1944 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1945 | i < sband->n_channels; |
| 1946 | i++) { |
| 1947 | nl_freq = nla_nest_start(msg, i); |
| 1948 | if (!nl_freq) |
| 1949 | goto nla_put_failure; |
| 1950 | |
| 1951 | chan = &sband->channels[i]; |
| 1952 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1953 | if (nl80211_msg_put_channel( |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1954 | msg, &rdev->wiphy, chan, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1955 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1956 | goto nla_put_failure; |
| 1957 | |
| 1958 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1959 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1960 | break; |
| 1961 | } |
| 1962 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1963 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1964 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1965 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1966 | nla_nest_end(msg, nl_freqs); |
| 1967 | } |
| 1968 | |
| 1969 | nla_nest_end(msg, nl_band); |
| 1970 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1971 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1972 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1973 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1974 | band--; |
| 1975 | break; |
| 1976 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1977 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1978 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1979 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1980 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1981 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1982 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1983 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1984 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1985 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1986 | if (state->band_start == 0 && state->chan_start == 0) |
| 1987 | state->split_start++; |
| 1988 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1989 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 1990 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1991 | case 4: |
| 1992 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1993 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1994 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1995 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1996 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 1997 | if (i < 0) |
| 1998 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1999 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2000 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 2001 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2002 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 2003 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 2004 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 2005 | if (rdev->wiphy.features & |
| 2006 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 2007 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 2008 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 2009 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2010 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2011 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 2012 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2013 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2014 | state->split_start++; |
| 2015 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2016 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2017 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2018 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2019 | if (rdev->ops->remain_on_channel && |
| 2020 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2021 | nla_put_u32(msg, |
| 2022 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2023 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2024 | goto nla_put_failure; |
| 2025 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2026 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2027 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 2028 | goto nla_put_failure; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2029 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2030 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 2031 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2032 | state->split_start++; |
| 2033 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2034 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2035 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2036 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 2037 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2038 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2039 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2040 | state->split_start++; |
| 2041 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2042 | break; |
| 2043 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2044 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2045 | #endif |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2046 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2047 | case 7: |
| 2048 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2049 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2050 | goto nla_put_failure; |
| 2051 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2052 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2053 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2054 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2055 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2056 | state->split_start++; |
| 2057 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2058 | break; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 2059 | /* fall through */ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2060 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2061 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2062 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2063 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2064 | goto nla_put_failure; |
| 2065 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2066 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2067 | /* |
| 2068 | * We can only add the per-channel limit information if the |
| 2069 | * dump is split, otherwise it makes it too big. Therefore |
| 2070 | * only advertise it in that case. |
| 2071 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2072 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2073 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 2074 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2075 | goto nla_put_failure; |
| 2076 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2077 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2078 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2079 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 2080 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2081 | goto nla_put_failure; |
| 2082 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2083 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 2084 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2085 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2086 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2087 | goto nla_put_failure; |
| 2088 | |
| 2089 | /* |
| 2090 | * Any information below this point is only available to |
| 2091 | * applications that can deal with it being split. This |
| 2092 | * helps ensure that newly added capabilities don't break |
| 2093 | * older tools by overrunning their buffers. |
| 2094 | * |
| 2095 | * We still increment split_start so that in the split |
| 2096 | * case we'll continue with more data in the next round, |
| 2097 | * but break unconditionally so unsplit data stops here. |
| 2098 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2099 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2100 | break; |
| 2101 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2102 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2103 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2104 | rdev->wiphy.extended_capabilities_len, |
| 2105 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2106 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2107 | rdev->wiphy.extended_capabilities_len, |
| 2108 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2109 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2110 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2111 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2112 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2113 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 2114 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2115 | goto nla_put_failure; |
| 2116 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2117 | state->split_start++; |
| 2118 | break; |
| 2119 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2120 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2121 | goto nla_put_failure; |
| 2122 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2123 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2124 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 2125 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 2126 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2127 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2128 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2129 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2130 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2131 | goto nla_put_failure; |
| 2132 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2133 | state->split_start++; |
| 2134 | break; |
| 2135 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2136 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2137 | const struct nl80211_vendor_cmd_info *info; |
| 2138 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2139 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2140 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 2141 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2142 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2143 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2144 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 2145 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2146 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2147 | goto nla_put_failure; |
| 2148 | } |
| 2149 | nla_nest_end(msg, nested); |
| 2150 | } |
| 2151 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2152 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2153 | const struct nl80211_vendor_cmd_info *info; |
| 2154 | struct nlattr *nested; |
| 2155 | |
| 2156 | nested = nla_nest_start(msg, |
| 2157 | NL80211_ATTR_VENDOR_EVENTS); |
| 2158 | if (!nested) |
| 2159 | goto nla_put_failure; |
| 2160 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2161 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 2162 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2163 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2164 | goto nla_put_failure; |
| 2165 | } |
| 2166 | nla_nest_end(msg, nested); |
| 2167 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 2168 | state->split_start++; |
| 2169 | break; |
| 2170 | case 12: |
| 2171 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 2172 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 2173 | rdev->wiphy.max_num_csa_counters)) |
| 2174 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2175 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 2176 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 2177 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 2178 | goto nla_put_failure; |
| 2179 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 2180 | if (rdev->wiphy.max_sched_scan_reqs && |
| 2181 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, |
| 2182 | rdev->wiphy.max_sched_scan_reqs)) |
| 2183 | goto nla_put_failure; |
| 2184 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 2185 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 2186 | sizeof(rdev->wiphy.ext_features), |
| 2187 | rdev->wiphy.ext_features)) |
| 2188 | goto nla_put_failure; |
| 2189 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2190 | if (rdev->wiphy.bss_select_support) { |
| 2191 | struct nlattr *nested; |
| 2192 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 2193 | |
| 2194 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 2195 | if (!nested) |
| 2196 | goto nla_put_failure; |
| 2197 | |
| 2198 | i = 0; |
| 2199 | while (bss_select_support) { |
| 2200 | if ((bss_select_support & 1) && |
| 2201 | nla_put_flag(msg, i)) |
| 2202 | goto nla_put_failure; |
| 2203 | i++; |
| 2204 | bss_select_support >>= 1; |
| 2205 | } |
| 2206 | nla_nest_end(msg, nested); |
| 2207 | } |
| 2208 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2209 | state->split_start++; |
| 2210 | break; |
| 2211 | case 13: |
| 2212 | if (rdev->wiphy.num_iftype_ext_capab && |
| 2213 | rdev->wiphy.iftype_ext_capab) { |
| 2214 | struct nlattr *nested_ext_capab, *nested; |
| 2215 | |
| 2216 | nested = nla_nest_start(msg, |
| 2217 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 2218 | if (!nested) |
| 2219 | goto nla_put_failure; |
| 2220 | |
| 2221 | for (i = state->capa_start; |
| 2222 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 2223 | const struct wiphy_iftype_ext_capab *capab; |
| 2224 | |
| 2225 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 2226 | |
| 2227 | nested_ext_capab = nla_nest_start(msg, i); |
| 2228 | if (!nested_ext_capab || |
| 2229 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 2230 | capab->iftype) || |
| 2231 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 2232 | capab->extended_capabilities_len, |
| 2233 | capab->extended_capabilities) || |
| 2234 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 2235 | capab->extended_capabilities_len, |
| 2236 | capab->extended_capabilities_mask)) |
| 2237 | goto nla_put_failure; |
| 2238 | |
| 2239 | nla_nest_end(msg, nested_ext_capab); |
| 2240 | if (state->split) |
| 2241 | break; |
| 2242 | } |
| 2243 | nla_nest_end(msg, nested); |
| 2244 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 2245 | state->capa_start = i + 1; |
| 2246 | break; |
| 2247 | } |
| 2248 | } |
| 2249 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 2250 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 2251 | rdev->wiphy.nan_supported_bands)) |
| 2252 | goto nla_put_failure; |
| 2253 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2254 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 2255 | NL80211_EXT_FEATURE_TXQS)) { |
| 2256 | struct cfg80211_txq_stats txqstats = {}; |
| 2257 | int res; |
| 2258 | |
| 2259 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); |
| 2260 | if (!res && |
| 2261 | !nl80211_put_txq_stats(msg, &txqstats, |
| 2262 | NL80211_ATTR_TXQ_STATS)) |
| 2263 | goto nla_put_failure; |
| 2264 | |
| 2265 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, |
| 2266 | rdev->wiphy.txq_limit)) |
| 2267 | goto nla_put_failure; |
| 2268 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, |
| 2269 | rdev->wiphy.txq_memory_limit)) |
| 2270 | goto nla_put_failure; |
| 2271 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, |
| 2272 | rdev->wiphy.txq_quantum)) |
| 2273 | goto nla_put_failure; |
| 2274 | } |
| 2275 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2276 | state->split_start++; |
| 2277 | break; |
| 2278 | case 14: |
| 2279 | if (nl80211_send_pmsr_capa(rdev, msg)) |
| 2280 | goto nla_put_failure; |
| 2281 | |
Veerendranath Jakkam | ab4dfa2 | 2018-12-19 22:52:25 +0530 | [diff] [blame] | 2282 | state->split_start++; |
| 2283 | break; |
| 2284 | case 15: |
| 2285 | if (rdev->wiphy.akm_suites && |
| 2286 | nla_put(msg, NL80211_ATTR_AKM_SUITES, |
| 2287 | sizeof(u32) * rdev->wiphy.n_akm_suites, |
| 2288 | rdev->wiphy.akm_suites)) |
| 2289 | goto nla_put_failure; |
| 2290 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2291 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2292 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2293 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2294 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2295 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2296 | genlmsg_end(msg, hdr); |
| 2297 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2298 | |
| 2299 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2300 | genlmsg_cancel(msg, hdr); |
| 2301 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2302 | } |
| 2303 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2304 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 2305 | struct netlink_callback *cb, |
| 2306 | struct nl80211_dump_wiphy_state *state) |
| 2307 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 2308 | struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 2309 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb, |
| 2310 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2311 | /* ignore parse errors for backward compatibility */ |
| 2312 | if (ret) |
| 2313 | return 0; |
| 2314 | |
| 2315 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 2316 | if (tb[NL80211_ATTR_WIPHY]) |
| 2317 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 2318 | if (tb[NL80211_ATTR_WDEV]) |
| 2319 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 2320 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 2321 | struct net_device *netdev; |
| 2322 | struct cfg80211_registered_device *rdev; |
| 2323 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 2324 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2325 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2326 | if (!netdev) |
| 2327 | return -ENODEV; |
| 2328 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2329 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2330 | netdev->ieee80211_ptr->wiphy); |
| 2331 | state->filter_wiphy = rdev->wiphy_idx; |
| 2332 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | return 0; |
| 2336 | } |
| 2337 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2338 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 2339 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2340 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2341 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2342 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 2343 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2344 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2345 | if (!state) { |
| 2346 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 2347 | if (!state) { |
| 2348 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2349 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2350 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2351 | state->filter_wiphy = -1; |
| 2352 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 2353 | if (ret) { |
| 2354 | kfree(state); |
| 2355 | rtnl_unlock(); |
| 2356 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2357 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2358 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2359 | } |
| 2360 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2361 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2362 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2363 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2364 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2365 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2366 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2367 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2368 | continue; |
| 2369 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 2370 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2371 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 2372 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2373 | NETLINK_CB(cb->skb).portid, |
| 2374 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2375 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2376 | if (ret < 0) { |
| 2377 | /* |
| 2378 | * If sending the wiphy data didn't fit (ENOBUFS |
| 2379 | * or EMSGSIZE returned), this SKB is still |
| 2380 | * empty (so it's not too big because another |
| 2381 | * wiphy dataset is already in the skb) and |
| 2382 | * we've not tried to adjust the dump allocation |
| 2383 | * yet ... then adjust the alloc size to be |
| 2384 | * bigger, and return 1 but with the empty skb. |
| 2385 | * This results in an empty message being RX'ed |
| 2386 | * in userspace, but that is ignored. |
| 2387 | * |
| 2388 | * We can then retry with the larger buffer. |
| 2389 | */ |
| 2390 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2391 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2392 | cb->min_dump_alloc < 4096) { |
| 2393 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2394 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 2395 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2396 | return 1; |
| 2397 | } |
| 2398 | idx--; |
| 2399 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2400 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2401 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2402 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2403 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2404 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2405 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2406 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2407 | |
| 2408 | return skb->len; |
| 2409 | } |
| 2410 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2411 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2412 | { |
| 2413 | kfree((void *)cb->args[0]); |
| 2414 | return 0; |
| 2415 | } |
| 2416 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2417 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2418 | { |
| 2419 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2421 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2422 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2423 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2424 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2425 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2426 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2427 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2428 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2429 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2430 | nlmsg_free(msg); |
| 2431 | return -ENOBUFS; |
| 2432 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2433 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2434 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2435 | } |
| 2436 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2437 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2438 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2439 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2440 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2441 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2442 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2443 | }; |
| 2444 | |
| 2445 | static int parse_txq_params(struct nlattr *tb[], |
| 2446 | struct ieee80211_txq_params *txq_params) |
| 2447 | { |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2448 | u8 ac; |
| 2449 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2450 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2451 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2452 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2453 | return -EINVAL; |
| 2454 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2455 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2456 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2457 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2458 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2459 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2460 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2461 | if (ac >= NL80211_NUM_ACS) |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2462 | return -EINVAL; |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2463 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2464 | return 0; |
| 2465 | } |
| 2466 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2467 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2468 | { |
| 2469 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2470 | * You can only set the channel explicitly for WDS interfaces, |
| 2471 | * all others have their channel managed via their respective |
| 2472 | * "establish a connection" command (connect, join, ...) |
| 2473 | * |
| 2474 | * For AP/GO and mesh mode, the channel can be set with the |
| 2475 | * channel userspace API, but is only stored and passed to the |
| 2476 | * low-level driver when the AP starts or the mesh is joined. |
| 2477 | * This is for backward compatibility, userspace can also give |
| 2478 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2479 | * |
| 2480 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2481 | * whatever else is going on, so they have their own special |
| 2482 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2483 | */ |
| 2484 | return !wdev || |
| 2485 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2486 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2487 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2488 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2489 | } |
| 2490 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2491 | int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2492 | struct genl_info *info, |
| 2493 | struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2494 | { |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2495 | struct netlink_ext_ack *extack = info->extack; |
| 2496 | struct nlattr **attrs = info->attrs; |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2497 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2498 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2499 | if (!attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2500 | return -EINVAL; |
| 2501 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2502 | control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2503 | |
| 2504 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2505 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2506 | chandef->center_freq1 = control_freq; |
| 2507 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2508 | |
| 2509 | /* Primary channel not allowed */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2510 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { |
| 2511 | NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], |
| 2512 | "Channel is disabled"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2513 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2514 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2515 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2516 | if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2517 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2518 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2519 | chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2520 | |
| 2521 | switch (chantype) { |
| 2522 | case NL80211_CHAN_NO_HT: |
| 2523 | case NL80211_CHAN_HT20: |
| 2524 | case NL80211_CHAN_HT40PLUS: |
| 2525 | case NL80211_CHAN_HT40MINUS: |
| 2526 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2527 | chantype); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2528 | /* user input for center_freq is incorrect */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2529 | if (attrs[NL80211_ATTR_CENTER_FREQ1] && |
| 2530 | chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { |
| 2531 | NL_SET_ERR_MSG_ATTR(extack, |
| 2532 | attrs[NL80211_ATTR_CENTER_FREQ1], |
| 2533 | "bad center frequency 1"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2534 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2535 | } |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2536 | /* center_freq2 must be zero */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2537 | if (attrs[NL80211_ATTR_CENTER_FREQ2] && |
| 2538 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { |
| 2539 | NL_SET_ERR_MSG_ATTR(extack, |
| 2540 | attrs[NL80211_ATTR_CENTER_FREQ2], |
| 2541 | "center frequency 2 can't be used"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2542 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2543 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2544 | break; |
| 2545 | default: |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2546 | NL_SET_ERR_MSG_ATTR(extack, |
| 2547 | attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], |
| 2548 | "invalid channel type"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2549 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2550 | } |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2551 | } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2552 | chandef->width = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2553 | nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2554 | if (attrs[NL80211_ATTR_CENTER_FREQ1]) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2555 | chandef->center_freq1 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2556 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2557 | if (attrs[NL80211_ATTR_CENTER_FREQ2]) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2558 | chandef->center_freq2 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2559 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2560 | } |
| 2561 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2562 | if (!cfg80211_chandef_valid(chandef)) { |
| 2563 | NL_SET_ERR_MSG(extack, "invalid channel definition"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2564 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2565 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2566 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2567 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2568 | IEEE80211_CHAN_DISABLED)) { |
| 2569 | NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2570 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2571 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2572 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2573 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2574 | chandef->width == NL80211_CHAN_WIDTH_10) && |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2575 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { |
| 2576 | NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2577 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2578 | } |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2579 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2580 | return 0; |
| 2581 | } |
| 2582 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2583 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2584 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2585 | struct genl_info *info) |
| 2586 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2587 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2588 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2589 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2590 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2591 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2592 | if (dev) |
| 2593 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2594 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2595 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2596 | if (wdev) |
| 2597 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2598 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2599 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2600 | if (result) |
| 2601 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2602 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2603 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2604 | case NL80211_IFTYPE_AP: |
| 2605 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2606 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2607 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2608 | result = -EINVAL; |
| 2609 | break; |
| 2610 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2611 | if (wdev->beacon_interval) { |
| 2612 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2613 | !(rdev->wiphy.features & |
| 2614 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2615 | result = -EBUSY; |
| 2616 | break; |
| 2617 | } |
| 2618 | |
| 2619 | /* Only allow dynamic channel width changes */ |
| 2620 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2621 | result = -EBUSY; |
| 2622 | break; |
| 2623 | } |
| 2624 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2625 | if (result) |
| 2626 | break; |
| 2627 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2628 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2629 | result = 0; |
| 2630 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2631 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2632 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2633 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2634 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2635 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2636 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2637 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2638 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2639 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2640 | |
| 2641 | return result; |
| 2642 | } |
| 2643 | |
| 2644 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2645 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2646 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2647 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2648 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2649 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2650 | } |
| 2651 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2652 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2653 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2654 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2655 | struct net_device *dev = info->user_ptr[1]; |
| 2656 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2657 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2658 | |
| 2659 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2660 | return -EINVAL; |
| 2661 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2662 | if (netif_running(dev)) |
| 2663 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2664 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2665 | if (!rdev->ops->set_wds_peer) |
| 2666 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2667 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2668 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2669 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2670 | |
| 2671 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2672 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2673 | } |
| 2674 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2675 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2676 | { |
| 2677 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2678 | struct net_device *netdev = NULL; |
| 2679 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2680 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2681 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2682 | u32 changed; |
| 2683 | u8 retry_short = 0, retry_long = 0; |
| 2684 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2685 | u8 coverage_class = 0; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2686 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2687 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2688 | ASSERT_RTNL(); |
| 2689 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2690 | /* |
| 2691 | * Try to find the wiphy and netdev. Normally this |
| 2692 | * function shouldn't need the netdev, but this is |
| 2693 | * done for backward compatibility -- previously |
| 2694 | * setting the channel was done per wiphy, but now |
| 2695 | * it is per netdev. Previous userland like hostapd |
| 2696 | * also passed a netdev to set_wiphy, so that it is |
| 2697 | * possible to let that go to the right netdev! |
| 2698 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2699 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2700 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2701 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2702 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2703 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2704 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2705 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2706 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2707 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2708 | } |
| 2709 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2710 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2711 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2712 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2713 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2714 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2715 | wdev = NULL; |
| 2716 | netdev = NULL; |
| 2717 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2718 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2719 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2720 | |
| 2721 | /* |
| 2722 | * end workaround code, by now the rdev is available |
| 2723 | * and locked, and wdev may or may not be NULL. |
| 2724 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2725 | |
| 2726 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2727 | result = cfg80211_dev_rename( |
| 2728 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2729 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2730 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2731 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2732 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2733 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2734 | struct ieee80211_txq_params txq_params; |
| 2735 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2736 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2737 | if (!rdev->ops->set_txq_params) |
| 2738 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2739 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2740 | if (!netdev) |
| 2741 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2742 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2743 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2744 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2745 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2746 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2747 | if (!netif_running(netdev)) |
| 2748 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2749 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2750 | nla_for_each_nested(nl_txq_params, |
| 2751 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2752 | rem_txq_params) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 2753 | result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX, |
| 2754 | nl_txq_params, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 2755 | txq_params_policy, |
| 2756 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2757 | if (result) |
| 2758 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2759 | result = parse_txq_params(tb, &txq_params); |
| 2760 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2761 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2762 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2763 | result = rdev_set_txq_params(rdev, netdev, |
| 2764 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2765 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2766 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2767 | } |
| 2768 | } |
| 2769 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2770 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2771 | result = __nl80211_set_channel( |
| 2772 | rdev, |
| 2773 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2774 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2775 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2776 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2777 | } |
| 2778 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2779 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2780 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2781 | enum nl80211_tx_power_setting type; |
| 2782 | int idx, mbm = 0; |
| 2783 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2784 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2785 | txp_wdev = NULL; |
| 2786 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2787 | if (!rdev->ops->set_tx_power) |
| 2788 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2789 | |
| 2790 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2791 | type = nla_get_u32(info->attrs[idx]); |
| 2792 | |
| 2793 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2794 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2795 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2796 | |
| 2797 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2798 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2799 | mbm = nla_get_u32(info->attrs[idx]); |
| 2800 | } |
| 2801 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2802 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2803 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2804 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2805 | } |
| 2806 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2807 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2808 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2809 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2810 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2811 | if ((!rdev->wiphy.available_antennas_tx && |
| 2812 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2813 | !rdev->ops->set_antenna) |
| 2814 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2815 | |
| 2816 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2817 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2818 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2819 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2820 | * available antenna masks, except for the "all" mask */ |
| 2821 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2822 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2823 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2824 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2825 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2826 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2827 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2828 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2829 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2830 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2831 | } |
| 2832 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2833 | changed = 0; |
| 2834 | |
| 2835 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2836 | retry_short = nla_get_u8( |
| 2837 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2838 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2839 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2840 | } |
| 2841 | |
| 2842 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2843 | retry_long = nla_get_u8( |
| 2844 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2845 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2846 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2847 | } |
| 2848 | |
| 2849 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2850 | frag_threshold = nla_get_u32( |
| 2851 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2852 | if (frag_threshold < 256) |
| 2853 | return -EINVAL; |
| 2854 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2855 | if (frag_threshold != (u32) -1) { |
| 2856 | /* |
| 2857 | * Fragments (apart from the last one) are required to |
| 2858 | * have even length. Make the fragmentation code |
| 2859 | * simpler by stripping LSB should someone try to use |
| 2860 | * odd threshold value. |
| 2861 | */ |
| 2862 | frag_threshold &= ~0x1; |
| 2863 | } |
| 2864 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2865 | } |
| 2866 | |
| 2867 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2868 | rts_threshold = nla_get_u32( |
| 2869 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2870 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2871 | } |
| 2872 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2873 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2874 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2875 | return -EINVAL; |
| 2876 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2877 | coverage_class = nla_get_u8( |
| 2878 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2879 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2880 | } |
| 2881 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2882 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2883 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2884 | return -EOPNOTSUPP; |
| 2885 | |
| 2886 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2887 | } |
| 2888 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2889 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { |
| 2890 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 2891 | NL80211_EXT_FEATURE_TXQS)) |
| 2892 | return -EOPNOTSUPP; |
| 2893 | txq_limit = nla_get_u32( |
| 2894 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); |
| 2895 | changed |= WIPHY_PARAM_TXQ_LIMIT; |
| 2896 | } |
| 2897 | |
| 2898 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { |
| 2899 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 2900 | NL80211_EXT_FEATURE_TXQS)) |
| 2901 | return -EOPNOTSUPP; |
| 2902 | txq_memory_limit = nla_get_u32( |
| 2903 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); |
| 2904 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; |
| 2905 | } |
| 2906 | |
| 2907 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { |
| 2908 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 2909 | NL80211_EXT_FEATURE_TXQS)) |
| 2910 | return -EOPNOTSUPP; |
| 2911 | txq_quantum = nla_get_u32( |
| 2912 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); |
| 2913 | changed |= WIPHY_PARAM_TXQ_QUANTUM; |
| 2914 | } |
| 2915 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2916 | if (changed) { |
| 2917 | u8 old_retry_short, old_retry_long; |
| 2918 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2919 | u8 old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2920 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2921 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2922 | if (!rdev->ops->set_wiphy_params) |
| 2923 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2924 | |
| 2925 | old_retry_short = rdev->wiphy.retry_short; |
| 2926 | old_retry_long = rdev->wiphy.retry_long; |
| 2927 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2928 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2929 | old_coverage_class = rdev->wiphy.coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2930 | old_txq_limit = rdev->wiphy.txq_limit; |
| 2931 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; |
| 2932 | old_txq_quantum = rdev->wiphy.txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2933 | |
| 2934 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2935 | rdev->wiphy.retry_short = retry_short; |
| 2936 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2937 | rdev->wiphy.retry_long = retry_long; |
| 2938 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2939 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2940 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2941 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2942 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2943 | rdev->wiphy.coverage_class = coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2944 | if (changed & WIPHY_PARAM_TXQ_LIMIT) |
| 2945 | rdev->wiphy.txq_limit = txq_limit; |
| 2946 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) |
| 2947 | rdev->wiphy.txq_memory_limit = txq_memory_limit; |
| 2948 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) |
| 2949 | rdev->wiphy.txq_quantum = txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2950 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2951 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2952 | if (result) { |
| 2953 | rdev->wiphy.retry_short = old_retry_short; |
| 2954 | rdev->wiphy.retry_long = old_retry_long; |
| 2955 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2956 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2957 | rdev->wiphy.coverage_class = old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2958 | rdev->wiphy.txq_limit = old_txq_limit; |
| 2959 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; |
| 2960 | rdev->wiphy.txq_quantum = old_txq_quantum; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2961 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2962 | } |
| 2963 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2964 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2965 | } |
| 2966 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2967 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2968 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2969 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2970 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2971 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2972 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2973 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2974 | chandef->chan->center_freq)) |
| 2975 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2976 | switch (chandef->width) { |
| 2977 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2978 | case NL80211_CHAN_WIDTH_20: |
| 2979 | case NL80211_CHAN_WIDTH_40: |
| 2980 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2981 | cfg80211_get_chandef_type(chandef))) |
| 2982 | return -ENOBUFS; |
| 2983 | break; |
| 2984 | default: |
| 2985 | break; |
| 2986 | } |
| 2987 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2988 | return -ENOBUFS; |
| 2989 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2990 | return -ENOBUFS; |
| 2991 | if (chandef->center_freq2 && |
| 2992 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2993 | return -ENOBUFS; |
| 2994 | return 0; |
| 2995 | } |
| 2996 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2997 | 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] | 2998 | struct cfg80211_registered_device *rdev, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 2999 | struct wireless_dev *wdev, |
| 3000 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3001 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3002 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3003 | void *hdr; |
| 3004 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3005 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 3006 | cmd != NL80211_CMD_DEL_INTERFACE && |
| 3007 | cmd != NL80211_CMD_SET_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3008 | |
| 3009 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3010 | if (!hdr) |
| 3011 | return -1; |
| 3012 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3013 | if (dev && |
| 3014 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3015 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3016 | goto nla_put_failure; |
| 3017 | |
| 3018 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 3019 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 3020 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 3021 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3022 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3023 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 3024 | rdev->devlist_generation ^ |
Antonio Quartulli | 446faa1 | 2018-06-14 09:43:06 +0800 | [diff] [blame] | 3025 | (cfg80211_rdev_list_generation << 2)) || |
| 3026 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3027 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3028 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3029 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3030 | int ret; |
| 3031 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3032 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3033 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 3034 | if (ret == 0) { |
| 3035 | if (nl80211_send_chandef(msg, &chandef)) |
| 3036 | goto nla_put_failure; |
| 3037 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 3038 | } |
| 3039 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 3040 | if (rdev->ops->get_tx_power) { |
| 3041 | int dbm, ret; |
| 3042 | |
| 3043 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 3044 | if (ret == 0 && |
| 3045 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 3046 | DBM_TO_MBM(dbm))) |
| 3047 | goto nla_put_failure; |
| 3048 | } |
| 3049 | |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3050 | wdev_lock(wdev); |
| 3051 | switch (wdev->iftype) { |
| 3052 | case NL80211_IFTYPE_AP: |
| 3053 | if (wdev->ssid_len && |
| 3054 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3055 | goto nla_put_failure_locked; |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3056 | break; |
| 3057 | case NL80211_IFTYPE_STATION: |
| 3058 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3059 | case NL80211_IFTYPE_ADHOC: { |
| 3060 | const u8 *ssid_ie; |
| 3061 | if (!wdev->current_bss) |
| 3062 | break; |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3063 | rcu_read_lock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3064 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 3065 | WLAN_EID_SSID); |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3066 | if (ssid_ie && |
| 3067 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) |
| 3068 | goto nla_put_failure_rcu_locked; |
| 3069 | rcu_read_unlock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3070 | break; |
| 3071 | } |
| 3072 | default: |
| 3073 | /* nothing */ |
| 3074 | break; |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3075 | } |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3076 | wdev_unlock(wdev); |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3077 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3078 | if (rdev->ops->get_txq_stats) { |
| 3079 | struct cfg80211_txq_stats txqstats = {}; |
| 3080 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); |
| 3081 | |
| 3082 | if (ret == 0 && |
| 3083 | !nl80211_put_txq_stats(msg, &txqstats, |
| 3084 | NL80211_ATTR_TXQ_STATS)) |
| 3085 | goto nla_put_failure; |
| 3086 | } |
| 3087 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3088 | genlmsg_end(msg, hdr); |
| 3089 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3090 | |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3091 | nla_put_failure_rcu_locked: |
| 3092 | rcu_read_unlock(); |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3093 | nla_put_failure_locked: |
| 3094 | wdev_unlock(wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3095 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3096 | genlmsg_cancel(msg, hdr); |
| 3097 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 3101 | { |
| 3102 | int wp_idx = 0; |
| 3103 | int if_idx = 0; |
| 3104 | int wp_start = cb->args[0]; |
| 3105 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3106 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3107 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3108 | struct wireless_dev *wdev; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3109 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3110 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3111 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3112 | if (!cb->args[2]) { |
| 3113 | struct nl80211_dump_wiphy_state state = { |
| 3114 | .filter_wiphy = -1, |
| 3115 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3116 | |
| 3117 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 3118 | if (ret) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3119 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3120 | |
| 3121 | filter_wiphy = state.filter_wiphy; |
| 3122 | |
| 3123 | /* |
| 3124 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 3125 | * value needed to determine that parsing is necessary. |
| 3126 | */ |
| 3127 | if (filter_wiphy >= 0) |
| 3128 | cb->args[2] = filter_wiphy + 1; |
| 3129 | else |
| 3130 | cb->args[2] = -1; |
| 3131 | } else if (cb->args[2] > 0) { |
| 3132 | filter_wiphy = cb->args[2] - 1; |
| 3133 | } |
| 3134 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3135 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 3136 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3137 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3138 | if (wp_idx < wp_start) { |
| 3139 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3140 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3141 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3142 | |
| 3143 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 3144 | continue; |
| 3145 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3146 | if_idx = 0; |
| 3147 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3148 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3149 | if (if_idx < if_start) { |
| 3150 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3151 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3152 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3153 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3154 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3155 | rdev, wdev, |
| 3156 | NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3157 | goto out; |
| 3158 | } |
| 3159 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3160 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3161 | |
| 3162 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3163 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3164 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3165 | cb->args[0] = wp_idx; |
| 3166 | cb->args[1] = if_idx; |
| 3167 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3168 | ret = skb->len; |
| 3169 | out_unlock: |
| 3170 | rtnl_unlock(); |
| 3171 | |
| 3172 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 3176 | { |
| 3177 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3178 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3179 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3180 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3181 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3182 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3183 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3184 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3185 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3186 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3187 | nlmsg_free(msg); |
| 3188 | return -ENOBUFS; |
| 3189 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3190 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3191 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3192 | } |
| 3193 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3194 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 3195 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 3196 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 3197 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 3198 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 3199 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3200 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3201 | }; |
| 3202 | |
| 3203 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 3204 | { |
| 3205 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 3206 | int flag; |
| 3207 | |
| 3208 | *mntrflags = 0; |
| 3209 | |
| 3210 | if (!nla) |
| 3211 | return -EINVAL; |
| 3212 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 3213 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla, |
| 3214 | mntr_flags_policy, NULL)) |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3215 | return -EINVAL; |
| 3216 | |
| 3217 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 3218 | if (flags[flag]) |
| 3219 | *mntrflags |= (1<<flag); |
| 3220 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3221 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 3222 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3223 | return 0; |
| 3224 | } |
| 3225 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3226 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 3227 | enum nl80211_iftype type, |
| 3228 | struct genl_info *info, |
| 3229 | struct vif_params *params) |
| 3230 | { |
| 3231 | bool change = false; |
| 3232 | int err; |
| 3233 | |
| 3234 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 3235 | if (type != NL80211_IFTYPE_MONITOR) |
| 3236 | return -EINVAL; |
| 3237 | |
| 3238 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 3239 | ¶ms->flags); |
| 3240 | if (err) |
| 3241 | return err; |
| 3242 | |
| 3243 | change = true; |
| 3244 | } |
| 3245 | |
| 3246 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 3247 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 3248 | return -EOPNOTSUPP; |
| 3249 | |
| 3250 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 3251 | const u8 *mumimo_groups; |
| 3252 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3253 | |
| 3254 | if (type != NL80211_IFTYPE_MONITOR) |
| 3255 | return -EINVAL; |
| 3256 | |
| 3257 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3258 | return -EOPNOTSUPP; |
| 3259 | |
| 3260 | mumimo_groups = |
| 3261 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 3262 | |
| 3263 | /* bits 0 and 63 are reserved and must be zero */ |
Johannes Berg | 4954601 | 2017-04-27 09:13:38 +0200 | [diff] [blame] | 3264 | if ((mumimo_groups[0] & BIT(0)) || |
| 3265 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3266 | return -EINVAL; |
| 3267 | |
| 3268 | params->vht_mumimo_groups = mumimo_groups; |
| 3269 | change = true; |
| 3270 | } |
| 3271 | |
| 3272 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 3273 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3274 | |
| 3275 | if (type != NL80211_IFTYPE_MONITOR) |
| 3276 | return -EINVAL; |
| 3277 | |
| 3278 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3279 | return -EOPNOTSUPP; |
| 3280 | |
| 3281 | params->vht_mumimo_follow_addr = |
| 3282 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 3283 | change = true; |
| 3284 | } |
| 3285 | |
| 3286 | return change ? 1 : 0; |
| 3287 | } |
| 3288 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3289 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3290 | struct net_device *netdev, u8 use_4addr, |
| 3291 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3292 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3293 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 3294 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3295 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3296 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3297 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3298 | |
| 3299 | switch (iftype) { |
| 3300 | case NL80211_IFTYPE_AP_VLAN: |
| 3301 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 3302 | return 0; |
| 3303 | break; |
| 3304 | case NL80211_IFTYPE_STATION: |
| 3305 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 3306 | return 0; |
| 3307 | break; |
| 3308 | default: |
| 3309 | break; |
| 3310 | } |
| 3311 | |
| 3312 | return -EOPNOTSUPP; |
| 3313 | } |
| 3314 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3315 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 3316 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3318 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 3319 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3320 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3321 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3322 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3323 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3324 | memset(¶ms, 0, sizeof(params)); |
| 3325 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3326 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3327 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3328 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3329 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3330 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3331 | change = true; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3332 | } |
| 3333 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 3334 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3335 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3336 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3337 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 3338 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3339 | if (netif_running(dev)) |
| 3340 | return -EBUSY; |
| 3341 | |
| 3342 | wdev_lock(wdev); |
| 3343 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3344 | IEEE80211_MAX_MESH_ID_LEN); |
| 3345 | wdev->mesh_id_up_len = |
| 3346 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3347 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3348 | wdev->mesh_id_up_len); |
| 3349 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3350 | } |
| 3351 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3352 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 3353 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 3354 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3355 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3356 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3357 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3358 | } else { |
| 3359 | params.use_4addr = -1; |
| 3360 | } |
| 3361 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3362 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 3363 | if (err < 0) |
| 3364 | return err; |
| 3365 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3366 | change = true; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3367 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3368 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3369 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3370 | else |
| 3371 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 3372 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3373 | if (!err && params.use_4addr != -1) |
| 3374 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 3375 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3376 | if (change && !err) { |
| 3377 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3378 | |
| 3379 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); |
| 3380 | } |
| 3381 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3382 | return err; |
| 3383 | } |
| 3384 | |
| 3385 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 3386 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3387 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3388 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3389 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 3390 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3391 | int err; |
| 3392 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 3393 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3394 | /* to avoid failing a new interface creation due to pending removal */ |
| 3395 | cfg80211_destroy_ifaces(rdev); |
| 3396 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3397 | memset(¶ms, 0, sizeof(params)); |
| 3398 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3399 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 3400 | return -EINVAL; |
| 3401 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 3402 | if (info->attrs[NL80211_ATTR_IFTYPE]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3403 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3404 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3405 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3406 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 3407 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3408 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3409 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 3410 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 3411 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 3412 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 3413 | ETH_ALEN); |
| 3414 | if (!is_valid_ether_addr(params.macaddr)) |
| 3415 | return -EADDRNOTAVAIL; |
| 3416 | } |
| 3417 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3418 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3419 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3420 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3421 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3422 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3423 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3424 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3425 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 3426 | if (err < 0) |
| 3427 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3428 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 3429 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 3430 | if (!msg) |
| 3431 | return -ENOMEM; |
| 3432 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3433 | wdev = rdev_add_virtual_intf(rdev, |
| 3434 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3435 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 3436 | if (WARN_ON(!wdev)) { |
| 3437 | nlmsg_free(msg); |
| 3438 | return -EPROTO; |
| 3439 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3440 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3441 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3442 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3443 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 3444 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3445 | wdev->owner_nlportid = info->snd_portid; |
| 3446 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3447 | switch (type) { |
| 3448 | case NL80211_IFTYPE_MESH_POINT: |
| 3449 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 3450 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3451 | wdev_lock(wdev); |
| 3452 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3453 | IEEE80211_MAX_MESH_ID_LEN); |
| 3454 | wdev->mesh_id_up_len = |
| 3455 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3456 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3457 | wdev->mesh_id_up_len); |
| 3458 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3459 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3460 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3461 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3462 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3463 | * 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] | 3464 | * through the netdev notifier and must be added here |
| 3465 | */ |
Johannes Berg | e4d4216 | 2018-09-13 14:12:03 +0200 | [diff] [blame] | 3466 | cfg80211_init_wdev(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3467 | break; |
| 3468 | default: |
| 3469 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3470 | } |
| 3471 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3472 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3473 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3474 | nlmsg_free(msg); |
| 3475 | return -ENOBUFS; |
| 3476 | } |
| 3477 | |
| 3478 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3482 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3484 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3485 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3486 | if (!rdev->ops->del_virtual_intf) |
| 3487 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3488 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3489 | /* |
| 3490 | * If we remove a wireless device without a netdev then clear |
| 3491 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3492 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3493 | * since the wdev has been freed, unlike with a netdev where |
| 3494 | * we need the dev_put() for the netdev to really be freed. |
| 3495 | */ |
| 3496 | if (!wdev->netdev) |
| 3497 | info->user_ptr[1] = NULL; |
| 3498 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 3499 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3500 | } |
| 3501 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3502 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3503 | { |
| 3504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3505 | struct net_device *dev = info->user_ptr[1]; |
| 3506 | u16 noack_map; |
| 3507 | |
| 3508 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3509 | return -EINVAL; |
| 3510 | |
| 3511 | if (!rdev->ops->set_noack_map) |
| 3512 | return -EOPNOTSUPP; |
| 3513 | |
| 3514 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3515 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3516 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3517 | } |
| 3518 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3519 | struct get_key_cookie { |
| 3520 | struct sk_buff *msg; |
| 3521 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3522 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3523 | }; |
| 3524 | |
| 3525 | static void get_key_callback(void *c, struct key_params *params) |
| 3526 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3527 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3528 | struct get_key_cookie *cookie = c; |
| 3529 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3530 | if ((params->key && |
| 3531 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3532 | params->key_len, params->key)) || |
| 3533 | (params->seq && |
| 3534 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3535 | params->seq_len, params->seq)) || |
| 3536 | (params->cipher && |
| 3537 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3538 | params->cipher))) |
| 3539 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3540 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3541 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 3542 | if (!key) |
| 3543 | goto nla_put_failure; |
| 3544 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3545 | if ((params->key && |
| 3546 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3547 | params->key_len, params->key)) || |
| 3548 | (params->seq && |
| 3549 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3550 | params->seq_len, params->seq)) || |
| 3551 | (params->cipher && |
| 3552 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3553 | params->cipher))) |
| 3554 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3555 | |
Andrew Zaborowski | efdfce7 | 2018-09-24 18:10:22 +0200 | [diff] [blame] | 3556 | if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3557 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3558 | |
| 3559 | nla_nest_end(cookie->msg, key); |
| 3560 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3561 | return; |
| 3562 | nla_put_failure: |
| 3563 | cookie->error = 1; |
| 3564 | } |
| 3565 | |
| 3566 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3567 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3569 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3570 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3571 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3572 | const u8 *mac_addr = NULL; |
| 3573 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3574 | struct get_key_cookie cookie = { |
| 3575 | .error = 0, |
| 3576 | }; |
| 3577 | void *hdr; |
| 3578 | struct sk_buff *msg; |
| 3579 | |
| 3580 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 3581 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 3582 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3583 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3584 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3585 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3586 | pairwise = !!mac_addr; |
| 3587 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3588 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3589 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3590 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3591 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3592 | return -EINVAL; |
| 3593 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3594 | } |
| 3595 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3596 | if (!rdev->ops->get_key) |
| 3597 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3598 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3599 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3600 | return -ENOENT; |
| 3601 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3603 | if (!msg) |
| 3604 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3605 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3606 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3607 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3608 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3609 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3610 | |
| 3611 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3612 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3613 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3614 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3615 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3616 | goto nla_put_failure; |
| 3617 | if (mac_addr && |
| 3618 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3619 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3620 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3621 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3622 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3623 | |
| 3624 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3625 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3626 | |
| 3627 | if (cookie.error) |
| 3628 | goto nla_put_failure; |
| 3629 | |
| 3630 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3631 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3632 | |
| 3633 | nla_put_failure: |
| 3634 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3635 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3636 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3637 | return err; |
| 3638 | } |
| 3639 | |
| 3640 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3641 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3642 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3643 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3644 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3645 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3646 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3647 | err = nl80211_parse_key(info, &key); |
| 3648 | if (err) |
| 3649 | return err; |
| 3650 | |
| 3651 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3652 | return -EINVAL; |
| 3653 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3654 | /* only support setting default key */ |
| 3655 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3656 | return -EINVAL; |
| 3657 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3658 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3659 | |
| 3660 | if (key.def) { |
| 3661 | if (!rdev->ops->set_default_key) { |
| 3662 | err = -EOPNOTSUPP; |
| 3663 | goto out; |
| 3664 | } |
| 3665 | |
| 3666 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3667 | if (err) |
| 3668 | goto out; |
| 3669 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3670 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3671 | key.def_uni, key.def_multi); |
| 3672 | |
| 3673 | if (err) |
| 3674 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3675 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3676 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3677 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3678 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3679 | } else { |
| 3680 | if (key.def_uni || !key.def_multi) { |
| 3681 | err = -EINVAL; |
| 3682 | goto out; |
| 3683 | } |
| 3684 | |
| 3685 | if (!rdev->ops->set_default_mgmt_key) { |
| 3686 | err = -EOPNOTSUPP; |
| 3687 | goto out; |
| 3688 | } |
| 3689 | |
| 3690 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3691 | if (err) |
| 3692 | goto out; |
| 3693 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3694 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3695 | if (err) |
| 3696 | goto out; |
| 3697 | |
| 3698 | #ifdef CONFIG_CFG80211_WEXT |
| 3699 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3700 | #endif |
| 3701 | } |
| 3702 | |
| 3703 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3704 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3705 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3706 | return err; |
| 3707 | } |
| 3708 | |
| 3709 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3710 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3711 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3712 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3713 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3714 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3715 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3716 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3717 | err = nl80211_parse_key(info, &key); |
| 3718 | if (err) |
| 3719 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3720 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3721 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3722 | return -EINVAL; |
| 3723 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3724 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3725 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3726 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3727 | if (key.type == -1) { |
| 3728 | if (mac_addr) |
| 3729 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3730 | else |
| 3731 | key.type = NL80211_KEYTYPE_GROUP; |
| 3732 | } |
| 3733 | |
| 3734 | /* for now */ |
| 3735 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3736 | key.type != NL80211_KEYTYPE_GROUP) |
| 3737 | return -EINVAL; |
| 3738 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3739 | if (!rdev->ops->add_key) |
| 3740 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3741 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3742 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3743 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3744 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3745 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3746 | |
| 3747 | wdev_lock(dev->ieee80211_ptr); |
| 3748 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3749 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3750 | err = rdev_add_key(rdev, dev, key.idx, |
| 3751 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3752 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3753 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3754 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3755 | return err; |
| 3756 | } |
| 3757 | |
| 3758 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3759 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3760 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3761 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3762 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3763 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3764 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3765 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3766 | err = nl80211_parse_key(info, &key); |
| 3767 | if (err) |
| 3768 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3769 | |
| 3770 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3771 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3772 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3773 | if (key.type == -1) { |
| 3774 | if (mac_addr) |
| 3775 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3776 | else |
| 3777 | key.type = NL80211_KEYTYPE_GROUP; |
| 3778 | } |
| 3779 | |
| 3780 | /* for now */ |
| 3781 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3782 | key.type != NL80211_KEYTYPE_GROUP) |
| 3783 | return -EINVAL; |
| 3784 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3785 | if (!rdev->ops->del_key) |
| 3786 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3787 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3788 | wdev_lock(dev->ieee80211_ptr); |
| 3789 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3790 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3791 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3792 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3793 | err = -ENOENT; |
| 3794 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3795 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3796 | err = rdev_del_key(rdev, dev, key.idx, |
| 3797 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3798 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3799 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3800 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3801 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3802 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3803 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3804 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3805 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3806 | } |
| 3807 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3808 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3809 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3810 | return err; |
| 3811 | } |
| 3812 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3813 | /* This function returns an error or the number of nested attributes */ |
| 3814 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3815 | { |
| 3816 | struct nlattr *attr; |
| 3817 | int n_entries = 0, tmp; |
| 3818 | |
| 3819 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3820 | if (nla_len(attr) != ETH_ALEN) |
| 3821 | return -EINVAL; |
| 3822 | |
| 3823 | n_entries++; |
| 3824 | } |
| 3825 | |
| 3826 | return n_entries; |
| 3827 | } |
| 3828 | |
| 3829 | /* |
| 3830 | * This function parses ACL information and allocates memory for ACL data. |
| 3831 | * On successful return, the calling function is responsible to free the |
| 3832 | * ACL buffer returned by this function. |
| 3833 | */ |
| 3834 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3835 | struct genl_info *info) |
| 3836 | { |
| 3837 | enum nl80211_acl_policy acl_policy; |
| 3838 | struct nlattr *attr; |
| 3839 | struct cfg80211_acl_data *acl; |
| 3840 | int i = 0, n_entries, tmp; |
| 3841 | |
| 3842 | if (!wiphy->max_acl_mac_addrs) |
| 3843 | return ERR_PTR(-EOPNOTSUPP); |
| 3844 | |
| 3845 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3846 | return ERR_PTR(-EINVAL); |
| 3847 | |
| 3848 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3849 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3850 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3851 | return ERR_PTR(-EINVAL); |
| 3852 | |
| 3853 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3854 | return ERR_PTR(-EINVAL); |
| 3855 | |
| 3856 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3857 | if (n_entries < 0) |
| 3858 | return ERR_PTR(n_entries); |
| 3859 | |
| 3860 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3861 | return ERR_PTR(-ENOTSUPP); |
| 3862 | |
| 3863 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3864 | GFP_KERNEL); |
| 3865 | if (!acl) |
| 3866 | return ERR_PTR(-ENOMEM); |
| 3867 | |
| 3868 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3869 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3870 | i++; |
| 3871 | } |
| 3872 | |
| 3873 | acl->n_acl_entries = n_entries; |
| 3874 | acl->acl_policy = acl_policy; |
| 3875 | |
| 3876 | return acl; |
| 3877 | } |
| 3878 | |
| 3879 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3880 | { |
| 3881 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3882 | struct net_device *dev = info->user_ptr[1]; |
| 3883 | struct cfg80211_acl_data *acl; |
| 3884 | int err; |
| 3885 | |
| 3886 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3887 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3888 | return -EOPNOTSUPP; |
| 3889 | |
| 3890 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3891 | return -EINVAL; |
| 3892 | |
| 3893 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3894 | if (IS_ERR(acl)) |
| 3895 | return PTR_ERR(acl); |
| 3896 | |
| 3897 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3898 | |
| 3899 | kfree(acl); |
| 3900 | |
| 3901 | return err; |
| 3902 | } |
| 3903 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3904 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3905 | u8 *rates, u8 rates_len) |
| 3906 | { |
| 3907 | u8 i; |
| 3908 | u32 mask = 0; |
| 3909 | |
| 3910 | for (i = 0; i < rates_len; i++) { |
| 3911 | int rate = (rates[i] & 0x7f) * 5; |
| 3912 | int ridx; |
| 3913 | |
| 3914 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 3915 | struct ieee80211_rate *srate = |
| 3916 | &sband->bitrates[ridx]; |
| 3917 | if (rate == srate->bitrate) { |
| 3918 | mask |= 1 << ridx; |
| 3919 | break; |
| 3920 | } |
| 3921 | } |
| 3922 | if (ridx == sband->n_bitrates) |
| 3923 | return 0; /* rate not found */ |
| 3924 | } |
| 3925 | |
| 3926 | return mask; |
| 3927 | } |
| 3928 | |
| 3929 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3930 | u8 *rates, u8 rates_len, |
| 3931 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 3932 | { |
| 3933 | u8 i; |
| 3934 | |
| 3935 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 3936 | |
| 3937 | for (i = 0; i < rates_len; i++) { |
| 3938 | int ridx, rbit; |
| 3939 | |
| 3940 | ridx = rates[i] / 8; |
| 3941 | rbit = BIT(rates[i] % 8); |
| 3942 | |
| 3943 | /* check validity */ |
| 3944 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 3945 | return false; |
| 3946 | |
| 3947 | /* check availability */ |
Masashi Honma | 30fe6d5 | 2018-09-25 11:15:00 +0900 | [diff] [blame] | 3948 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3949 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 3950 | mcs[ridx] |= rbit; |
| 3951 | else |
| 3952 | return false; |
| 3953 | } |
| 3954 | |
| 3955 | return true; |
| 3956 | } |
| 3957 | |
| 3958 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 3959 | { |
| 3960 | u16 mcs_mask = 0; |
| 3961 | |
| 3962 | switch (vht_mcs_map) { |
| 3963 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 3964 | break; |
| 3965 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 3966 | mcs_mask = 0x00FF; |
| 3967 | break; |
| 3968 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 3969 | mcs_mask = 0x01FF; |
| 3970 | break; |
| 3971 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 3972 | mcs_mask = 0x03FF; |
| 3973 | break; |
| 3974 | default: |
| 3975 | break; |
| 3976 | } |
| 3977 | |
| 3978 | return mcs_mask; |
| 3979 | } |
| 3980 | |
| 3981 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 3982 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 3983 | { |
| 3984 | u8 nss; |
| 3985 | |
| 3986 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 3987 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 3988 | vht_mcs_map >>= 2; |
| 3989 | } |
| 3990 | } |
| 3991 | |
| 3992 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 3993 | struct nl80211_txrate_vht *txrate, |
| 3994 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 3995 | { |
| 3996 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3997 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 3998 | u8 i; |
| 3999 | |
| 4000 | if (!sband->vht_cap.vht_supported) |
| 4001 | return false; |
| 4002 | |
| 4003 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 4004 | |
| 4005 | /* Build vht_mcs_mask from VHT capabilities */ |
| 4006 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4007 | |
| 4008 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 4009 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4010 | mcs[i] = txrate->mcs[i]; |
| 4011 | else |
| 4012 | return false; |
| 4013 | } |
| 4014 | |
| 4015 | return true; |
| 4016 | } |
| 4017 | |
| 4018 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 4019 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4020 | .len = NL80211_MAX_SUPP_RATES }, |
| 4021 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 4022 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 4023 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
| 4024 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 4025 | }; |
| 4026 | |
| 4027 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| 4028 | struct cfg80211_bitrate_mask *mask) |
| 4029 | { |
| 4030 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 4031 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4032 | int rem, i; |
| 4033 | struct nlattr *tx_rates; |
| 4034 | struct ieee80211_supported_band *sband; |
| 4035 | u16 vht_tx_mcs_map; |
| 4036 | |
| 4037 | memset(mask, 0, sizeof(*mask)); |
| 4038 | /* Default to all rates enabled */ |
| 4039 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 4040 | sband = rdev->wiphy.bands[i]; |
| 4041 | |
| 4042 | if (!sband) |
| 4043 | continue; |
| 4044 | |
| 4045 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 4046 | memcpy(mask->control[i].ht_mcs, |
| 4047 | sband->ht_cap.mcs.rx_mask, |
| 4048 | sizeof(mask->control[i].ht_mcs)); |
| 4049 | |
| 4050 | if (!sband->vht_cap.vht_supported) |
| 4051 | continue; |
| 4052 | |
| 4053 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4054 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 4055 | } |
| 4056 | |
| 4057 | /* if no rates are given set it back to the defaults */ |
| 4058 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 4059 | goto out; |
| 4060 | |
| 4061 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 4062 | * directly to the enum nl80211_band values used in cfg80211. |
| 4063 | */ |
| 4064 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| 4065 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
| 4066 | enum nl80211_band band = nla_type(tx_rates); |
| 4067 | int err; |
| 4068 | |
| 4069 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 4070 | return -EINVAL; |
| 4071 | sband = rdev->wiphy.bands[band]; |
| 4072 | if (sband == NULL) |
| 4073 | return -EINVAL; |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 4074 | err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 4075 | nl80211_txattr_policy, info->extack); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4076 | if (err) |
| 4077 | return err; |
| 4078 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4079 | mask->control[band].legacy = rateset_to_mask( |
| 4080 | sband, |
| 4081 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4082 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 4083 | if ((mask->control[band].legacy == 0) && |
| 4084 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 4085 | return -EINVAL; |
| 4086 | } |
| 4087 | if (tb[NL80211_TXRATE_HT]) { |
| 4088 | if (!ht_rateset_to_mask( |
| 4089 | sband, |
| 4090 | nla_data(tb[NL80211_TXRATE_HT]), |
| 4091 | nla_len(tb[NL80211_TXRATE_HT]), |
| 4092 | mask->control[band].ht_mcs)) |
| 4093 | return -EINVAL; |
| 4094 | } |
| 4095 | if (tb[NL80211_TXRATE_VHT]) { |
| 4096 | if (!vht_set_mcs_mask( |
| 4097 | sband, |
| 4098 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 4099 | mask->control[band].vht_mcs)) |
| 4100 | return -EINVAL; |
| 4101 | } |
| 4102 | if (tb[NL80211_TXRATE_GI]) { |
| 4103 | mask->control[band].gi = |
| 4104 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 4105 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 4106 | return -EINVAL; |
| 4107 | } |
| 4108 | |
| 4109 | if (mask->control[band].legacy == 0) { |
| 4110 | /* don't allow empty legacy rates if HT or VHT |
| 4111 | * are not even supported. |
| 4112 | */ |
| 4113 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 4114 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 4115 | return -EINVAL; |
| 4116 | |
| 4117 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 4118 | if (mask->control[band].ht_mcs[i]) |
| 4119 | goto out; |
| 4120 | |
| 4121 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 4122 | if (mask->control[band].vht_mcs[i]) |
| 4123 | goto out; |
| 4124 | |
| 4125 | /* legacy and mcs rates may not be both empty */ |
| 4126 | return -EINVAL; |
| 4127 | } |
| 4128 | } |
| 4129 | |
| 4130 | out: |
| 4131 | return 0; |
| 4132 | } |
| 4133 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4134 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 4135 | enum nl80211_band band, |
| 4136 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4137 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4138 | u32 count_ht, count_vht, i; |
| 4139 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4140 | |
| 4141 | /* Allow only one rate */ |
| 4142 | if (hweight32(rate) > 1) |
| 4143 | return -EINVAL; |
| 4144 | |
| 4145 | count_ht = 0; |
| 4146 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4147 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4148 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4149 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4150 | count_ht++; |
| 4151 | if (count_ht > 1) |
| 4152 | return -EINVAL; |
| 4153 | } |
| 4154 | if (count_ht && rate) |
| 4155 | return -EINVAL; |
| 4156 | } |
| 4157 | |
| 4158 | count_vht = 0; |
| 4159 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4160 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4161 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4162 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4163 | count_vht++; |
| 4164 | if (count_vht > 1) |
| 4165 | return -EINVAL; |
| 4166 | } |
| 4167 | if (count_vht && rate) |
| 4168 | return -EINVAL; |
| 4169 | } |
| 4170 | |
| 4171 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 4172 | return -EINVAL; |
| 4173 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4174 | if (rate && |
| 4175 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4176 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 4177 | return -EINVAL; |
| 4178 | if (count_ht && |
| 4179 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4180 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 4181 | return -EINVAL; |
| 4182 | if (count_vht && |
| 4183 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4184 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 4185 | return -EINVAL; |
| 4186 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4187 | return 0; |
| 4188 | } |
| 4189 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4190 | static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, |
| 4191 | struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4192 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4193 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4194 | bool haveinfo = false; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4195 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4196 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4197 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4198 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4199 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 4200 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 4201 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4202 | if (!bcn->head_len) |
| 4203 | return -EINVAL; |
| 4204 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4205 | } |
| 4206 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4207 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 4208 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 4209 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4210 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4211 | } |
| 4212 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4213 | if (!haveinfo) |
| 4214 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4215 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4216 | if (attrs[NL80211_ATTR_IE]) { |
| 4217 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 4218 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4219 | } |
| 4220 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4221 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4222 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4223 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4224 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4225 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4226 | } |
| 4227 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4228 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4229 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4230 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4231 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4232 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4233 | } |
| 4234 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4235 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 4236 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 4237 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 4238 | } |
| 4239 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4240 | if (attrs[NL80211_ATTR_FTM_RESPONDER]) { |
| 4241 | struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; |
| 4242 | |
| 4243 | err = nla_parse_nested(tb, NL80211_FTM_RESP_ATTR_MAX, |
| 4244 | attrs[NL80211_ATTR_FTM_RESPONDER], |
| 4245 | NULL, NULL); |
| 4246 | if (err) |
| 4247 | return err; |
| 4248 | |
| 4249 | if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && |
| 4250 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4251 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) |
| 4252 | bcn->ftm_responder = 1; |
| 4253 | else |
| 4254 | return -EOPNOTSUPP; |
| 4255 | |
| 4256 | if (tb[NL80211_FTM_RESP_ATTR_LCI]) { |
| 4257 | bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4258 | bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4259 | } |
| 4260 | |
| 4261 | if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { |
| 4262 | bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4263 | bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4264 | } |
| 4265 | } else { |
| 4266 | bcn->ftm_responder = -1; |
| 4267 | } |
| 4268 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4269 | return 0; |
| 4270 | } |
| 4271 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4272 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 4273 | const u8 *rates) |
| 4274 | { |
| 4275 | int i; |
| 4276 | |
| 4277 | if (!rates) |
| 4278 | return; |
| 4279 | |
| 4280 | for (i = 0; i < rates[1]; i++) { |
| 4281 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 4282 | params->ht_required = true; |
| 4283 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 4284 | params->vht_required = true; |
| 4285 | } |
| 4286 | } |
| 4287 | |
| 4288 | /* |
| 4289 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 4290 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 4291 | * benefit of drivers that rebuild IEs in the firmware. |
| 4292 | */ |
| 4293 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 4294 | { |
| 4295 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
Igor Mitsyanko | ba83bfb | 2017-08-30 13:52:25 -0700 | [diff] [blame] | 4296 | size_t ies_len = bcn->tail_len; |
| 4297 | const u8 *ies = bcn->tail; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4298 | const u8 *rates; |
| 4299 | const u8 *cap; |
| 4300 | |
| 4301 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 4302 | nl80211_check_ap_rate_selectors(params, rates); |
| 4303 | |
| 4304 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 4305 | nl80211_check_ap_rate_selectors(params, rates); |
| 4306 | |
| 4307 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 4308 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 4309 | params->ht_cap = (void *)(cap + 2); |
| 4310 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 4311 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 4312 | params->vht_cap = (void *)(cap + 2); |
Shaul Triebitz | 244eb9a | 2018-08-31 11:31:14 +0300 | [diff] [blame] | 4313 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); |
| 4314 | if (cap && cap[1] >= sizeof(*params->he_cap) + 1) |
| 4315 | params->he_cap = (void *)(cap + 3); |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4316 | } |
| 4317 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4318 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 4319 | struct cfg80211_ap_settings *params) |
| 4320 | { |
| 4321 | struct wireless_dev *wdev; |
| 4322 | bool ret = false; |
| 4323 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 4324 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4325 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 4326 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 4327 | continue; |
| 4328 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4329 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4330 | continue; |
| 4331 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4332 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4333 | ret = true; |
| 4334 | break; |
| 4335 | } |
| 4336 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4337 | return ret; |
| 4338 | } |
| 4339 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4340 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 4341 | enum nl80211_auth_type auth_type, |
| 4342 | enum nl80211_commands cmd) |
| 4343 | { |
| 4344 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 4345 | return false; |
| 4346 | |
| 4347 | switch (cmd) { |
| 4348 | case NL80211_CMD_AUTHENTICATE: |
| 4349 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 4350 | auth_type == NL80211_AUTHTYPE_SAE) |
| 4351 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 4352 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 4353 | NL80211_EXT_FEATURE_FILS_STA) && |
| 4354 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 4355 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4356 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 4357 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4358 | return true; |
| 4359 | case NL80211_CMD_CONNECT: |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 4360 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 4361 | auth_type == NL80211_AUTHTYPE_SAE) |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 4362 | return false; |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 4363 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 4364 | /* FILS with SK PFS or PK not supported yet */ |
| 4365 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4366 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 4367 | return false; |
| 4368 | if (!wiphy_ext_feature_isset( |
| 4369 | &rdev->wiphy, |
| 4370 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 4371 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 4372 | return false; |
| 4373 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4374 | case NL80211_CMD_START_AP: |
| 4375 | /* SAE not supported yet */ |
| 4376 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 4377 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 4378 | /* FILS not supported yet */ |
| 4379 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 4380 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4381 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 4382 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4383 | return true; |
| 4384 | default: |
| 4385 | return false; |
| 4386 | } |
| 4387 | } |
| 4388 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4389 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 4390 | { |
| 4391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4392 | struct net_device *dev = info->user_ptr[1]; |
| 4393 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4394 | struct cfg80211_ap_settings params; |
| 4395 | int err; |
| 4396 | |
| 4397 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4398 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4399 | return -EOPNOTSUPP; |
| 4400 | |
| 4401 | if (!rdev->ops->start_ap) |
| 4402 | return -EOPNOTSUPP; |
| 4403 | |
| 4404 | if (wdev->beacon_interval) |
| 4405 | return -EALREADY; |
| 4406 | |
| 4407 | memset(¶ms, 0, sizeof(params)); |
| 4408 | |
| 4409 | /* these are required for START_AP */ |
| 4410 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 4411 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 4412 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 4413 | return -EINVAL; |
| 4414 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4415 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4416 | if (err) |
| 4417 | return err; |
| 4418 | |
| 4419 | params.beacon_interval = |
| 4420 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4421 | params.dtim_period = |
| 4422 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 4423 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 4424 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 4425 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4426 | if (err) |
| 4427 | return err; |
| 4428 | |
| 4429 | /* |
| 4430 | * In theory, some of these attributes should be required here |
| 4431 | * but since they were not used when the command was originally |
| 4432 | * added, keep them optional for old user space programs to let |
| 4433 | * them continue to work with drivers that do not need the |
| 4434 | * additional information -- drivers must check! |
| 4435 | */ |
| 4436 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 4437 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4438 | params.ssid_len = |
| 4439 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4440 | if (params.ssid_len == 0 || |
| 4441 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 4442 | return -EINVAL; |
| 4443 | } |
| 4444 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 4445 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4446 | params.hidden_ssid = nla_get_u32( |
| 4447 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4448 | |
| 4449 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 4450 | |
| 4451 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4452 | params.auth_type = nla_get_u32( |
| 4453 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4454 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 4455 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4456 | return -EINVAL; |
| 4457 | } else |
| 4458 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4459 | |
| 4460 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 4461 | NL80211_MAX_NR_CIPHER_SUITES); |
| 4462 | if (err) |
| 4463 | return err; |
| 4464 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 4465 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 4466 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 4467 | return -EOPNOTSUPP; |
| 4468 | params.inactivity_timeout = nla_get_u16( |
| 4469 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 4470 | } |
| 4471 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4472 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4473 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4474 | return -EINVAL; |
| 4475 | params.p2p_ctwindow = |
| 4476 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4477 | if (params.p2p_ctwindow != 0 && |
| 4478 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4479 | return -EINVAL; |
| 4480 | } |
| 4481 | |
| 4482 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4483 | u8 tmp; |
| 4484 | |
| 4485 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4486 | return -EINVAL; |
| 4487 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4488 | params.p2p_opp_ps = tmp; |
| 4489 | if (params.p2p_opp_ps != 0 && |
| 4490 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4491 | return -EINVAL; |
| 4492 | } |
| 4493 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4494 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4495 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 4496 | if (err) |
| 4497 | return err; |
| 4498 | } else if (wdev->preset_chandef.chan) { |
| 4499 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4500 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4501 | return -EINVAL; |
| 4502 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 4503 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 4504 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4505 | return -EINVAL; |
| 4506 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4507 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 4508 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); |
| 4509 | if (err) |
| 4510 | return err; |
| 4511 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4512 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 4513 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4514 | if (err) |
| 4515 | return err; |
| 4516 | } |
| 4517 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 4518 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 4519 | params.smps_mode = |
| 4520 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 4521 | switch (params.smps_mode) { |
| 4522 | case NL80211_SMPS_OFF: |
| 4523 | break; |
| 4524 | case NL80211_SMPS_STATIC: |
| 4525 | if (!(rdev->wiphy.features & |
| 4526 | NL80211_FEATURE_STATIC_SMPS)) |
| 4527 | return -EINVAL; |
| 4528 | break; |
| 4529 | case NL80211_SMPS_DYNAMIC: |
| 4530 | if (!(rdev->wiphy.features & |
| 4531 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 4532 | return -EINVAL; |
| 4533 | break; |
| 4534 | default: |
| 4535 | return -EINVAL; |
| 4536 | } |
| 4537 | } else { |
| 4538 | params.smps_mode = NL80211_SMPS_OFF; |
| 4539 | } |
| 4540 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 4541 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 4542 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 4543 | return -EOPNOTSUPP; |
| 4544 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 4545 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 4546 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 4547 | if (IS_ERR(params.acl)) |
| 4548 | return PTR_ERR(params.acl); |
| 4549 | } |
| 4550 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4551 | nl80211_calculate_ap_params(¶ms); |
| 4552 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame^] | 4553 | if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) |
| 4554 | params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; |
| 4555 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4556 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4557 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4558 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4559 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4560 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 4561 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 4562 | wdev->ssid_len = params.ssid_len; |
| 4563 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Denis Kenzior | 466a306 | 2018-03-26 12:52:47 -0500 | [diff] [blame] | 4564 | |
| 4565 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 4566 | wdev->conn_owner_nlportid = info->snd_portid; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4567 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4568 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4569 | |
| 4570 | kfree(params.acl); |
| 4571 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 4572 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4573 | } |
| 4574 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4575 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 4576 | { |
| 4577 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4578 | struct net_device *dev = info->user_ptr[1]; |
| 4579 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4580 | struct cfg80211_beacon_data params; |
| 4581 | int err; |
| 4582 | |
| 4583 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4584 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4585 | return -EOPNOTSUPP; |
| 4586 | |
| 4587 | if (!rdev->ops->change_beacon) |
| 4588 | return -EOPNOTSUPP; |
| 4589 | |
| 4590 | if (!wdev->beacon_interval) |
| 4591 | return -EINVAL; |
| 4592 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4593 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4594 | if (err) |
| 4595 | return err; |
| 4596 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4597 | wdev_lock(wdev); |
| 4598 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 4599 | wdev_unlock(wdev); |
| 4600 | |
| 4601 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | 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] | 4605 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4607 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4608 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 4609 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4610 | } |
| 4611 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4612 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 4613 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 4614 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 4615 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 4616 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 4617 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 4618 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4619 | }; |
| 4620 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4621 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4622 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4623 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4624 | { |
| 4625 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4626 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4627 | int flag; |
| 4628 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4629 | /* |
| 4630 | * Try parsing the new attribute first so userspace |
| 4631 | * can specify both for older kernels. |
| 4632 | */ |
| 4633 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 4634 | if (nla) { |
| 4635 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4636 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4637 | sta_flags = nla_data(nla); |
| 4638 | params->sta_flags_mask = sta_flags->mask; |
| 4639 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4640 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4641 | if ((params->sta_flags_mask | |
| 4642 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 4643 | return -EINVAL; |
| 4644 | return 0; |
| 4645 | } |
| 4646 | |
| 4647 | /* if present, parse the old attribute */ |
| 4648 | |
| 4649 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4650 | if (!nla) |
| 4651 | return 0; |
| 4652 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 4653 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 4654 | sta_flags_policy, info->extack)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4655 | return -EINVAL; |
| 4656 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4657 | /* |
| 4658 | * Only allow certain flags for interface types so that |
| 4659 | * other attributes are silently ignored. Remember that |
| 4660 | * this is backward compatibility code with old userspace |
| 4661 | * and shouldn't be hit in other cases anyway. |
| 4662 | */ |
| 4663 | switch (iftype) { |
| 4664 | case NL80211_IFTYPE_AP: |
| 4665 | case NL80211_IFTYPE_AP_VLAN: |
| 4666 | case NL80211_IFTYPE_P2P_GO: |
| 4667 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4668 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4669 | BIT(NL80211_STA_FLAG_WME) | |
| 4670 | BIT(NL80211_STA_FLAG_MFP); |
| 4671 | break; |
| 4672 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4673 | case NL80211_IFTYPE_STATION: |
| 4674 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4675 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4676 | break; |
| 4677 | case NL80211_IFTYPE_MESH_POINT: |
| 4678 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4679 | BIT(NL80211_STA_FLAG_MFP) | |
| 4680 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
Bernd Edlinger | 5cf3006 | 2018-07-08 09:57:22 +0000 | [diff] [blame] | 4681 | break; |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4682 | default: |
| 4683 | return -EINVAL; |
| 4684 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4685 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4686 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 4687 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4688 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4689 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4690 | /* no longer support new API additions in old API */ |
| 4691 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 4692 | return -EINVAL; |
| 4693 | } |
| 4694 | } |
| 4695 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4696 | return 0; |
| 4697 | } |
| 4698 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 4699 | 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] | 4700 | { |
| 4701 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4702 | u32 bitrate; |
| 4703 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 4704 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4705 | |
| 4706 | rate = nla_nest_start(msg, attr); |
| 4707 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4708 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4709 | |
| 4710 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 4711 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4712 | /* report 16-bit bitrate only if we can */ |
| 4713 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4714 | if (bitrate > 0 && |
| 4715 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 4716 | return false; |
| 4717 | if (bitrate_compat > 0 && |
| 4718 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 4719 | return false; |
| 4720 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4721 | switch (info->bw) { |
| 4722 | case RATE_INFO_BW_5: |
| 4723 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 4724 | break; |
| 4725 | case RATE_INFO_BW_10: |
| 4726 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 4727 | break; |
| 4728 | default: |
| 4729 | WARN_ON(1); |
| 4730 | /* fall through */ |
| 4731 | case RATE_INFO_BW_20: |
| 4732 | rate_flg = 0; |
| 4733 | break; |
| 4734 | case RATE_INFO_BW_40: |
| 4735 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 4736 | break; |
| 4737 | case RATE_INFO_BW_80: |
| 4738 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 4739 | break; |
| 4740 | case RATE_INFO_BW_160: |
| 4741 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 4742 | break; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 4743 | case RATE_INFO_BW_HE_RU: |
| 4744 | rate_flg = 0; |
| 4745 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 4749 | return false; |
| 4750 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4751 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 4752 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 4753 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4754 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4755 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4756 | return false; |
| 4757 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 4758 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 4759 | return false; |
| 4760 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 4761 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4762 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4763 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4764 | return false; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 4765 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { |
| 4766 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) |
| 4767 | return false; |
| 4768 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) |
| 4769 | return false; |
| 4770 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) |
| 4771 | return false; |
| 4772 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) |
| 4773 | return false; |
| 4774 | if (info->bw == RATE_INFO_BW_HE_RU && |
| 4775 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, |
| 4776 | info->he_ru_alloc)) |
| 4777 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4778 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4779 | |
| 4780 | nla_nest_end(msg, rate); |
| 4781 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4782 | } |
| 4783 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4784 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 4785 | int id) |
| 4786 | { |
| 4787 | void *attr; |
| 4788 | int i = 0; |
| 4789 | |
| 4790 | if (!mask) |
| 4791 | return true; |
| 4792 | |
| 4793 | attr = nla_nest_start(msg, id); |
| 4794 | if (!attr) |
| 4795 | return false; |
| 4796 | |
| 4797 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 4798 | if (!(mask & BIT(i))) |
| 4799 | continue; |
| 4800 | |
| 4801 | if (nla_put_u8(msg, i, signal[i])) |
| 4802 | return false; |
| 4803 | } |
| 4804 | |
| 4805 | nla_nest_end(msg, attr); |
| 4806 | |
| 4807 | return true; |
| 4808 | } |
| 4809 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4810 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 4811 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4812 | struct cfg80211_registered_device *rdev, |
| 4813 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 4814 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4815 | { |
| 4816 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4817 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4818 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4819 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4820 | if (!hdr) |
| 4821 | return -1; |
| 4822 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4823 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4824 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 4825 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 4826 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4827 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4828 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 4829 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4830 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4831 | |
| 4832 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4833 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 4834 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4835 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 4836 | sinfo->memb)) \ |
| 4837 | goto nla_put_failure; \ |
| 4838 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4839 | #define PUT_SINFO_U64(attr, memb) do { \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 4840 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4841 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 4842 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 4843 | goto nla_put_failure; \ |
| 4844 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4845 | |
| 4846 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 4847 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 4848 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 4849 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | |
| 4850 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4851 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4852 | (u32)sinfo->rx_bytes)) |
| 4853 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4854 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 4855 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | |
| 4856 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4857 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 4858 | (u32)sinfo->tx_bytes)) |
| 4859 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4860 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4861 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 4862 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4863 | PUT_SINFO(LLID, llid, u16); |
| 4864 | PUT_SINFO(PLID, plid, u16); |
| 4865 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4866 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 4867 | PUT_SINFO_U64(TX_DURATION, tx_duration); |
| 4868 | |
| 4869 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 4870 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 4871 | PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4872 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4873 | switch (rdev->wiphy.signal_type) { |
| 4874 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4875 | PUT_SINFO(SIGNAL, signal, u8); |
| 4876 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4877 | break; |
| 4878 | default: |
| 4879 | break; |
| 4880 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 4881 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4882 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4883 | sinfo->chain_signal, |
| 4884 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 4885 | goto nla_put_failure; |
| 4886 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 4887 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4888 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4889 | sinfo->chain_signal_avg, |
| 4890 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 4891 | goto nla_put_failure; |
| 4892 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 4893 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4894 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 4895 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4896 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4897 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 4898 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4899 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 4900 | NL80211_STA_INFO_RX_BITRATE)) |
| 4901 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4902 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4903 | |
| 4904 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 4905 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 4906 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 4907 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 4908 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 4909 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 4910 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 4911 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 4912 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
Bob Copeland | dbdaee7 | 2018-10-25 15:48:53 -0400 | [diff] [blame] | 4913 | PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4914 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 4915 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4916 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 4917 | if (!bss_param) |
| 4918 | goto nla_put_failure; |
| 4919 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4920 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 4921 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 4922 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 4923 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 4924 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 4925 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 4926 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 4927 | sinfo->bss_param.dtim_period) || |
| 4928 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 4929 | sinfo->bss_param.beacon_interval)) |
| 4930 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4931 | |
| 4932 | nla_nest_end(msg, bss_param); |
| 4933 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 4934 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4935 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 4936 | sizeof(struct nl80211_sta_flag_update), |
| 4937 | &sinfo->sta_flags)) |
| 4938 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4939 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4940 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 4941 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 4942 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 4943 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Ankita Bajaj | 0d4e14a | 2018-09-27 18:01:57 +0300 | [diff] [blame] | 4944 | PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); |
| 4945 | PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); |
Balaji Pothunoori | 81d5439 | 2018-04-16 20:18:40 +0530 | [diff] [blame] | 4946 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
Balaji Pothunoori | 9c06602 | 2018-07-19 18:56:27 +0530 | [diff] [blame] | 4947 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { |
| 4948 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); |
| 4949 | PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); |
| 4950 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4951 | |
| 4952 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4953 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4954 | |
Arend van Spriel | 8689c05 | 2018-05-10 13:50:12 +0200 | [diff] [blame] | 4955 | if (sinfo->pertid) { |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4956 | struct nlattr *tidsattr; |
| 4957 | int tid; |
| 4958 | |
| 4959 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 4960 | if (!tidsattr) |
| 4961 | goto nla_put_failure; |
| 4962 | |
| 4963 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 4964 | struct cfg80211_tid_stats *tidstats; |
| 4965 | struct nlattr *tidattr; |
| 4966 | |
| 4967 | tidstats = &sinfo->pertid[tid]; |
| 4968 | |
| 4969 | if (!tidstats->filled) |
| 4970 | continue; |
| 4971 | |
| 4972 | tidattr = nla_nest_start(msg, tid + 1); |
| 4973 | if (!tidattr) |
| 4974 | goto nla_put_failure; |
| 4975 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4976 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4977 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4978 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 4979 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4980 | goto nla_put_failure; \ |
| 4981 | } while (0) |
| 4982 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4983 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 4984 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 4985 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 4986 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4987 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4988 | #undef PUT_TIDVAL_U64 |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 4989 | if ((tidstats->filled & |
| 4990 | BIT(NL80211_TID_STATS_TXQ_STATS)) && |
| 4991 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, |
| 4992 | NL80211_TID_STATS_TXQ_STATS)) |
| 4993 | goto nla_put_failure; |
| 4994 | |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4995 | nla_nest_end(msg, tidattr); |
| 4996 | } |
| 4997 | |
| 4998 | nla_nest_end(msg, tidsattr); |
| 4999 | } |
| 5000 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5001 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5002 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5003 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5004 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 5005 | sinfo->assoc_req_ies)) |
| 5006 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 5007 | |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5008 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5009 | genlmsg_end(msg, hdr); |
| 5010 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5011 | |
| 5012 | nla_put_failure: |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5013 | cfg80211_sinfo_release_content(sinfo); |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5014 | genlmsg_cancel(msg, hdr); |
| 5015 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5016 | } |
| 5017 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5018 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5019 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5020 | { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5021 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5022 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5023 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5024 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5025 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5026 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5027 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5028 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 5029 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5030 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5031 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5032 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5033 | if (!wdev->netdev) { |
| 5034 | err = -EINVAL; |
| 5035 | goto out_err; |
| 5036 | } |
| 5037 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5038 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5039 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5040 | goto out_err; |
| 5041 | } |
| 5042 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5043 | while (1) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5044 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5045 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5046 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5047 | if (err == -ENOENT) |
| 5048 | break; |
| 5049 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5050 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5051 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5052 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5053 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5054 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5055 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5056 | &sinfo) < 0) |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5057 | goto out; |
| 5058 | |
| 5059 | sta_idx++; |
| 5060 | } |
| 5061 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5062 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5063 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5064 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5065 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5066 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5067 | |
| 5068 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5069 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5070 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5071 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 5072 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5073 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5074 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5075 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5076 | struct sk_buff *msg; |
| 5077 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5078 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5079 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5080 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5081 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5082 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5083 | return -EINVAL; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5084 | |
| 5085 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5086 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5087 | if (!rdev->ops->get_station) |
| 5088 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5089 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5090 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5091 | if (err) |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5092 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5093 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5094 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5095 | if (!msg) { |
Denis Kenzior | ba8f566 | 2018-05-21 19:21:42 -0500 | [diff] [blame] | 5096 | cfg80211_sinfo_release_content(&sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5097 | return -ENOMEM; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5098 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5099 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5100 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 5101 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5102 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5103 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5104 | return -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5105 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5106 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5107 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5108 | } |
| 5109 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5110 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 5111 | struct station_parameters *params, |
| 5112 | enum cfg80211_station_type statype) |
| 5113 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5114 | if (params->listen_interval != -1 && |
| 5115 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5116 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5117 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5118 | if (params->support_p2p_ps != -1 && |
| 5119 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 5120 | return -EINVAL; |
| 5121 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 5122 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5123 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 5124 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5125 | return -EINVAL; |
| 5126 | |
| 5127 | /* When you run into this, adjust the code below for the new flag */ |
| 5128 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5129 | |
| 5130 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5131 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 5132 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5133 | /* |
| 5134 | * No ignoring the TDLS flag here -- the userspace mesh |
| 5135 | * code doesn't have the bug of including TDLS in the |
| 5136 | * mask everywhere. |
| 5137 | */ |
| 5138 | if (params->sta_flags_mask & |
| 5139 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5140 | BIT(NL80211_STA_FLAG_MFP) | |
| 5141 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5142 | return -EINVAL; |
| 5143 | break; |
| 5144 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5145 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5146 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5147 | return -EINVAL; |
| 5148 | /* ignore since it can't change */ |
| 5149 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5150 | break; |
| 5151 | default: |
| 5152 | /* disallow mesh-specific things */ |
| 5153 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 5154 | return -EINVAL; |
| 5155 | if (params->local_pm) |
| 5156 | return -EINVAL; |
| 5157 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5158 | return -EINVAL; |
| 5159 | } |
| 5160 | |
| 5161 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5162 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 5163 | /* TDLS can't be set, ... */ |
| 5164 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 5165 | return -EINVAL; |
| 5166 | /* |
| 5167 | * ... but don't bother the driver with it. This works around |
| 5168 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 5169 | * TLDS_PEER flag in the mask even for AP mode. |
| 5170 | */ |
| 5171 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5172 | } |
| 5173 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5174 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5175 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5176 | /* reject other things that can't change */ |
| 5177 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 5178 | return -EINVAL; |
| 5179 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 5180 | return -EINVAL; |
| 5181 | if (params->supported_rates) |
| 5182 | return -EINVAL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5183 | if (params->ext_capab || params->ht_capa || params->vht_capa || |
| 5184 | params->he_capa) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5185 | return -EINVAL; |
| 5186 | } |
| 5187 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5188 | if (statype != CFG80211_STA_AP_CLIENT && |
| 5189 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5190 | if (params->vlan) |
| 5191 | return -EINVAL; |
| 5192 | } |
| 5193 | |
| 5194 | switch (statype) { |
| 5195 | case CFG80211_STA_AP_MLME_CLIENT: |
| 5196 | /* Use this only for authorizing/unauthorizing a station */ |
| 5197 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5198 | return -EOPNOTSUPP; |
| 5199 | break; |
| 5200 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5201 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5202 | /* accept only the listed bits */ |
| 5203 | if (params->sta_flags_mask & |
| 5204 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5205 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5206 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5207 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5208 | BIT(NL80211_STA_FLAG_WME) | |
| 5209 | BIT(NL80211_STA_FLAG_MFP))) |
| 5210 | return -EINVAL; |
| 5211 | |
| 5212 | /* but authenticated/associated only if driver handles it */ |
| 5213 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 5214 | params->sta_flags_mask & |
| 5215 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5216 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 5217 | return -EINVAL; |
| 5218 | break; |
| 5219 | case CFG80211_STA_IBSS: |
| 5220 | case CFG80211_STA_AP_STA: |
| 5221 | /* reject any changes other than AUTHORIZED */ |
| 5222 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 5223 | return -EINVAL; |
| 5224 | break; |
| 5225 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5226 | /* reject any changes other than AUTHORIZED or WME */ |
| 5227 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5228 | BIT(NL80211_STA_FLAG_WME))) |
| 5229 | return -EINVAL; |
| 5230 | /* force (at least) rates when authorizing */ |
| 5231 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 5232 | !params->supported_rates) |
| 5233 | return -EINVAL; |
| 5234 | break; |
| 5235 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5236 | /* reject any changes */ |
| 5237 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5238 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5239 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5240 | return -EINVAL; |
| 5241 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5242 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 5243 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 5244 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5245 | return -EINVAL; |
| 5246 | break; |
| 5247 | } |
| 5248 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 5249 | /* |
| 5250 | * Older kernel versions ignored this attribute entirely, so don't |
| 5251 | * reject attempts to update it but mark it as unused instead so the |
| 5252 | * driver won't look at the data. |
| 5253 | */ |
| 5254 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 5255 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 5256 | params->opmode_notif_used = false; |
| 5257 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5258 | return 0; |
| 5259 | } |
| 5260 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 5261 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5262 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 5263 | * 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] | 5264 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5265 | static struct net_device *get_vlan(struct genl_info *info, |
| 5266 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5267 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5268 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5269 | struct net_device *v; |
| 5270 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5271 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5272 | if (!vlanattr) |
| 5273 | return NULL; |
| 5274 | |
| 5275 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 5276 | if (!v) |
| 5277 | return ERR_PTR(-ENODEV); |
| 5278 | |
| 5279 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 5280 | ret = -EINVAL; |
| 5281 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5282 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5283 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5284 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5285 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5286 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 5287 | ret = -EINVAL; |
| 5288 | goto error; |
| 5289 | } |
| 5290 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5291 | if (!netif_running(v)) { |
| 5292 | ret = -ENETDOWN; |
| 5293 | goto error; |
| 5294 | } |
| 5295 | |
| 5296 | return v; |
| 5297 | error: |
| 5298 | dev_put(v); |
| 5299 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5300 | } |
| 5301 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 5302 | static const struct nla_policy |
| 5303 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5304 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 5305 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 5306 | }; |
| 5307 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5308 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 5309 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5310 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5311 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 5312 | struct nlattr *nla; |
| 5313 | int err; |
| 5314 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5315 | /* parse WME attributes if present */ |
| 5316 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 5317 | return 0; |
| 5318 | |
| 5319 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 5320 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 5321 | nl80211_sta_wme_policy, info->extack); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5322 | if (err) |
| 5323 | return err; |
| 5324 | |
| 5325 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 5326 | params->uapsd_queues = nla_get_u8( |
| 5327 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 5328 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 5329 | return -EINVAL; |
| 5330 | |
| 5331 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 5332 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 5333 | |
| 5334 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 5335 | return -EINVAL; |
| 5336 | |
| 5337 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 5338 | |
| 5339 | return 0; |
| 5340 | } |
| 5341 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5342 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 5343 | struct station_parameters *params) |
| 5344 | { |
| 5345 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 5346 | params->supported_channels = |
| 5347 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 5348 | params->supported_channels_len = |
| 5349 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 5350 | /* |
| 5351 | * Need to include at least one (first channel, number of |
| 5352 | * channels) tuple for each subband, and must have proper |
| 5353 | * tuples for the rest of the data as well. |
| 5354 | */ |
| 5355 | if (params->supported_channels_len < 2) |
| 5356 | return -EINVAL; |
| 5357 | if (params->supported_channels_len % 2) |
| 5358 | return -EINVAL; |
| 5359 | } |
| 5360 | |
| 5361 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 5362 | params->supported_oper_classes = |
| 5363 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 5364 | params->supported_oper_classes_len = |
| 5365 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 5366 | /* |
| 5367 | * The value of the Length field of the Supported Operating |
| 5368 | * Classes element is between 2 and 253. |
| 5369 | */ |
| 5370 | if (params->supported_oper_classes_len < 2 || |
| 5371 | params->supported_oper_classes_len > 253) |
| 5372 | return -EINVAL; |
| 5373 | } |
| 5374 | return 0; |
| 5375 | } |
| 5376 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5377 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 5378 | struct station_parameters *params) |
| 5379 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5380 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5381 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5382 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 5383 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5384 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 5385 | params->ht_capa = |
| 5386 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5387 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 5388 | params->vht_capa = |
| 5389 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5390 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 5391 | params->he_capa = |
| 5392 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5393 | params->he_capa_len = |
| 5394 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5395 | |
| 5396 | if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) |
| 5397 | return -EINVAL; |
| 5398 | } |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5399 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5400 | err = nl80211_parse_sta_channel_info(info, params); |
| 5401 | if (err) |
| 5402 | return err; |
| 5403 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5404 | return nl80211_parse_sta_wme(info, params); |
| 5405 | } |
| 5406 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5407 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 5408 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5409 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5410 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5411 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5412 | u8 *mac_addr; |
| 5413 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5414 | |
| 5415 | memset(¶ms, 0, sizeof(params)); |
| 5416 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5417 | if (!rdev->ops->change_station) |
| 5418 | return -EOPNOTSUPP; |
| 5419 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5420 | /* |
| 5421 | * AID and listen_interval properties can be set only for unassociated |
| 5422 | * station. Include these parameters here and will check them in |
| 5423 | * cfg80211_check_station_change(). |
| 5424 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 5425 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 5426 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5427 | |
| 5428 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 5429 | params.listen_interval = |
| 5430 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 5431 | else |
| 5432 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5433 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5434 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) |
| 5435 | params.support_p2p_ps = |
| 5436 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 5437 | else |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5438 | params.support_p2p_ps = -1; |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5439 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5440 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5441 | return -EINVAL; |
| 5442 | |
| 5443 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5444 | |
| 5445 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 5446 | params.supported_rates = |
| 5447 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5448 | params.supported_rates_len = |
| 5449 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5450 | } |
| 5451 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 5452 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 5453 | params.capability = |
| 5454 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 5455 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 5456 | } |
| 5457 | |
| 5458 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 5459 | params.ext_capab = |
| 5460 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5461 | params.ext_capab_len = |
| 5462 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5463 | } |
| 5464 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5465 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5466 | return -EINVAL; |
| 5467 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5468 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5469 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5470 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5471 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5472 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 5473 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5474 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5475 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 5476 | params.peer_aid = nla_get_u16( |
| 5477 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5478 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 5479 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 5480 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5481 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) |
| 5482 | params.local_pm = nla_get_u32( |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5483 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 5484 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 5485 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 5486 | params.opmode_notif_used = true; |
| 5487 | params.opmode_notif = |
| 5488 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 5489 | } |
| 5490 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 5491 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 5492 | params.airtime_weight = |
| 5493 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 5494 | |
| 5495 | if (params.airtime_weight && |
| 5496 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5497 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 5498 | return -EOPNOTSUPP; |
| 5499 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5500 | /* Include parameters for TDLS peer (will check later) */ |
| 5501 | err = nl80211_set_station_tdls(info, ¶ms); |
| 5502 | if (err) |
| 5503 | return err; |
| 5504 | |
| 5505 | params.vlan = get_vlan(info, rdev); |
| 5506 | if (IS_ERR(params.vlan)) |
| 5507 | return PTR_ERR(params.vlan); |
| 5508 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5509 | switch (dev->ieee80211_ptr->iftype) { |
| 5510 | case NL80211_IFTYPE_AP: |
| 5511 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5512 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5513 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5514 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5515 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5516 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5517 | break; |
| 5518 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5519 | err = -EOPNOTSUPP; |
| 5520 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 5521 | } |
| 5522 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5523 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5524 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5525 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5526 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5527 | if (params.vlan) |
| 5528 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5529 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5530 | return err; |
| 5531 | } |
| 5532 | |
| 5533 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 5534 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5535 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5536 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5537 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5538 | struct station_parameters params; |
| 5539 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5540 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5541 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5542 | |
| 5543 | memset(¶ms, 0, sizeof(params)); |
| 5544 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5545 | if (!rdev->ops->add_station) |
| 5546 | return -EOPNOTSUPP; |
| 5547 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5548 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5549 | return -EINVAL; |
| 5550 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5551 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 5552 | return -EINVAL; |
| 5553 | |
| 5554 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 5555 | return -EINVAL; |
| 5556 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5557 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 5558 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 5559 | return -EINVAL; |
| 5560 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5561 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5562 | params.supported_rates = |
| 5563 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5564 | params.supported_rates_len = |
| 5565 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5566 | params.listen_interval = |
| 5567 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5568 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5569 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5570 | params.support_p2p_ps = |
| 5571 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5572 | } else { |
| 5573 | /* |
| 5574 | * if not specified, assume it's supported for P2P GO interface, |
| 5575 | * and is NOT supported for AP interface |
| 5576 | */ |
| 5577 | params.support_p2p_ps = |
| 5578 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 5579 | } |
| 5580 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5581 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5582 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5583 | else |
| 5584 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5585 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 5586 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 5587 | params.capability = |
| 5588 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 5589 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 5590 | } |
| 5591 | |
| 5592 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 5593 | params.ext_capab = |
| 5594 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5595 | params.ext_capab_len = |
| 5596 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5597 | } |
| 5598 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 5599 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 5600 | params.ht_capa = |
| 5601 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5602 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 5603 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 5604 | params.vht_capa = |
| 5605 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 5606 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5607 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 5608 | params.he_capa = |
| 5609 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5610 | params.he_capa_len = |
| 5611 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5612 | |
| 5613 | /* max len is validated in nla policy */ |
| 5614 | if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) |
| 5615 | return -EINVAL; |
| 5616 | } |
| 5617 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 5618 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 5619 | params.opmode_notif_used = true; |
| 5620 | params.opmode_notif = |
| 5621 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 5622 | } |
| 5623 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5624 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5625 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5626 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5627 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 5628 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 5629 | params.airtime_weight = |
| 5630 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 5631 | |
| 5632 | if (params.airtime_weight && |
| 5633 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5634 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 5635 | return -EOPNOTSUPP; |
| 5636 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5637 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 5638 | if (err) |
| 5639 | return err; |
| 5640 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5641 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 5642 | if (err) |
| 5643 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5644 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5645 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5646 | return -EINVAL; |
| 5647 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 5648 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 5649 | * as userspace might just pass through the capabilities from the IEs |
| 5650 | * directly, rather than enforcing this restriction and returning an |
| 5651 | * error in this case. |
| 5652 | */ |
| 5653 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 5654 | params.ht_capa = NULL; |
| 5655 | params.vht_capa = NULL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5656 | |
| 5657 | /* HE requires WME */ |
| 5658 | if (params.he_capa_len) |
| 5659 | return -EINVAL; |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 5660 | } |
| 5661 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5662 | /* When you run into this, adjust the code below for the new flag */ |
| 5663 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5664 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5665 | switch (dev->ieee80211_ptr->iftype) { |
| 5666 | case NL80211_IFTYPE_AP: |
| 5667 | case NL80211_IFTYPE_AP_VLAN: |
| 5668 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5669 | /* ignore WME attributes if iface/sta is not capable */ |
| 5670 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 5671 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 5672 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5673 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5674 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5675 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5676 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5677 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5678 | /* but don't bother the driver with it */ |
| 5679 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5680 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5681 | /* allow authenticated/associated only if driver handles it */ |
| 5682 | if (!(rdev->wiphy.features & |
| 5683 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5684 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5685 | return -EINVAL; |
| 5686 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5687 | /* Older userspace, or userspace wanting to be compatible with |
| 5688 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 5689 | * and assoc flags in the mask, but assumes the station will be |
| 5690 | * added as associated anyway since this was the required driver |
| 5691 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 5692 | * introduced. |
| 5693 | * In order to not bother drivers with this quirk in the API |
| 5694 | * set the flags in both the mask and set for new stations in |
| 5695 | * this case. |
| 5696 | */ |
| 5697 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 5698 | params.sta_flags_mask |= auth_assoc; |
| 5699 | params.sta_flags_set |= auth_assoc; |
| 5700 | } |
| 5701 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5702 | /* must be last in here for error handling */ |
| 5703 | params.vlan = get_vlan(info, rdev); |
| 5704 | if (IS_ERR(params.vlan)) |
| 5705 | return PTR_ERR(params.vlan); |
| 5706 | break; |
| 5707 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5708 | /* ignore uAPSD data */ |
| 5709 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5710 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5711 | /* associated is disallowed */ |
| 5712 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 5713 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5714 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5715 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5716 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5717 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5718 | break; |
| 5719 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 5720 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5721 | /* ignore uAPSD data */ |
| 5722 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5723 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5724 | /* these are disallowed */ |
| 5725 | if (params.sta_flags_mask & |
| 5726 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5727 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5728 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5729 | /* Only TDLS peers can be added */ |
| 5730 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5731 | return -EINVAL; |
| 5732 | /* Can only add if TDLS ... */ |
| 5733 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 5734 | return -EOPNOTSUPP; |
| 5735 | /* ... with external setup is supported */ |
| 5736 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 5737 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5738 | /* |
| 5739 | * Older wpa_supplicant versions always mark the TDLS peer |
| 5740 | * as authorized, but it shouldn't yet be. |
| 5741 | */ |
| 5742 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5743 | break; |
| 5744 | default: |
| 5745 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5746 | } |
| 5747 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5748 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5749 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5750 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5751 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5752 | if (params.vlan) |
| 5753 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5754 | return err; |
| 5755 | } |
| 5756 | |
| 5757 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 5758 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5759 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5760 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5761 | struct station_del_parameters params; |
| 5762 | |
| 5763 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5764 | |
| 5765 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5766 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5767 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5768 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 5769 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5770 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5771 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5772 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5774 | if (!rdev->ops->del_station) |
| 5775 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5776 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 5777 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 5778 | params.subtype = |
| 5779 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 5780 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 5781 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 5782 | return -EINVAL; |
| 5783 | } else { |
| 5784 | /* Default to Deauthentication frame */ |
| 5785 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 5786 | } |
| 5787 | |
| 5788 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 5789 | params.reason_code = |
| 5790 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5791 | if (params.reason_code == 0) |
| 5792 | return -EINVAL; /* 0 is reserved */ |
| 5793 | } else { |
| 5794 | /* Default to reason code 2 */ |
| 5795 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 5796 | } |
| 5797 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5798 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5799 | } |
| 5800 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5801 | 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] | 5802 | int flags, struct net_device *dev, |
| 5803 | u8 *dst, u8 *next_hop, |
| 5804 | struct mpath_info *pinfo) |
| 5805 | { |
| 5806 | void *hdr; |
| 5807 | struct nlattr *pinfoattr; |
| 5808 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 5809 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5810 | if (!hdr) |
| 5811 | return -1; |
| 5812 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5813 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5814 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 5815 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 5816 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 5817 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5818 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5819 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 5820 | if (!pinfoattr) |
| 5821 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5822 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 5823 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 5824 | pinfo->frame_qlen)) |
| 5825 | goto nla_put_failure; |
| 5826 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 5827 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 5828 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 5829 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 5830 | pinfo->metric)) || |
| 5831 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 5832 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 5833 | pinfo->exptime)) || |
| 5834 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 5835 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 5836 | pinfo->flags)) || |
| 5837 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 5838 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 5839 | pinfo->discovery_timeout)) || |
| 5840 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 5841 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
Julan Hsu | cc24163 | 2019-01-15 15:28:42 -0800 | [diff] [blame] | 5842 | pinfo->discovery_retries)) || |
| 5843 | ((pinfo->filled & MPATH_INFO_HOP_COUNT) && |
| 5844 | nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, |
Julan Hsu | 540bbcb | 2019-01-15 15:28:43 -0800 | [diff] [blame] | 5845 | pinfo->hop_count)) || |
| 5846 | ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && |
| 5847 | nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, |
| 5848 | pinfo->path_change_count))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5849 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5850 | |
| 5851 | nla_nest_end(msg, pinfoattr); |
| 5852 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5853 | genlmsg_end(msg, hdr); |
| 5854 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5855 | |
| 5856 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5857 | genlmsg_cancel(msg, hdr); |
| 5858 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5862 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5863 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5864 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5865 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5866 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5867 | u8 dst[ETH_ALEN]; |
| 5868 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5869 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5870 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5871 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5872 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 5873 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5874 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5875 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5876 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5877 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5878 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5879 | goto out_err; |
| 5880 | } |
| 5881 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5882 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5883 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 5884 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5885 | } |
| 5886 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5887 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5888 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5889 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5890 | if (err == -ENOENT) |
| 5891 | break; |
| 5892 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5893 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5894 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5895 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5896 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5897 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5898 | &pinfo) < 0) |
| 5899 | goto out; |
| 5900 | |
| 5901 | path_idx++; |
| 5902 | } |
| 5903 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5904 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5905 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5906 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5907 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5908 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5909 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5913 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5915 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5916 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5917 | struct mpath_info pinfo; |
| 5918 | struct sk_buff *msg; |
| 5919 | u8 *dst = NULL; |
| 5920 | u8 next_hop[ETH_ALEN]; |
| 5921 | |
| 5922 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5923 | |
| 5924 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5925 | return -EINVAL; |
| 5926 | |
| 5927 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5928 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5929 | if (!rdev->ops->get_mpath) |
| 5930 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5931 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5932 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5933 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5934 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5935 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5936 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5937 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5938 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5939 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5940 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5941 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5942 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5943 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5944 | dev, dst, next_hop, &pinfo) < 0) { |
| 5945 | nlmsg_free(msg); |
| 5946 | return -ENOBUFS; |
| 5947 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5948 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5949 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5950 | } |
| 5951 | |
| 5952 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5953 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5954 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5955 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5956 | u8 *dst = NULL; |
| 5957 | u8 *next_hop = NULL; |
| 5958 | |
| 5959 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5960 | return -EINVAL; |
| 5961 | |
| 5962 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5963 | return -EINVAL; |
| 5964 | |
| 5965 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5966 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5967 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5968 | if (!rdev->ops->change_mpath) |
| 5969 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5970 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5971 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5972 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5973 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5974 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5975 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5976 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5977 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5978 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5979 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5980 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5981 | u8 *dst = NULL; |
| 5982 | u8 *next_hop = NULL; |
| 5983 | |
| 5984 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5985 | return -EINVAL; |
| 5986 | |
| 5987 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5988 | return -EINVAL; |
| 5989 | |
| 5990 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5991 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5992 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5993 | if (!rdev->ops->add_mpath) |
| 5994 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5995 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5996 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5997 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5998 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5999 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6000 | } |
| 6001 | |
| 6002 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6003 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6005 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6006 | u8 *dst = NULL; |
| 6007 | |
| 6008 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6009 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6010 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6011 | if (!rdev->ops->del_mpath) |
| 6012 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6013 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6014 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6015 | } |
| 6016 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6017 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 6018 | { |
| 6019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6020 | int err; |
| 6021 | struct net_device *dev = info->user_ptr[1]; |
| 6022 | struct mpath_info pinfo; |
| 6023 | struct sk_buff *msg; |
| 6024 | u8 *dst = NULL; |
| 6025 | u8 mpp[ETH_ALEN]; |
| 6026 | |
| 6027 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6028 | |
| 6029 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6030 | return -EINVAL; |
| 6031 | |
| 6032 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6033 | |
| 6034 | if (!rdev->ops->get_mpp) |
| 6035 | return -EOPNOTSUPP; |
| 6036 | |
| 6037 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6038 | return -EOPNOTSUPP; |
| 6039 | |
| 6040 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 6041 | if (err) |
| 6042 | return err; |
| 6043 | |
| 6044 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6045 | if (!msg) |
| 6046 | return -ENOMEM; |
| 6047 | |
| 6048 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 6049 | dev, dst, mpp, &pinfo) < 0) { |
| 6050 | nlmsg_free(msg); |
| 6051 | return -ENOBUFS; |
| 6052 | } |
| 6053 | |
| 6054 | return genlmsg_reply(msg, info); |
| 6055 | } |
| 6056 | |
| 6057 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 6058 | struct netlink_callback *cb) |
| 6059 | { |
| 6060 | struct mpath_info pinfo; |
| 6061 | struct cfg80211_registered_device *rdev; |
| 6062 | struct wireless_dev *wdev; |
| 6063 | u8 dst[ETH_ALEN]; |
| 6064 | u8 mpp[ETH_ALEN]; |
| 6065 | int path_idx = cb->args[2]; |
| 6066 | int err; |
| 6067 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6068 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 6069 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6070 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6071 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6072 | |
| 6073 | if (!rdev->ops->dump_mpp) { |
| 6074 | err = -EOPNOTSUPP; |
| 6075 | goto out_err; |
| 6076 | } |
| 6077 | |
| 6078 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 6079 | err = -EOPNOTSUPP; |
| 6080 | goto out_err; |
| 6081 | } |
| 6082 | |
| 6083 | while (1) { |
| 6084 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 6085 | mpp, &pinfo); |
| 6086 | if (err == -ENOENT) |
| 6087 | break; |
| 6088 | if (err) |
| 6089 | goto out_err; |
| 6090 | |
| 6091 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 6092 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6093 | wdev->netdev, dst, mpp, |
| 6094 | &pinfo) < 0) |
| 6095 | goto out; |
| 6096 | |
| 6097 | path_idx++; |
| 6098 | } |
| 6099 | |
| 6100 | out: |
| 6101 | cb->args[2] = path_idx; |
| 6102 | err = skb->len; |
| 6103 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6104 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6105 | return err; |
| 6106 | } |
| 6107 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6108 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 6109 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6110 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6111 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6112 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6113 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6114 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6115 | |
| 6116 | memset(¶ms, 0, sizeof(params)); |
| 6117 | /* default to not changing parameters */ |
| 6118 | params.use_cts_prot = -1; |
| 6119 | params.use_short_preamble = -1; |
| 6120 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 6121 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 6122 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6123 | params.p2p_ctwindow = -1; |
| 6124 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6125 | |
| 6126 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 6127 | params.use_cts_prot = |
| 6128 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 6129 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 6130 | params.use_short_preamble = |
| 6131 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 6132 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 6133 | params.use_short_slot_time = |
| 6134 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 6135 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6136 | params.basic_rates = |
| 6137 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6138 | params.basic_rates_len = |
| 6139 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6140 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 6141 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 6142 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 6143 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 6144 | params.ht_opmode = |
| 6145 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6146 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6147 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 6148 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6149 | return -EINVAL; |
| 6150 | params.p2p_ctwindow = |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6151 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6152 | if (params.p2p_ctwindow != 0 && |
| 6153 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 6154 | return -EINVAL; |
| 6155 | } |
| 6156 | |
| 6157 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 6158 | u8 tmp; |
| 6159 | |
| 6160 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6161 | return -EINVAL; |
| 6162 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6163 | params.p2p_opp_ps = tmp; |
| 6164 | if (params.p2p_opp_ps && |
| 6165 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 6166 | return -EINVAL; |
| 6167 | } |
| 6168 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6169 | if (!rdev->ops->change_bss) |
| 6170 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6171 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6172 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6173 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6174 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6175 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6176 | wdev_lock(wdev); |
| 6177 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 6178 | wdev_unlock(wdev); |
| 6179 | |
| 6180 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6181 | } |
| 6182 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6183 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6184 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6185 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6186 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6187 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6188 | u32 owner_nlportid; |
| 6189 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 6190 | /* |
| 6191 | * You should only get this when cfg80211 hasn't yet initialized |
| 6192 | * completely when built-in to the kernel right between the time |
| 6193 | * window between nl80211_init() and regulatory_init(), if that is |
| 6194 | * even possible. |
| 6195 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6196 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 6197 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 6198 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6199 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 6200 | user_reg_hint_type = |
| 6201 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 6202 | else |
| 6203 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 6204 | |
| 6205 | switch (user_reg_hint_type) { |
| 6206 | case NL80211_USER_REG_HINT_USER: |
| 6207 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 6208 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6209 | return -EINVAL; |
| 6210 | |
| 6211 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6212 | return regulatory_hint_user(data, user_reg_hint_type); |
| 6213 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6214 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 6215 | owner_nlportid = info->snd_portid; |
| 6216 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 6217 | } else { |
| 6218 | owner_nlportid = 0; |
| 6219 | is_indoor = true; |
| 6220 | } |
| 6221 | |
| 6222 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6223 | default: |
| 6224 | return -EINVAL; |
| 6225 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6226 | } |
| 6227 | |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 6228 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
| 6229 | { |
| 6230 | return reg_reload_regdb(); |
| 6231 | } |
| 6232 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6233 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6234 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6235 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6236 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6237 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6238 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6239 | struct mesh_config cur_params; |
| 6240 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6241 | void *hdr; |
| 6242 | struct nlattr *pinfoattr; |
| 6243 | struct sk_buff *msg; |
| 6244 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6245 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6246 | return -EOPNOTSUPP; |
| 6247 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6248 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6249 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 6250 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6251 | wdev_lock(wdev); |
| 6252 | /* If not connected, get default parameters */ |
| 6253 | if (!wdev->mesh_id_len) |
| 6254 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 6255 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6256 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6257 | wdev_unlock(wdev); |
| 6258 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6259 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6260 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6261 | |
| 6262 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6263 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6264 | if (!msg) |
| 6265 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6266 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6267 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6268 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6269 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6270 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6271 | if (!pinfoattr) |
| 6272 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6273 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 6274 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 6275 | cur_params.dot11MeshRetryTimeout) || |
| 6276 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 6277 | cur_params.dot11MeshConfirmTimeout) || |
| 6278 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 6279 | cur_params.dot11MeshHoldingTimeout) || |
| 6280 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 6281 | cur_params.dot11MeshMaxPeerLinks) || |
| 6282 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 6283 | cur_params.dot11MeshMaxRetries) || |
| 6284 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 6285 | cur_params.dot11MeshTTL) || |
| 6286 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 6287 | cur_params.element_ttl) || |
| 6288 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 6289 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 6290 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 6291 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6292 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 6293 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 6294 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 6295 | cur_params.path_refresh_time) || |
| 6296 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 6297 | cur_params.min_discovery_timeout) || |
| 6298 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 6299 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 6300 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 6301 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 6302 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 6303 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 6304 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 6305 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 6306 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 6307 | cur_params.dot11MeshHWMPRootMode) || |
| 6308 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 6309 | cur_params.dot11MeshHWMPRannInterval) || |
| 6310 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 6311 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 6312 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 6313 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 6314 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 6315 | cur_params.rssi_threshold) || |
| 6316 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6317 | cur_params.ht_opmode) || |
| 6318 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 6319 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 6320 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6321 | cur_params.dot11MeshHWMProotInterval) || |
| 6322 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6323 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 6324 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 6325 | cur_params.power_mode) || |
| 6326 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6327 | cur_params.dot11MeshAwakeWindowDuration) || |
| 6328 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 6329 | cur_params.plink_timeout) || |
| 6330 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, |
| 6331 | cur_params.dot11MeshConnectedToMeshGate)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6332 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6333 | nla_nest_end(msg, pinfoattr); |
| 6334 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6335 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6336 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6337 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6338 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6339 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6340 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6341 | } |
| 6342 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6343 | static const struct nla_policy |
| 6344 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
| 6345 | [NL80211_MESHCONF_RETRY_TIMEOUT] = |
| 6346 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 6347 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = |
| 6348 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 6349 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = |
| 6350 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 6351 | [NL80211_MESHCONF_MAX_PEER_LINKS] = |
| 6352 | NLA_POLICY_RANGE(NLA_U16, 0, 255), |
| 6353 | [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), |
| 6354 | [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 6355 | [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 6356 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 6357 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = |
| 6358 | NLA_POLICY_RANGE(NLA_U32, 1, 255), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6359 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 6360 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6361 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6362 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6363 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = |
| 6364 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6365 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = |
| 6366 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6367 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = |
| 6368 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6369 | [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), |
| 6370 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = |
| 6371 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6372 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 6373 | [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), |
| 6374 | [NL80211_MESHCONF_RSSI_THRESHOLD] = |
| 6375 | NLA_POLICY_RANGE(NLA_S32, -255, 0), |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6376 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6377 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6378 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = |
| 6379 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6380 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = |
| 6381 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6382 | [NL80211_MESHCONF_POWER_MODE] = |
| 6383 | NLA_POLICY_RANGE(NLA_U32, |
| 6384 | NL80211_MESH_POWER_ACTIVE, |
| 6385 | NL80211_MESH_POWER_MAX), |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6386 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6387 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 6388 | [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] | 6389 | }; |
| 6390 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6391 | static const struct nla_policy |
| 6392 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6393 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6394 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 6395 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 6396 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6397 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6398 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 6399 | [NL80211_MESH_SETUP_IE] = |
| 6400 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 6401 | IEEE80211_MAX_DATA_LEN), |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6402 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6403 | }; |
| 6404 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6405 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6406 | struct mesh_config *cfg, |
| 6407 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6408 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6409 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6410 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6411 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6412 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6413 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ |
| 6414 | do { \ |
| 6415 | if (tb[attr]) { \ |
| 6416 | cfg->param = fn(tb[attr]); \ |
| 6417 | mask |= BIT((attr) - 1); \ |
| 6418 | } \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6419 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6420 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6421 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6422 | return -EINVAL; |
| 6423 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6424 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6425 | nl80211_meshconf_params_policy, info->extack)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6426 | return -EINVAL; |
| 6427 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6428 | /* This makes sure that there aren't more than 32 mesh config |
| 6429 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 6430 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 6431 | |
| 6432 | /* Fill in the params struct */ |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6433 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, |
| 6434 | NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 6435 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, |
| 6436 | NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 6437 | nla_get_u16); |
| 6438 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, |
| 6439 | NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 6440 | nla_get_u16); |
| 6441 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, |
| 6442 | NL80211_MESHCONF_MAX_PEER_LINKS, |
| 6443 | nla_get_u16); |
| 6444 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, |
| 6445 | NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 6446 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, |
| 6447 | NL80211_MESHCONF_TTL, nla_get_u8); |
| 6448 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, |
| 6449 | NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
| 6450 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, |
| 6451 | NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 6452 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6453 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6454 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6455 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6456 | nla_get_u32); |
| 6457 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, |
| 6458 | NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 6459 | nla_get_u8); |
| 6460 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, |
| 6461 | NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 6462 | nla_get_u32); |
| 6463 | if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && |
| 6464 | (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) |
| 6465 | return -EINVAL; |
| 6466 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, |
| 6467 | NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 6468 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6469 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6470 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6471 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6472 | nla_get_u32); |
| 6473 | if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && |
| 6474 | (cfg->dot11MeshHWMPactivePathTimeout < 1 || |
| 6475 | cfg->dot11MeshHWMPactivePathTimeout > 65535)) |
| 6476 | return -EINVAL; |
| 6477 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6478 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6479 | nla_get_u16); |
| 6480 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6481 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6482 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6483 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6484 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6485 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6486 | nla_get_u16); |
| 6487 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 6488 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 6489 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 6490 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 6491 | nla_get_u16); |
| 6492 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6493 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6494 | nla_get_u8); |
| 6495 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, |
| 6496 | NL80211_MESHCONF_FORWARDING, nla_get_u8); |
| 6497 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, |
| 6498 | NL80211_MESHCONF_RSSI_THRESHOLD, |
| 6499 | nla_get_s32); |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 6500 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, |
| 6501 | NL80211_MESHCONF_CONNECTED_TO_GATE, |
| 6502 | nla_get_u8); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6503 | /* |
| 6504 | * Check HT operation mode based on |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 6505 | * IEEE 802.11-2016 9.4.2.57 HT Operation element. |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6506 | */ |
| 6507 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 6508 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 6509 | |
| 6510 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 6511 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 6512 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6513 | return -EINVAL; |
| 6514 | |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 6515 | /* NON_HT_STA bit is reserved, but some programs set it */ |
| 6516 | ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6517 | |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6518 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 6519 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6520 | } |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6521 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6522 | dot11MeshHWMPactivePathToRootTimeout, mask, |
| 6523 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 6524 | nla_get_u32); |
| 6525 | if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && |
| 6526 | (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || |
| 6527 | cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) |
| 6528 | return -EINVAL; |
| 6529 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, |
| 6530 | NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 6531 | nla_get_u16); |
| 6532 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, |
| 6533 | mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6534 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6535 | nla_get_u16); |
| 6536 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, |
| 6537 | NL80211_MESHCONF_POWER_MODE, nla_get_u32); |
| 6538 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, |
| 6539 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
| 6540 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, |
| 6541 | NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6542 | if (mask_out) |
| 6543 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6544 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6545 | return 0; |
| 6546 | |
| 6547 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 6548 | } |
| 6549 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6550 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 6551 | struct mesh_setup *setup) |
| 6552 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6553 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6554 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 6555 | |
| 6556 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 6557 | return -EINVAL; |
| 6558 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 6559 | info->attrs[NL80211_ATTR_MESH_SETUP], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6560 | nl80211_mesh_setup_params_policy, info->extack)) |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6561 | return -EINVAL; |
| 6562 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6563 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 6564 | setup->sync_method = |
| 6565 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 6566 | IEEE80211_SYNC_METHOD_VENDOR : |
| 6567 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 6568 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6569 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 6570 | setup->path_sel_proto = |
| 6571 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 6572 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 6573 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 6574 | |
| 6575 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 6576 | setup->path_metric = |
| 6577 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 6578 | IEEE80211_PATH_METRIC_VENDOR : |
| 6579 | IEEE80211_PATH_METRIC_AIRTIME; |
| 6580 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6581 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6582 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6583 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6584 | setup->ie = nla_data(ieattr); |
| 6585 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6586 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6587 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 6588 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 6589 | return -EINVAL; |
| 6590 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6591 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 6592 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6593 | if (setup->is_secure) |
| 6594 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6595 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6596 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 6597 | if (!setup->user_mpm) |
| 6598 | return -EINVAL; |
| 6599 | setup->auth_id = |
| 6600 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 6601 | } |
| 6602 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6603 | return 0; |
| 6604 | } |
| 6605 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6606 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6607 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6608 | { |
| 6609 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6610 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6611 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6612 | struct mesh_config cfg; |
| 6613 | u32 mask; |
| 6614 | int err; |
| 6615 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6616 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6617 | return -EOPNOTSUPP; |
| 6618 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6619 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6620 | return -EOPNOTSUPP; |
| 6621 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6622 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6623 | if (err) |
| 6624 | return err; |
| 6625 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6626 | wdev_lock(wdev); |
| 6627 | if (!wdev->mesh_id_len) |
| 6628 | err = -ENOLINK; |
| 6629 | |
| 6630 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6631 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6632 | |
| 6633 | wdev_unlock(wdev); |
| 6634 | |
| 6635 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6636 | } |
| 6637 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6638 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 6639 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6640 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6641 | struct nlattr *nl_reg_rules; |
| 6642 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6643 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6644 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 6645 | (regdom->dfs_region && |
| 6646 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6647 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6648 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6649 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 6650 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6651 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6652 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6653 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6654 | struct nlattr *nl_reg_rule; |
| 6655 | const struct ieee80211_reg_rule *reg_rule; |
| 6656 | const struct ieee80211_freq_range *freq_range; |
| 6657 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6658 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6659 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6660 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6661 | freq_range = ®_rule->freq_range; |
| 6662 | power_rule = ®_rule->power_rule; |
| 6663 | |
| 6664 | nl_reg_rule = nla_nest_start(msg, i); |
| 6665 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6666 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6667 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6668 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 6669 | if (!max_bandwidth_khz) |
| 6670 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 6671 | reg_rule); |
| 6672 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6673 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 6674 | reg_rule->flags) || |
| 6675 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 6676 | freq_range->start_freq_khz) || |
| 6677 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 6678 | freq_range->end_freq_khz) || |
| 6679 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6680 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6681 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 6682 | power_rule->max_antenna_gain) || |
| 6683 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 6684 | power_rule->max_eirp) || |
| 6685 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 6686 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6687 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6688 | |
| 6689 | nla_nest_end(msg, nl_reg_rule); |
| 6690 | } |
| 6691 | |
| 6692 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6693 | return 0; |
| 6694 | |
| 6695 | nla_put_failure: |
| 6696 | return -EMSGSIZE; |
| 6697 | } |
| 6698 | |
| 6699 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 6700 | { |
| 6701 | const struct ieee80211_regdomain *regdom = NULL; |
| 6702 | struct cfg80211_registered_device *rdev; |
| 6703 | struct wiphy *wiphy = NULL; |
| 6704 | struct sk_buff *msg; |
| 6705 | void *hdr; |
| 6706 | |
| 6707 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6708 | if (!msg) |
| 6709 | return -ENOBUFS; |
| 6710 | |
| 6711 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 6712 | NL80211_CMD_GET_REG); |
| 6713 | if (!hdr) |
| 6714 | goto put_failure; |
| 6715 | |
| 6716 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6717 | bool self_managed; |
| 6718 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6719 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 6720 | if (IS_ERR(rdev)) { |
| 6721 | nlmsg_free(msg); |
| 6722 | return PTR_ERR(rdev); |
| 6723 | } |
| 6724 | |
| 6725 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6726 | self_managed = wiphy->regulatory_flags & |
| 6727 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6728 | regdom = get_wiphy_regdom(wiphy); |
| 6729 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6730 | /* a self-managed-reg device must have a private regdom */ |
| 6731 | if (WARN_ON(!regdom && self_managed)) { |
| 6732 | nlmsg_free(msg); |
| 6733 | return -EINVAL; |
| 6734 | } |
| 6735 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6736 | if (regdom && |
| 6737 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6738 | goto nla_put_failure; |
| 6739 | } |
| 6740 | |
| 6741 | if (!wiphy && reg_last_request_cell_base() && |
| 6742 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6743 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6744 | goto nla_put_failure; |
| 6745 | |
| 6746 | rcu_read_lock(); |
| 6747 | |
| 6748 | if (!regdom) |
| 6749 | regdom = rcu_dereference(cfg80211_regdomain); |
| 6750 | |
| 6751 | if (nl80211_put_regdom(regdom, msg)) |
| 6752 | goto nla_put_failure_rcu; |
| 6753 | |
| 6754 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6755 | |
| 6756 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6757 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6758 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6759 | nla_put_failure_rcu: |
| 6760 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6761 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6762 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6763 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6764 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6765 | } |
| 6766 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6767 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 6768 | u32 seq, int flags, struct wiphy *wiphy, |
| 6769 | const struct ieee80211_regdomain *regdom) |
| 6770 | { |
| 6771 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 6772 | NL80211_CMD_GET_REG); |
| 6773 | |
| 6774 | if (!hdr) |
| 6775 | return -1; |
| 6776 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 6777 | genl_dump_check_consistent(cb, hdr); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6778 | |
| 6779 | if (nl80211_put_regdom(regdom, msg)) |
| 6780 | goto nla_put_failure; |
| 6781 | |
| 6782 | if (!wiphy && reg_last_request_cell_base() && |
| 6783 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6784 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6785 | goto nla_put_failure; |
| 6786 | |
| 6787 | if (wiphy && |
| 6788 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6789 | goto nla_put_failure; |
| 6790 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6791 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 6792 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 6793 | goto nla_put_failure; |
| 6794 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6795 | genlmsg_end(msg, hdr); |
| 6796 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6797 | |
| 6798 | nla_put_failure: |
| 6799 | genlmsg_cancel(msg, hdr); |
| 6800 | return -EMSGSIZE; |
| 6801 | } |
| 6802 | |
| 6803 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 6804 | struct netlink_callback *cb) |
| 6805 | { |
| 6806 | const struct ieee80211_regdomain *regdom = NULL; |
| 6807 | struct cfg80211_registered_device *rdev; |
| 6808 | int err, reg_idx, start = cb->args[2]; |
| 6809 | |
| 6810 | rtnl_lock(); |
| 6811 | |
| 6812 | if (cfg80211_regdomain && start == 0) { |
| 6813 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6814 | NLM_F_MULTI, NULL, |
| 6815 | rtnl_dereference(cfg80211_regdomain)); |
| 6816 | if (err < 0) |
| 6817 | goto out_err; |
| 6818 | } |
| 6819 | |
| 6820 | /* the global regdom is idx 0 */ |
| 6821 | reg_idx = 1; |
| 6822 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 6823 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 6824 | if (!regdom) |
| 6825 | continue; |
| 6826 | |
| 6827 | if (++reg_idx <= start) |
| 6828 | continue; |
| 6829 | |
| 6830 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6831 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 6832 | if (err < 0) { |
| 6833 | reg_idx--; |
| 6834 | break; |
| 6835 | } |
| 6836 | } |
| 6837 | |
| 6838 | cb->args[2] = reg_idx; |
| 6839 | err = skb->len; |
| 6840 | out_err: |
| 6841 | rtnl_unlock(); |
| 6842 | return err; |
| 6843 | } |
| 6844 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6845 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 6846 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 6847 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6848 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6849 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6850 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6851 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6852 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6853 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 6854 | }; |
| 6855 | |
| 6856 | static int parse_reg_rule(struct nlattr *tb[], |
| 6857 | struct ieee80211_reg_rule *reg_rule) |
| 6858 | { |
| 6859 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 6860 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 6861 | |
| 6862 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6863 | return -EINVAL; |
| 6864 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 6865 | return -EINVAL; |
| 6866 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 6867 | return -EINVAL; |
| 6868 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6869 | return -EINVAL; |
| 6870 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6871 | return -EINVAL; |
| 6872 | |
| 6873 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 6874 | |
| 6875 | freq_range->start_freq_khz = |
| 6876 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 6877 | freq_range->end_freq_khz = |
| 6878 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 6879 | freq_range->max_bandwidth_khz = |
| 6880 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 6881 | |
| 6882 | power_rule->max_eirp = |
| 6883 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 6884 | |
| 6885 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 6886 | power_rule->max_antenna_gain = |
| 6887 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 6888 | |
| 6889 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 6890 | reg_rule->dfs_cac_ms = |
| 6891 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 6892 | |
| 6893 | return 0; |
| 6894 | } |
| 6895 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6896 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6897 | { |
| 6898 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 6899 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6900 | char *alpha2; |
| 6901 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6902 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 6903 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6904 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6905 | |
| 6906 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6907 | return -EINVAL; |
| 6908 | |
| 6909 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 6910 | return -EINVAL; |
| 6911 | |
| 6912 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6913 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6914 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 6915 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 6916 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6917 | 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] | 6918 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6919 | num_rules++; |
| 6920 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 6921 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6922 | } |
| 6923 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 6924 | if (!reg_is_valid_request(alpha2)) |
| 6925 | return -EINVAL; |
| 6926 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6927 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6928 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6929 | |
| 6930 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 6931 | if (!rd) |
| 6932 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6933 | |
| 6934 | rd->n_reg_rules = num_rules; |
| 6935 | rd->alpha2[0] = alpha2[0]; |
| 6936 | rd->alpha2[1] = alpha2[1]; |
| 6937 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6938 | /* |
| 6939 | * Disable DFS master mode if the DFS region was |
| 6940 | * not supported or known on this kernel. |
| 6941 | */ |
| 6942 | if (reg_supported_dfs_region(dfs_region)) |
| 6943 | rd->dfs_region = dfs_region; |
| 6944 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6945 | 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] | 6946 | rem_reg_rules) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6947 | r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6948 | nl_reg_rule, reg_rule_policy, |
| 6949 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6950 | if (r) |
| 6951 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6952 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 6953 | if (r) |
| 6954 | goto bad_reg; |
| 6955 | |
| 6956 | rule_idx++; |
| 6957 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6958 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 6959 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6960 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6961 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6962 | } |
| 6963 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 6964 | /* set_regdom takes ownership of rd */ |
| 6965 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 6966 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6967 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6968 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6969 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6970 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6971 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6972 | static int validate_scan_freqs(struct nlattr *freqs) |
| 6973 | { |
| 6974 | struct nlattr *attr1, *attr2; |
| 6975 | int n_channels = 0, tmp1, tmp2; |
| 6976 | |
Srinivas Dasari | d7f13f7 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 6977 | nla_for_each_nested(attr1, freqs, tmp1) |
| 6978 | if (nla_len(attr1) != sizeof(u32)) |
| 6979 | return 0; |
| 6980 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6981 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 6982 | n_channels++; |
| 6983 | /* |
| 6984 | * Some hardware has a limited channel list for |
| 6985 | * scanning, and it is pretty much nonsensical |
| 6986 | * to scan for a channel twice, so disallow that |
| 6987 | * and don't require drivers to check that the |
| 6988 | * channel list they get isn't longer than what |
| 6989 | * they can scan, as long as they can scan all |
| 6990 | * the channels they registered at once. |
| 6991 | */ |
| 6992 | nla_for_each_nested(attr2, freqs, tmp2) |
| 6993 | if (attr1 != attr2 && |
| 6994 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 6995 | return 0; |
| 6996 | } |
| 6997 | |
| 6998 | return n_channels; |
| 6999 | } |
| 7000 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7001 | 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] | 7002 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7003 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7004 | } |
| 7005 | |
| 7006 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 7007 | struct cfg80211_bss_selection *bss_select) |
| 7008 | { |
| 7009 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 7010 | struct nlattr *nest; |
| 7011 | int err; |
| 7012 | bool found = false; |
| 7013 | int i; |
| 7014 | |
| 7015 | /* only process one nested attribute */ |
| 7016 | nest = nla_data(nla); |
| 7017 | if (!nla_ok(nest, nla_len(nest))) |
| 7018 | return -EINVAL; |
| 7019 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7020 | err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7021 | nl80211_bss_select_policy, NULL); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7022 | if (err) |
| 7023 | return err; |
| 7024 | |
| 7025 | /* only one attribute may be given */ |
| 7026 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 7027 | if (attr[i]) { |
| 7028 | if (found) |
| 7029 | return -EINVAL; |
| 7030 | found = true; |
| 7031 | } |
| 7032 | } |
| 7033 | |
| 7034 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 7035 | |
| 7036 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 7037 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 7038 | |
| 7039 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 7040 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 7041 | bss_select->param.band_pref = |
| 7042 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 7043 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 7044 | return -EINVAL; |
| 7045 | } |
| 7046 | |
| 7047 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 7048 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 7049 | |
| 7050 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 7051 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 7052 | bss_select->param.adjust.band = adj_param->band; |
| 7053 | bss_select->param.adjust.delta = adj_param->delta; |
| 7054 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 7055 | return -EINVAL; |
| 7056 | } |
| 7057 | |
| 7058 | /* user-space did not provide behaviour attribute */ |
| 7059 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 7060 | return -EINVAL; |
| 7061 | |
| 7062 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 7063 | return -EINVAL; |
| 7064 | |
| 7065 | return 0; |
| 7066 | } |
| 7067 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 7068 | int nl80211_parse_random_mac(struct nlattr **attrs, |
| 7069 | u8 *mac_addr, u8 *mac_addr_mask) |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7070 | { |
| 7071 | int i; |
| 7072 | |
| 7073 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 7074 | eth_zero_addr(mac_addr); |
| 7075 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7076 | mac_addr[0] = 0x2; |
| 7077 | mac_addr_mask[0] = 0x3; |
| 7078 | |
| 7079 | return 0; |
| 7080 | } |
| 7081 | |
| 7082 | /* need both or none */ |
| 7083 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 7084 | return -EINVAL; |
| 7085 | |
| 7086 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 7087 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 7088 | |
| 7089 | /* don't allow or configure an mcast address */ |
| 7090 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 7091 | is_multicast_ether_addr(mac_addr)) |
| 7092 | return -EINVAL; |
| 7093 | |
| 7094 | /* |
| 7095 | * allow users to pass a MAC address that has bits set outside |
| 7096 | * of the mask, but don't bother drivers with having to deal |
| 7097 | * with such bits |
| 7098 | */ |
| 7099 | for (i = 0; i < ETH_ALEN; i++) |
| 7100 | mac_addr[i] &= mac_addr_mask[i]; |
| 7101 | |
| 7102 | return 0; |
| 7103 | } |
| 7104 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 7105 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 7106 | { |
| 7107 | ASSERT_WDEV_LOCK(wdev); |
| 7108 | |
| 7109 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 7110 | return true; |
| 7111 | |
| 7112 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 7113 | return true; |
| 7114 | |
| 7115 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 7116 | } |
| 7117 | |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 7118 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, |
| 7119 | enum nl80211_ext_feature_index feat) |
| 7120 | { |
| 7121 | if (!(flags & flag)) |
| 7122 | return true; |
| 7123 | if (wiphy_ext_feature_isset(wiphy, feat)) |
| 7124 | return true; |
| 7125 | return false; |
| 7126 | } |
| 7127 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7128 | static int |
| 7129 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 7130 | void *request, struct nlattr **attrs, |
| 7131 | bool is_sched_scan) |
| 7132 | { |
| 7133 | u8 *mac_addr, *mac_addr_mask; |
| 7134 | u32 *flags; |
| 7135 | enum nl80211_feature_flags randomness_flag; |
| 7136 | |
| 7137 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) |
| 7138 | return 0; |
| 7139 | |
| 7140 | if (is_sched_scan) { |
| 7141 | struct cfg80211_sched_scan_request *req = request; |
| 7142 | |
| 7143 | randomness_flag = wdev ? |
| 7144 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : |
| 7145 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7146 | flags = &req->flags; |
| 7147 | mac_addr = req->mac_addr; |
| 7148 | mac_addr_mask = req->mac_addr_mask; |
| 7149 | } else { |
| 7150 | struct cfg80211_scan_request *req = request; |
| 7151 | |
| 7152 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 7153 | flags = &req->flags; |
| 7154 | mac_addr = req->mac_addr; |
| 7155 | mac_addr_mask = req->mac_addr_mask; |
| 7156 | } |
| 7157 | |
| 7158 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); |
| 7159 | |
Sunil Dutt | 5037a00 | 2018-01-25 17:13:37 +0200 | [diff] [blame] | 7160 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 7161 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 7162 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7163 | NL80211_SCAN_FLAG_LOW_SPAN, |
| 7164 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || |
| 7165 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7166 | NL80211_SCAN_FLAG_LOW_POWER, |
| 7167 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || |
| 7168 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7169 | NL80211_SCAN_FLAG_HIGH_ACCURACY, |
| 7170 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || |
| 7171 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7172 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, |
| 7173 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || |
| 7174 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7175 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, |
| 7176 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || |
| 7177 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7178 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, |
| 7179 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || |
| 7180 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7181 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, |
Johannes Berg | 2e076f1 | 2018-05-28 15:47:40 +0200 | [diff] [blame] | 7182 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || |
| 7183 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7184 | NL80211_SCAN_FLAG_RANDOM_SN, |
| 7185 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || |
| 7186 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7187 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, |
| 7188 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7189 | return -EOPNOTSUPP; |
| 7190 | |
| 7191 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 7192 | int err; |
| 7193 | |
| 7194 | if (!(wiphy->features & randomness_flag) || |
| 7195 | (wdev && wdev->current_bss)) |
| 7196 | return -EOPNOTSUPP; |
| 7197 | |
| 7198 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); |
| 7199 | if (err) |
| 7200 | return err; |
| 7201 | } |
| 7202 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7203 | return 0; |
| 7204 | } |
| 7205 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7206 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 7207 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7209 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7210 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7211 | struct nlattr *attr; |
| 7212 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7213 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7214 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7215 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7216 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7217 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 7218 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 7219 | return -EOPNOTSUPP; |
| 7220 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7221 | if (!rdev->ops->scan) |
| 7222 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7223 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 7224 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7225 | err = -EBUSY; |
| 7226 | goto unlock; |
| 7227 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7228 | |
| 7229 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7230 | n_channels = validate_scan_freqs( |
| 7231 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7232 | if (!n_channels) { |
| 7233 | err = -EINVAL; |
| 7234 | goto unlock; |
| 7235 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7236 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7237 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7238 | } |
| 7239 | |
| 7240 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7241 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 7242 | n_ssids++; |
| 7243 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7244 | if (n_ssids > wiphy->max_scan_ssids) { |
| 7245 | err = -EINVAL; |
| 7246 | goto unlock; |
| 7247 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7248 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7249 | if (info->attrs[NL80211_ATTR_IE]) |
| 7250 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7251 | else |
| 7252 | ie_len = 0; |
| 7253 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7254 | if (ie_len > wiphy->max_scan_ie_len) { |
| 7255 | err = -EINVAL; |
| 7256 | goto unlock; |
| 7257 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 7258 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7259 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7260 | + sizeof(*request->ssids) * n_ssids |
| 7261 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7262 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7263 | if (!request) { |
| 7264 | err = -ENOMEM; |
| 7265 | goto unlock; |
| 7266 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7267 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7268 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 7269 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7270 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7271 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7272 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7273 | request->ie = (void *)(request->ssids + n_ssids); |
| 7274 | else |
| 7275 | request->ie = (void *)(request->channels + n_channels); |
| 7276 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7277 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7278 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7279 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 7280 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7281 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7282 | struct ieee80211_channel *chan; |
| 7283 | |
| 7284 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7285 | |
| 7286 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7287 | err = -EINVAL; |
| 7288 | goto out_free; |
| 7289 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7290 | |
| 7291 | /* ignore disabled channels */ |
| 7292 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7293 | continue; |
| 7294 | |
| 7295 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7296 | i++; |
| 7297 | } |
| 7298 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7299 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7300 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7301 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7302 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7303 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7304 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7305 | if (!wiphy->bands[band]) |
| 7306 | continue; |
| 7307 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7308 | struct ieee80211_channel *chan; |
| 7309 | |
| 7310 | chan = &wiphy->bands[band]->channels[j]; |
| 7311 | |
| 7312 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7313 | continue; |
| 7314 | |
| 7315 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7316 | i++; |
| 7317 | } |
| 7318 | } |
| 7319 | } |
| 7320 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7321 | if (!i) { |
| 7322 | err = -EINVAL; |
| 7323 | goto out_free; |
| 7324 | } |
| 7325 | |
| 7326 | request->n_channels = i; |
| 7327 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 7328 | wdev_lock(wdev); |
| 7329 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 7330 | struct ieee80211_channel *chan; |
| 7331 | |
| 7332 | if (request->n_channels != 1) { |
| 7333 | wdev_unlock(wdev); |
| 7334 | err = -EBUSY; |
| 7335 | goto out_free; |
| 7336 | } |
| 7337 | |
| 7338 | chan = request->channels[0]; |
| 7339 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 7340 | wdev_unlock(wdev); |
| 7341 | err = -EBUSY; |
| 7342 | goto out_free; |
| 7343 | } |
| 7344 | } |
| 7345 | wdev_unlock(wdev); |
| 7346 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7347 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7348 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7349 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7350 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7351 | err = -EINVAL; |
| 7352 | goto out_free; |
| 7353 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7354 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7355 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7356 | i++; |
| 7357 | } |
| 7358 | } |
| 7359 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7360 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7361 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54b | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 7362 | memcpy((void *)request->ie, |
| 7363 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7364 | request->ie_len); |
| 7365 | } |
| 7366 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7367 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 7368 | if (wiphy->bands[i]) |
| 7369 | request->rates[i] = |
| 7370 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7371 | |
| 7372 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 7373 | nla_for_each_nested(attr, |
| 7374 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 7375 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7376 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7377 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7378 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7379 | err = -EINVAL; |
| 7380 | goto out_free; |
| 7381 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 7382 | |
| 7383 | if (!wiphy->bands[band]) |
| 7384 | continue; |
| 7385 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7386 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 7387 | nla_data(attr), |
| 7388 | nla_len(attr), |
| 7389 | &request->rates[band]); |
| 7390 | if (err) |
| 7391 | goto out_free; |
| 7392 | } |
| 7393 | } |
| 7394 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7395 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 7396 | if (!wiphy_ext_feature_isset(wiphy, |
| 7397 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 7398 | err = -EOPNOTSUPP; |
| 7399 | goto out_free; |
| 7400 | } |
| 7401 | |
| 7402 | request->duration = |
| 7403 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 7404 | request->duration_mandatory = |
| 7405 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 7406 | } |
| 7407 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7408 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
| 7409 | false); |
| 7410 | if (err) |
| 7411 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7412 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7413 | request->no_cck = |
| 7414 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7415 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 7416 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 7417 | * BSSID to scan for. This was problematic because that same attribute |
| 7418 | * was already used for another purpose (local random MAC address). The |
| 7419 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 7420 | * compatibility with older userspace components, also use the |
| 7421 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 7422 | * the specific BSSID use case instead of the random MAC address |
| 7423 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 7424 | */ |
| 7425 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 7426 | memcpy(request->bssid, |
| 7427 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 7428 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 7429 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 7430 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 7431 | ETH_ALEN); |
| 7432 | else |
| 7433 | eth_broadcast_addr(request->bssid); |
| 7434 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7435 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7436 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7437 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7438 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7439 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7440 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7441 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7442 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7443 | nl80211_send_scan_start(rdev, wdev); |
| 7444 | if (wdev->netdev) |
| 7445 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7446 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7447 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7448 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7449 | kfree(request); |
| 7450 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7451 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7452 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7453 | return err; |
| 7454 | } |
| 7455 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 7456 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 7457 | { |
| 7458 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7459 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7460 | |
| 7461 | if (!rdev->ops->abort_scan) |
| 7462 | return -EOPNOTSUPP; |
| 7463 | |
| 7464 | if (rdev->scan_msg) |
| 7465 | return 0; |
| 7466 | |
| 7467 | if (!rdev->scan_req) |
| 7468 | return -ENOENT; |
| 7469 | |
| 7470 | rdev_abort_scan(rdev, wdev); |
| 7471 | return 0; |
| 7472 | } |
| 7473 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7474 | static int |
| 7475 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 7476 | struct cfg80211_sched_scan_request *request, |
| 7477 | struct nlattr **attrs) |
| 7478 | { |
| 7479 | int tmp, err, i = 0; |
| 7480 | struct nlattr *attr; |
| 7481 | |
| 7482 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 7483 | u32 interval; |
| 7484 | |
| 7485 | /* |
| 7486 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 7487 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7488 | * case one scan plan will be set with the specified scan |
| 7489 | * interval and infinite number of iterations. |
| 7490 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7491 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 7492 | if (!interval) |
| 7493 | return -EINVAL; |
| 7494 | |
| 7495 | request->scan_plans[0].interval = |
| 7496 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 7497 | if (!request->scan_plans[0].interval) |
| 7498 | return -EINVAL; |
| 7499 | |
| 7500 | if (request->scan_plans[0].interval > |
| 7501 | wiphy->max_sched_scan_plan_interval) |
| 7502 | request->scan_plans[0].interval = |
| 7503 | wiphy->max_sched_scan_plan_interval; |
| 7504 | |
| 7505 | return 0; |
| 7506 | } |
| 7507 | |
| 7508 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 7509 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 7510 | |
| 7511 | if (WARN_ON(i >= n_plans)) |
| 7512 | return -EINVAL; |
| 7513 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7514 | err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7515 | attr, nl80211_plan_policy, NULL); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7516 | if (err) |
| 7517 | return err; |
| 7518 | |
| 7519 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 7520 | return -EINVAL; |
| 7521 | |
| 7522 | request->scan_plans[i].interval = |
| 7523 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 7524 | if (!request->scan_plans[i].interval || |
| 7525 | request->scan_plans[i].interval > |
| 7526 | wiphy->max_sched_scan_plan_interval) |
| 7527 | return -EINVAL; |
| 7528 | |
| 7529 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 7530 | request->scan_plans[i].iterations = |
| 7531 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 7532 | if (!request->scan_plans[i].iterations || |
| 7533 | (request->scan_plans[i].iterations > |
| 7534 | wiphy->max_sched_scan_plan_iterations)) |
| 7535 | return -EINVAL; |
| 7536 | } else if (i < n_plans - 1) { |
| 7537 | /* |
| 7538 | * All scan plans but the last one must specify |
| 7539 | * a finite number of iterations |
| 7540 | */ |
| 7541 | return -EINVAL; |
| 7542 | } |
| 7543 | |
| 7544 | i++; |
| 7545 | } |
| 7546 | |
| 7547 | /* |
| 7548 | * The last scan plan must not specify the number of |
| 7549 | * iterations, it is supposed to run infinitely |
| 7550 | */ |
| 7551 | if (request->scan_plans[n_plans - 1].iterations) |
| 7552 | return -EINVAL; |
| 7553 | |
| 7554 | return 0; |
| 7555 | } |
| 7556 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7557 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7558 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7559 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7560 | { |
| 7561 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7562 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7563 | 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] | 7564 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7565 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7566 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7567 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7568 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7569 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7570 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7571 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7572 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7573 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7574 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7575 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7576 | } |
| 7577 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7578 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7579 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7580 | tmp) |
| 7581 | n_ssids++; |
| 7582 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 7583 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7584 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7585 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7586 | /* |
| 7587 | * First, count the number of 'real' matchsets. Due to an issue with |
| 7588 | * the old implementation, matchsets containing only the RSSI attribute |
| 7589 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 7590 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 7591 | * all APs with a strong RSSI. This is needed to be compatible with |
| 7592 | * older userspace that treated a matchset with only the RSSI as the |
| 7593 | * global RSSI for all other matchsets - if there are other matchsets. |
| 7594 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7595 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7596 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7597 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7598 | tmp) { |
| 7599 | struct nlattr *rssi; |
| 7600 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7601 | err = nla_parse_nested(tb, |
| 7602 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7603 | attr, nl80211_match_policy, |
| 7604 | NULL); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7605 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7606 | return ERR_PTR(err); |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7607 | |
| 7608 | /* SSID and BSSID are mutually exclusive */ |
| 7609 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 7610 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 7611 | return ERR_PTR(-EINVAL); |
| 7612 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7613 | /* add other standalone attributes here */ |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7614 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 7615 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7616 | n_match_sets++; |
| 7617 | continue; |
| 7618 | } |
| 7619 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7620 | if (rssi) |
| 7621 | default_match_rssi = nla_get_s32(rssi); |
| 7622 | } |
| 7623 | } |
| 7624 | |
| 7625 | /* However, if there's no other matchset, add the RSSI one */ |
| 7626 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 7627 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7628 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7629 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7630 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7631 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7632 | if (attrs[NL80211_ATTR_IE]) |
| 7633 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7634 | else |
| 7635 | ie_len = 0; |
| 7636 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 7637 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7638 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 7639 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7640 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 7641 | /* |
| 7642 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 7643 | * each scan plan already specifies its own interval |
| 7644 | */ |
| 7645 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7646 | return ERR_PTR(-EINVAL); |
| 7647 | |
| 7648 | nla_for_each_nested(attr, |
| 7649 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 7650 | n_plans++; |
| 7651 | } else { |
| 7652 | /* |
| 7653 | * The scan interval attribute is kept for backward |
| 7654 | * compatibility. If no scan plans are specified and sched scan |
| 7655 | * interval is specified, one scan plan will be set with this |
| 7656 | * scan interval and infinite number of iterations. |
| 7657 | */ |
| 7658 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7659 | return ERR_PTR(-EINVAL); |
| 7660 | |
| 7661 | n_plans = 1; |
| 7662 | } |
| 7663 | |
| 7664 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 7665 | return ERR_PTR(-EINVAL); |
| 7666 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7667 | if (!wiphy_ext_feature_isset( |
| 7668 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 7669 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 7670 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 7671 | return ERR_PTR(-EINVAL); |
| 7672 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7673 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7674 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7675 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7676 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7677 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7678 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7679 | if (!request) |
| 7680 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7681 | |
| 7682 | if (n_ssids) |
| 7683 | request->ssids = (void *)&request->channels[n_channels]; |
| 7684 | request->n_ssids = n_ssids; |
| 7685 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7686 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7687 | request->ie = (void *)(request->ssids + n_ssids); |
| 7688 | else |
| 7689 | request->ie = (void *)(request->channels + n_channels); |
| 7690 | } |
| 7691 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7692 | if (n_match_sets) { |
| 7693 | if (request->ie) |
| 7694 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7695 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7696 | request->match_sets = |
| 7697 | (void *)(request->ssids + n_ssids); |
| 7698 | else |
| 7699 | request->match_sets = |
| 7700 | (void *)(request->channels + n_channels); |
| 7701 | } |
| 7702 | request->n_match_sets = n_match_sets; |
| 7703 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7704 | if (n_match_sets) |
| 7705 | request->scan_plans = (void *)(request->match_sets + |
| 7706 | n_match_sets); |
| 7707 | else if (request->ie) |
| 7708 | request->scan_plans = (void *)(request->ie + ie_len); |
| 7709 | else if (n_ssids) |
| 7710 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 7711 | else |
| 7712 | request->scan_plans = (void *)(request->channels + n_channels); |
| 7713 | |
| 7714 | request->n_scan_plans = n_plans; |
| 7715 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7716 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7717 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7718 | /* user specified, bail out if channel not found */ |
| 7719 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7720 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7721 | tmp) { |
| 7722 | struct ieee80211_channel *chan; |
| 7723 | |
| 7724 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7725 | |
| 7726 | if (!chan) { |
| 7727 | err = -EINVAL; |
| 7728 | goto out_free; |
| 7729 | } |
| 7730 | |
| 7731 | /* ignore disabled channels */ |
| 7732 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7733 | continue; |
| 7734 | |
| 7735 | request->channels[i] = chan; |
| 7736 | i++; |
| 7737 | } |
| 7738 | } else { |
| 7739 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7740 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7741 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7742 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7743 | if (!wiphy->bands[band]) |
| 7744 | continue; |
| 7745 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 7746 | struct ieee80211_channel *chan; |
| 7747 | |
| 7748 | chan = &wiphy->bands[band]->channels[j]; |
| 7749 | |
| 7750 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7751 | continue; |
| 7752 | |
| 7753 | request->channels[i] = chan; |
| 7754 | i++; |
| 7755 | } |
| 7756 | } |
| 7757 | } |
| 7758 | |
| 7759 | if (!i) { |
| 7760 | err = -EINVAL; |
| 7761 | goto out_free; |
| 7762 | } |
| 7763 | |
| 7764 | request->n_channels = i; |
| 7765 | |
| 7766 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7767 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7768 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7769 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7770 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7771 | err = -EINVAL; |
| 7772 | goto out_free; |
| 7773 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7774 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7775 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 7776 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7777 | i++; |
| 7778 | } |
| 7779 | } |
| 7780 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7781 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7782 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7783 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7784 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7785 | tmp) { |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7786 | struct nlattr *ssid, *bssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7787 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7788 | err = nla_parse_nested(tb, |
| 7789 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7790 | attr, nl80211_match_policy, |
| 7791 | NULL); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7792 | if (err) |
| 7793 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 7794 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7795 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
| 7796 | if (ssid || bssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7797 | if (WARN_ON(i >= n_match_sets)) { |
| 7798 | /* this indicates a programming error, |
| 7799 | * the loop above should have verified |
| 7800 | * things properly |
| 7801 | */ |
| 7802 | err = -EINVAL; |
| 7803 | goto out_free; |
| 7804 | } |
| 7805 | |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7806 | if (ssid) { |
| 7807 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 7808 | err = -EINVAL; |
| 7809 | goto out_free; |
| 7810 | } |
| 7811 | memcpy(request->match_sets[i].ssid.ssid, |
| 7812 | nla_data(ssid), nla_len(ssid)); |
| 7813 | request->match_sets[i].ssid.ssid_len = |
| 7814 | nla_len(ssid); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7815 | } |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7816 | if (bssid) { |
| 7817 | if (nla_len(bssid) != ETH_ALEN) { |
| 7818 | err = -EINVAL; |
| 7819 | goto out_free; |
| 7820 | } |
| 7821 | memcpy(request->match_sets[i].bssid, |
| 7822 | nla_data(bssid), ETH_ALEN); |
| 7823 | } |
| 7824 | |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 7825 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7826 | request->match_sets[i].rssi_thold = |
| 7827 | default_match_rssi; |
| 7828 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7829 | if (rssi) |
| 7830 | request->match_sets[i].rssi_thold = |
| 7831 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7832 | } |
| 7833 | i++; |
| 7834 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7835 | |
| 7836 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 7837 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7838 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 7839 | |
| 7840 | request->min_rssi_thold = INT_MAX; |
| 7841 | for (i = 0; i < n_match_sets; i++) |
| 7842 | request->min_rssi_thold = |
| 7843 | min(request->match_sets[i].rssi_thold, |
| 7844 | request->min_rssi_thold); |
| 7845 | } else { |
| 7846 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7847 | } |
| 7848 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 7849 | if (ie_len) { |
| 7850 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7851 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7852 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7853 | request->ie_len); |
| 7854 | } |
| 7855 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7856 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
| 7857 | if (err) |
| 7858 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7859 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 7860 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 7861 | request->delay = |
| 7862 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 7863 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7864 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 7865 | request->relative_rssi = nla_get_s8( |
| 7866 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 7867 | request->relative_rssi_set = true; |
| 7868 | } |
| 7869 | |
| 7870 | if (request->relative_rssi_set && |
| 7871 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 7872 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 7873 | |
| 7874 | rssi_adjust = nla_data( |
| 7875 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 7876 | request->rssi_adjust.band = rssi_adjust->band; |
| 7877 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 7878 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 7879 | err = -EINVAL; |
| 7880 | goto out_free; |
| 7881 | } |
| 7882 | } |
| 7883 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7884 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 7885 | if (err) |
| 7886 | goto out_free; |
| 7887 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7888 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7889 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7890 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7891 | |
| 7892 | out_free: |
| 7893 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7894 | return ERR_PTR(err); |
| 7895 | } |
| 7896 | |
| 7897 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 7898 | struct genl_info *info) |
| 7899 | { |
| 7900 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7901 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7902 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7903 | struct cfg80211_sched_scan_request *sched_scan_req; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7904 | bool want_multi; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7905 | int err; |
| 7906 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7907 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7908 | return -EOPNOTSUPP; |
| 7909 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7910 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 7911 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 7912 | if (err) |
| 7913 | return err; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7914 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7915 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7916 | info->attrs, |
| 7917 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7918 | |
| 7919 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7920 | if (err) |
| 7921 | goto out_err; |
| 7922 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7923 | /* leave request id zero for legacy request |
| 7924 | * or if driver does not support multi-scheduled scan |
| 7925 | */ |
| 7926 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) { |
| 7927 | while (!sched_scan_req->reqid) |
Johannes Berg | b60ad34 | 2018-10-01 11:52:07 +0200 | [diff] [blame] | 7928 | sched_scan_req->reqid = cfg80211_assign_cookie(rdev); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7929 | } |
| 7930 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7931 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7932 | if (err) |
| 7933 | goto out_free; |
| 7934 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7935 | sched_scan_req->dev = dev; |
| 7936 | sched_scan_req->wiphy = &rdev->wiphy; |
| 7937 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 7938 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 7939 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 7940 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7941 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7942 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 7943 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7944 | return 0; |
| 7945 | |
| 7946 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7947 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7948 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7949 | return err; |
| 7950 | } |
| 7951 | |
| 7952 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 7953 | struct genl_info *info) |
| 7954 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7955 | struct cfg80211_sched_scan_request *req; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7957 | u64 cookie; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7958 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7959 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7960 | return -EOPNOTSUPP; |
| 7961 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7962 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 7963 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7964 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 7965 | } |
| 7966 | |
| 7967 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 7968 | struct cfg80211_sched_scan_request, |
| 7969 | list); |
| 7970 | if (!req || req->reqid || |
| 7971 | (req->owner_nlportid && |
| 7972 | req->owner_nlportid != info->snd_portid)) |
| 7973 | return -ENOENT; |
| 7974 | |
| 7975 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7976 | } |
| 7977 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7978 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 7979 | struct genl_info *info) |
| 7980 | { |
| 7981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7982 | struct net_device *dev = info->user_ptr[1]; |
| 7983 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 7984 | struct wiphy *wiphy = wdev->wiphy; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7985 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7986 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7987 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7988 | int err; |
| 7989 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 7990 | dfs_region = reg_get_dfs_region(wiphy); |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7991 | if (dfs_region == NL80211_DFS_UNSET) |
| 7992 | return -EINVAL; |
| 7993 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7994 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7995 | if (err) |
| 7996 | return err; |
| 7997 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 7998 | if (netif_carrier_ok(dev)) |
| 7999 | return -EBUSY; |
| 8000 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8001 | if (wdev->cac_started) |
| 8002 | return -EBUSY; |
| 8003 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8004 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8005 | if (err < 0) |
| 8006 | return err; |
| 8007 | |
| 8008 | if (err == 0) |
| 8009 | return -EINVAL; |
| 8010 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8011 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8012 | return -EINVAL; |
| 8013 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8014 | /* CAC start is offloaded to HW and can't be started manually */ |
| 8015 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) |
| 8016 | return -EOPNOTSUPP; |
| 8017 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8018 | if (!rdev->ops->start_radar_detection) |
| 8019 | return -EOPNOTSUPP; |
| 8020 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8021 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 8022 | if (WARN_ON(!cac_time_ms)) |
| 8023 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 8024 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8025 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8026 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 8027 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8028 | wdev->cac_started = true; |
| 8029 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8030 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8031 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8032 | return err; |
| 8033 | } |
| 8034 | |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 8035 | static int nl80211_notify_radar_detection(struct sk_buff *skb, |
| 8036 | struct genl_info *info) |
| 8037 | { |
| 8038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8039 | struct net_device *dev = info->user_ptr[1]; |
| 8040 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8041 | struct wiphy *wiphy = wdev->wiphy; |
| 8042 | struct cfg80211_chan_def chandef; |
| 8043 | enum nl80211_dfs_regions dfs_region; |
| 8044 | int err; |
| 8045 | |
| 8046 | dfs_region = reg_get_dfs_region(wiphy); |
| 8047 | if (dfs_region == NL80211_DFS_UNSET) { |
| 8048 | GENL_SET_ERR_MSG(info, |
| 8049 | "DFS Region is not set. Unexpected Radar indication"); |
| 8050 | return -EINVAL; |
| 8051 | } |
| 8052 | |
| 8053 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8054 | if (err) { |
| 8055 | GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); |
| 8056 | return err; |
| 8057 | } |
| 8058 | |
| 8059 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
| 8060 | if (err < 0) { |
| 8061 | GENL_SET_ERR_MSG(info, "chandef is invalid"); |
| 8062 | return err; |
| 8063 | } |
| 8064 | |
| 8065 | if (err == 0) { |
| 8066 | GENL_SET_ERR_MSG(info, |
| 8067 | "Unexpected Radar indication for chandef/iftype"); |
| 8068 | return -EINVAL; |
| 8069 | } |
| 8070 | |
| 8071 | /* Do not process this notification if radar is already detected |
| 8072 | * by kernel on this channel, and return success. |
| 8073 | */ |
| 8074 | if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) |
| 8075 | return 0; |
| 8076 | |
| 8077 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); |
| 8078 | |
| 8079 | cfg80211_sched_dfs_chan_update(rdev); |
| 8080 | |
| 8081 | memcpy(&rdev->radar_chandef, &chandef, sizeof(chandef)); |
| 8082 | |
| 8083 | /* Propagate this notification to other radios as well */ |
| 8084 | queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); |
| 8085 | |
| 8086 | return 0; |
| 8087 | } |
| 8088 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8089 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 8090 | { |
| 8091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8092 | struct net_device *dev = info->user_ptr[1]; |
| 8093 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8094 | struct cfg80211_csa_settings params; |
| 8095 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 8096 | * function is called under RTNL lock, so this should not be a problem. |
| 8097 | */ |
| 8098 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8099 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8100 | bool need_new_beacon = false; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8101 | bool need_handle_dfs_flag = true; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8102 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 8103 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8104 | |
| 8105 | if (!rdev->ops->channel_switch || |
| 8106 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 8107 | return -EOPNOTSUPP; |
| 8108 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8109 | switch (dev->ieee80211_ptr->iftype) { |
| 8110 | case NL80211_IFTYPE_AP: |
| 8111 | case NL80211_IFTYPE_P2P_GO: |
| 8112 | need_new_beacon = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8113 | /* For all modes except AP the handle_dfs flag needs to be |
| 8114 | * supplied to tell the kernel that userspace will handle radar |
| 8115 | * events when they happen. Otherwise a switch to a channel |
| 8116 | * requiring DFS will be rejected. |
| 8117 | */ |
| 8118 | need_handle_dfs_flag = false; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8119 | |
| 8120 | /* useless if AP is not running */ |
| 8121 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8122 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8123 | break; |
| 8124 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8125 | if (!wdev->ssid_len) |
| 8126 | return -ENOTCONN; |
| 8127 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 8128 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8129 | if (!wdev->mesh_id_len) |
| 8130 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8131 | break; |
| 8132 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8133 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8134 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8135 | |
| 8136 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | c177db2 | 2018-10-30 09:17:44 +0100 | [diff] [blame] | 8137 | params.beacon_csa.ftm_responder = -1; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8138 | |
| 8139 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8140 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 8141 | return -EINVAL; |
| 8142 | |
| 8143 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 8144 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8145 | return -EINVAL; |
| 8146 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 8147 | /* Even though the attribute is u32, the specification says |
| 8148 | * u8, so let's make sure we don't overflow. |
| 8149 | */ |
| 8150 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 8151 | if (cs_count > 255) |
| 8152 | return -EINVAL; |
| 8153 | |
| 8154 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8155 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8156 | if (!need_new_beacon) |
| 8157 | goto skip_beacons; |
| 8158 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 8159 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8160 | if (err) |
| 8161 | return err; |
| 8162 | |
| 8163 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 8164 | info->attrs[NL80211_ATTR_CSA_IES], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 8165 | nl80211_policy, info->extack); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8166 | if (err) |
| 8167 | return err; |
| 8168 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 8169 | err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8170 | if (err) |
| 8171 | return err; |
| 8172 | |
| 8173 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 8174 | return -EINVAL; |
| 8175 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8176 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 8177 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8178 | return -EINVAL; |
| 8179 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8180 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 8181 | if (rdev->wiphy.max_num_csa_counters && |
| 8182 | (params.n_counter_offsets_beacon > |
| 8183 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8184 | return -EINVAL; |
| 8185 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8186 | params.counter_offsets_beacon = |
| 8187 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 8188 | |
| 8189 | /* sanity checks - counters should fit and be the same */ |
| 8190 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 8191 | u16 offset = params.counter_offsets_beacon[i]; |
| 8192 | |
| 8193 | if (offset >= params.beacon_csa.tail_len) |
| 8194 | return -EINVAL; |
| 8195 | |
| 8196 | if (params.beacon_csa.tail[offset] != params.count) |
| 8197 | return -EINVAL; |
| 8198 | } |
| 8199 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8200 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8201 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 8202 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8203 | return -EINVAL; |
| 8204 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8205 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 8206 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 8207 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8208 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8209 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8210 | |
| 8211 | params.counter_offsets_presp = |
| 8212 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 8213 | |
| 8214 | /* sanity checks - counters should fit and be the same */ |
| 8215 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 8216 | u16 offset = params.counter_offsets_presp[i]; |
| 8217 | |
| 8218 | if (offset >= params.beacon_csa.probe_resp_len) |
| 8219 | return -EINVAL; |
| 8220 | |
| 8221 | if (params.beacon_csa.probe_resp[offset] != |
| 8222 | params.count) |
| 8223 | return -EINVAL; |
| 8224 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8225 | } |
| 8226 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8227 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8228 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 8229 | if (err) |
| 8230 | return err; |
| 8231 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 8232 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 8233 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8234 | return -EINVAL; |
| 8235 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 8236 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 8237 | ¶ms.chandef, |
| 8238 | wdev->iftype); |
| 8239 | if (err < 0) |
| 8240 | return err; |
| 8241 | |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8242 | if (err > 0) { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 8243 | params.radar_required = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8244 | if (need_handle_dfs_flag && |
| 8245 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
| 8246 | return -EINVAL; |
| 8247 | } |
| 8248 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8249 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8250 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 8251 | params.block_tx = true; |
| 8252 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 8253 | wdev_lock(wdev); |
| 8254 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 8255 | wdev_unlock(wdev); |
| 8256 | |
| 8257 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8258 | } |
| 8259 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8260 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 8261 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8262 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8263 | struct wireless_dev *wdev, |
| 8264 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8265 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8266 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8267 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8268 | void *hdr; |
| 8269 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8270 | |
| 8271 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8272 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8273 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8274 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 8275 | if (!hdr) |
| 8276 | return -1; |
| 8277 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 8278 | genl_dump_check_consistent(cb, hdr); |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8279 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8280 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 8281 | goto nla_put_failure; |
| 8282 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8283 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 8284 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8285 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 8286 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8287 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8288 | |
| 8289 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 8290 | if (!bss) |
| 8291 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8292 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8293 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8294 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8295 | |
| 8296 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8297 | /* indicate whether we have probe response data or not */ |
| 8298 | if (rcu_access_pointer(res->proberesp_ies) && |
| 8299 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 8300 | goto fail_unlock_rcu; |
| 8301 | |
| 8302 | /* this pointer prefers to be pointed to probe response data |
| 8303 | * but is always valid |
| 8304 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8305 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8306 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8307 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 8308 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8309 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8310 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 8311 | ies->len, ies->data)) |
| 8312 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8313 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8314 | |
| 8315 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8316 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8317 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8318 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 8319 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8320 | goto fail_unlock_rcu; |
| 8321 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 8322 | ies->len, ies->data)) |
| 8323 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8324 | } |
| 8325 | rcu_read_unlock(); |
| 8326 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8327 | if (res->beacon_interval && |
| 8328 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 8329 | goto nla_put_failure; |
| 8330 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 8331 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 8332 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8333 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 8334 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 8335 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8336 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 8337 | if (intbss->parent_tsf && |
| 8338 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 8339 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 8340 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 8341 | intbss->parent_bssid))) |
| 8342 | goto nla_put_failure; |
| 8343 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 8344 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8345 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 8346 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 8347 | goto nla_put_failure; |
| 8348 | |
Sunil Dutt | 983dafa | 2017-12-13 19:51:36 +0200 | [diff] [blame] | 8349 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
| 8350 | intbss->pub.chain_signal, |
| 8351 | NL80211_BSS_CHAIN_SIGNAL)) |
| 8352 | goto nla_put_failure; |
| 8353 | |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 8354 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8355 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8356 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 8357 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8358 | break; |
| 8359 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8360 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 8361 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8362 | break; |
| 8363 | default: |
| 8364 | break; |
| 8365 | } |
| 8366 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8367 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8368 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8369 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8370 | if (intbss == wdev->current_bss && |
| 8371 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 8372 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 8373 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8374 | break; |
| 8375 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8376 | if (intbss == wdev->current_bss && |
| 8377 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 8378 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 8379 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8380 | break; |
| 8381 | default: |
| 8382 | break; |
| 8383 | } |
| 8384 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8385 | nla_nest_end(msg, bss); |
| 8386 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 8387 | genlmsg_end(msg, hdr); |
| 8388 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8389 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8390 | fail_unlock_rcu: |
| 8391 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8392 | nla_put_failure: |
| 8393 | genlmsg_cancel(msg, hdr); |
| 8394 | return -EMSGSIZE; |
| 8395 | } |
| 8396 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8397 | 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] | 8398 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8399 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8400 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8401 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8402 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8403 | int err; |
| 8404 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8405 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 8406 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8407 | if (err) { |
| 8408 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8409 | return err; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8410 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8411 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8412 | wdev_lock(wdev); |
| 8413 | spin_lock_bh(&rdev->bss_lock); |
Denis Kenzior | d1e23c9 | 2018-05-21 10:31:13 -0500 | [diff] [blame] | 8414 | |
| 8415 | /* |
| 8416 | * dump_scan will be called multiple times to break up the scan results |
| 8417 | * into multiple messages. It is unlikely that any more bss-es will be |
| 8418 | * expired after the first call, so only call only call this on the |
| 8419 | * first dump_scan invocation. |
| 8420 | */ |
| 8421 | if (start == 0) |
| 8422 | cfg80211_bss_expire(rdev); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8423 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8424 | cb->seq = rdev->bss_generation; |
| 8425 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8426 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8427 | if (++idx <= start) |
| 8428 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8429 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8430 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8431 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8432 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8433 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8434 | } |
| 8435 | } |
| 8436 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8437 | spin_unlock_bh(&rdev->bss_lock); |
| 8438 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8439 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8440 | cb->args[2] = idx; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8441 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8442 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8443 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8444 | } |
| 8445 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8446 | 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] | 8447 | int flags, struct net_device *dev, |
| 8448 | bool allow_radio_stats, |
| 8449 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8450 | { |
| 8451 | void *hdr; |
| 8452 | struct nlattr *infoattr; |
| 8453 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8454 | /* skip radio stats if userspace didn't request them */ |
| 8455 | if (!survey->channel && !allow_radio_stats) |
| 8456 | return 0; |
| 8457 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8458 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8459 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 8460 | if (!hdr) |
| 8461 | return -ENOMEM; |
| 8462 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8463 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 8464 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8465 | |
| 8466 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 8467 | if (!infoattr) |
| 8468 | goto nla_put_failure; |
| 8469 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8470 | if (survey->channel && |
| 8471 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8472 | survey->channel->center_freq)) |
| 8473 | goto nla_put_failure; |
| 8474 | |
| 8475 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 8476 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 8477 | goto nla_put_failure; |
| 8478 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 8479 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 8480 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8481 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8482 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 8483 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8484 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8485 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8486 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 8487 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8488 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8489 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8490 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 8491 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8492 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8493 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8494 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 8495 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8496 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8497 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8498 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 8499 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8500 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 8501 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8502 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 8503 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 8504 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8505 | |
| 8506 | nla_nest_end(msg, infoattr); |
| 8507 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 8508 | genlmsg_end(msg, hdr); |
| 8509 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8510 | |
| 8511 | nla_put_failure: |
| 8512 | genlmsg_cancel(msg, hdr); |
| 8513 | return -EMSGSIZE; |
| 8514 | } |
| 8515 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8516 | 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] | 8517 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8518 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8519 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8520 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8521 | struct wireless_dev *wdev; |
| 8522 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8523 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8524 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8525 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8526 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 8527 | res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8528 | if (res) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8529 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8530 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8531 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8532 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8533 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8534 | if (!wdev->netdev) { |
| 8535 | res = -EINVAL; |
| 8536 | goto out_err; |
| 8537 | } |
| 8538 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8539 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8540 | res = -EOPNOTSUPP; |
| 8541 | goto out_err; |
| 8542 | } |
| 8543 | |
| 8544 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8545 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8546 | if (res == -ENOENT) |
| 8547 | break; |
| 8548 | if (res) |
| 8549 | goto out_err; |
| 8550 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8551 | /* don't send disabled channels, but do send non-channel data */ |
| 8552 | if (survey.channel && |
| 8553 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 8554 | survey_idx++; |
| 8555 | continue; |
| 8556 | } |
| 8557 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8558 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8559 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8560 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8561 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8562 | goto out; |
| 8563 | survey_idx++; |
| 8564 | } |
| 8565 | |
| 8566 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8567 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8568 | res = skb->len; |
| 8569 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8570 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8571 | return res; |
| 8572 | } |
| 8573 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8574 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 8575 | { |
| 8576 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 8577 | NL80211_WPA_VERSION_2)); |
| 8578 | } |
| 8579 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8580 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 8581 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8583 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8584 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8585 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 8586 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8587 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8588 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8589 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8590 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8591 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8592 | return -EINVAL; |
| 8593 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 8594 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 8595 | return -EINVAL; |
| 8596 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8597 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 8598 | return -EINVAL; |
| 8599 | |
| 8600 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8601 | return -EINVAL; |
| 8602 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8603 | err = nl80211_parse_key(info, &key); |
| 8604 | if (err) |
| 8605 | return err; |
| 8606 | |
| 8607 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 8608 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 8609 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8610 | if (!key.p.key || !key.p.key_len) |
| 8611 | return -EINVAL; |
| 8612 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 8613 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 8614 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 8615 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 8616 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 8617 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8618 | return -EINVAL; |
| 8619 | } else { |
| 8620 | key.p.key_len = 0; |
| 8621 | key.p.key = NULL; |
| 8622 | } |
| 8623 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8624 | if (key.idx >= 0) { |
| 8625 | int i; |
| 8626 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8627 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8628 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 8629 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 8630 | ok = true; |
| 8631 | break; |
| 8632 | } |
| 8633 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8634 | if (!ok) |
| 8635 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8636 | } |
| 8637 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8638 | if (!rdev->ops->auth) |
| 8639 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8640 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8641 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8642 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8643 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8644 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8645 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8646 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8647 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8648 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8649 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8650 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8651 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8652 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8653 | |
| 8654 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8655 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8656 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8657 | } |
| 8658 | |
| 8659 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8660 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8661 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8662 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8663 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 8664 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 8665 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 8666 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8667 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8668 | return -EINVAL; |
| 8669 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8670 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8671 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 8672 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 8673 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 8674 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8675 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8676 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 8677 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8678 | /* need to include at least Auth Transaction and Status Code */ |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8679 | if (auth_data_len < 4) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8680 | return -EINVAL; |
| 8681 | } |
| 8682 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8683 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8684 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 8685 | /* |
| 8686 | * Since we no longer track auth state, ignore |
| 8687 | * requests to only change local state. |
| 8688 | */ |
| 8689 | if (local_state_change) |
| 8690 | return 0; |
| 8691 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8692 | wdev_lock(dev->ieee80211_ptr); |
| 8693 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 8694 | ssid, ssid_len, ie, ie_len, |
| 8695 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8696 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8697 | wdev_unlock(dev->ieee80211_ptr); |
| 8698 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8699 | } |
| 8700 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 8701 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, |
| 8702 | struct genl_info *info) |
| 8703 | { |
| 8704 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8705 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); |
| 8706 | return -EINVAL; |
| 8707 | } |
| 8708 | |
| 8709 | if (!rdev->ops->tx_control_port || |
| 8710 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8711 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 8712 | return -EOPNOTSUPP; |
| 8713 | |
| 8714 | return 0; |
| 8715 | } |
| 8716 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8717 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 8718 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8719 | struct cfg80211_crypto_settings *settings, |
| 8720 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8721 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 8722 | memset(settings, 0, sizeof(*settings)); |
| 8723 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8724 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 8725 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8726 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 8727 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8728 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8729 | proto = nla_get_u16( |
| 8730 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 8731 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 8732 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 8733 | proto != ETH_P_PAE) |
| 8734 | return -EINVAL; |
| 8735 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 8736 | settings->control_port_no_encrypt = true; |
| 8737 | } else |
| 8738 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 8739 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 8740 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 8741 | int r = validate_pae_over_nl80211(rdev, info); |
| 8742 | |
| 8743 | if (r < 0) |
| 8744 | return r; |
| 8745 | |
| 8746 | settings->control_port_over_nl80211 = true; |
| 8747 | } |
| 8748 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8749 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 8750 | void *data; |
| 8751 | int len, i; |
| 8752 | |
| 8753 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8754 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8755 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 8756 | |
| 8757 | if (len % sizeof(u32)) |
| 8758 | return -EINVAL; |
| 8759 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8760 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8761 | return -EINVAL; |
| 8762 | |
| 8763 | memcpy(settings->ciphers_pairwise, data, len); |
| 8764 | |
| 8765 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8766 | if (!cfg80211_supported_cipher_suite( |
| 8767 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8768 | settings->ciphers_pairwise[i])) |
| 8769 | return -EINVAL; |
| 8770 | } |
| 8771 | |
| 8772 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 8773 | settings->cipher_group = |
| 8774 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8775 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 8776 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8777 | return -EINVAL; |
| 8778 | } |
| 8779 | |
| 8780 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 8781 | settings->wpa_versions = |
| 8782 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 8783 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 8784 | return -EINVAL; |
| 8785 | } |
| 8786 | |
| 8787 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 8788 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 8789 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8790 | |
| 8791 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8792 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8793 | settings->n_akm_suites = len / sizeof(u32); |
| 8794 | |
| 8795 | if (len % sizeof(u32)) |
| 8796 | return -EINVAL; |
| 8797 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 8798 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 8799 | return -EINVAL; |
| 8800 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8801 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8802 | } |
| 8803 | |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 8804 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 8805 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 8806 | return -EINVAL; |
| 8807 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8808 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) |
| 8809 | return -EINVAL; |
| 8810 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 8811 | } |
| 8812 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8813 | return 0; |
| 8814 | } |
| 8815 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8816 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 8817 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8818 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8819 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8820 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8821 | struct cfg80211_assoc_request req = {}; |
| 8822 | const u8 *bssid, *ssid; |
| 8823 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8824 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 8825 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 8826 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 8827 | return -EPERM; |
| 8828 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8829 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8830 | !info->attrs[NL80211_ATTR_SSID] || |
| 8831 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8832 | return -EINVAL; |
| 8833 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8834 | if (!rdev->ops->assoc) |
| 8835 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8836 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8837 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8838 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8839 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8840 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8841 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8842 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8843 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8844 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8845 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8846 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8847 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8848 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8849 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8850 | |
| 8851 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8852 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8853 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8854 | } |
| 8855 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8856 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8857 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8858 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8859 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8860 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8861 | else if (mfp != NL80211_MFP_NO) |
| 8862 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8863 | } |
| 8864 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8865 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8866 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8867 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8868 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8869 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8870 | |
| 8871 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8872 | memcpy(&req.ht_capa_mask, |
| 8873 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8874 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8875 | |
| 8876 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8877 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8878 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8879 | memcpy(&req.ht_capa, |
| 8880 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8881 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8882 | } |
| 8883 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8884 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8885 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8886 | |
| 8887 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8888 | memcpy(&req.vht_capa_mask, |
| 8889 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8890 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8891 | |
| 8892 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8893 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8894 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8895 | memcpy(&req.vht_capa, |
| 8896 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8897 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8898 | } |
| 8899 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8900 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8901 | if (!((rdev->wiphy.features & |
| 8902 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8903 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8904 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8905 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8906 | return -EINVAL; |
| 8907 | req.flags |= ASSOC_REQ_USE_RRM; |
| 8908 | } |
| 8909 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 8910 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 8911 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8912 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8913 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 8914 | return -EINVAL; |
| 8915 | req.fils_nonces = |
| 8916 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 8917 | } |
| 8918 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8919 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8920 | if (!err) { |
| 8921 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8922 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8923 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 8924 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8925 | |
| 8926 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8927 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 8928 | info->snd_portid; |
| 8929 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 8930 | bssid, ETH_ALEN); |
| 8931 | } |
| 8932 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8933 | wdev_unlock(dev->ieee80211_ptr); |
| 8934 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8935 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8936 | return err; |
| 8937 | } |
| 8938 | |
| 8939 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 8940 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8942 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8943 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8944 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8945 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8946 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8947 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 8948 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 8949 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 8950 | return -EPERM; |
| 8951 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8952 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8953 | return -EINVAL; |
| 8954 | |
| 8955 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8956 | return -EINVAL; |
| 8957 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8958 | if (!rdev->ops->deauth) |
| 8959 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8960 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8961 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8962 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8963 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8964 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8965 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8966 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8967 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8968 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8969 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8970 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8971 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8972 | |
| 8973 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8974 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8975 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8976 | } |
| 8977 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8978 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8979 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8980 | wdev_lock(dev->ieee80211_ptr); |
| 8981 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8982 | local_state_change); |
| 8983 | wdev_unlock(dev->ieee80211_ptr); |
| 8984 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8985 | } |
| 8986 | |
| 8987 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 8988 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8989 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8990 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8991 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8992 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8993 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8994 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8995 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 8996 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 8997 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 8998 | return -EPERM; |
| 8999 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9000 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9001 | return -EINVAL; |
| 9002 | |
| 9003 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9004 | return -EINVAL; |
| 9005 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9006 | if (!rdev->ops->disassoc) |
| 9007 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9008 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9009 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9010 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9011 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9012 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9013 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9014 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9015 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9016 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9017 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9018 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 9019 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9020 | |
| 9021 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9022 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9023 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9024 | } |
| 9025 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9026 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9027 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9028 | wdev_lock(dev->ieee80211_ptr); |
| 9029 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9030 | local_state_change); |
| 9031 | wdev_unlock(dev->ieee80211_ptr); |
| 9032 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9033 | } |
| 9034 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9035 | static bool |
| 9036 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9037 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9038 | int rateval) |
| 9039 | { |
| 9040 | struct wiphy *wiphy = &rdev->wiphy; |
| 9041 | bool found = false; |
| 9042 | int band, i; |
| 9043 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9044 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9045 | struct ieee80211_supported_band *sband; |
| 9046 | |
| 9047 | sband = wiphy->bands[band]; |
| 9048 | if (!sband) |
| 9049 | continue; |
| 9050 | |
| 9051 | for (i = 0; i < sband->n_bitrates; i++) { |
| 9052 | if (sband->bitrates[i].bitrate == rateval) { |
| 9053 | mcast_rate[band] = i + 1; |
| 9054 | found = true; |
| 9055 | break; |
| 9056 | } |
| 9057 | } |
| 9058 | } |
| 9059 | |
| 9060 | return found; |
| 9061 | } |
| 9062 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9063 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 9064 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9066 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9067 | struct cfg80211_ibss_params ibss; |
| 9068 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9069 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9070 | int err; |
| 9071 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9072 | memset(&ibss, 0, sizeof(ibss)); |
| 9073 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9074 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9075 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 9076 | return -EINVAL; |
| 9077 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9078 | ibss.beacon_interval = 100; |
| 9079 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9080 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9081 | ibss.beacon_interval = |
| 9082 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9083 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 9084 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 9085 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9086 | if (err) |
| 9087 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9088 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9089 | if (!rdev->ops->join_ibss) |
| 9090 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9091 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9092 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 9093 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9094 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 9095 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9096 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 9097 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9098 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 9099 | |
| 9100 | if (!is_valid_ether_addr(ibss.bssid)) |
| 9101 | return -EINVAL; |
| 9102 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9103 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9104 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9105 | |
| 9106 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9107 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9108 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9109 | } |
| 9110 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9111 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 9112 | if (err) |
| 9113 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 9114 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 9115 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 9116 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 9117 | return -EINVAL; |
| 9118 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9119 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 9120 | case NL80211_CHAN_WIDTH_5: |
| 9121 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9122 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 9123 | break; |
| 9124 | case NL80211_CHAN_WIDTH_20: |
| 9125 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 9126 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 9127 | return -EINVAL; |
| 9128 | break; |
| 9129 | case NL80211_CHAN_WIDTH_80: |
| 9130 | case NL80211_CHAN_WIDTH_80P80: |
| 9131 | case NL80211_CHAN_WIDTH_160: |
| 9132 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 9133 | return -EINVAL; |
| 9134 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9135 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 9136 | return -EINVAL; |
| 9137 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9138 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 9139 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9140 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 9141 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9142 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9143 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9144 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9145 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9146 | u8 *rates = |
| 9147 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9148 | int n_rates = |
| 9149 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9150 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9151 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9152 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 9153 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9154 | &ibss.basic_rates); |
| 9155 | if (err) |
| 9156 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9157 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9158 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 9159 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9160 | memcpy(&ibss.ht_capa_mask, |
| 9161 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9162 | sizeof(ibss.ht_capa_mask)); |
| 9163 | |
| 9164 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 9165 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9166 | return -EINVAL; |
| 9167 | memcpy(&ibss.ht_capa, |
| 9168 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9169 | sizeof(ibss.ht_capa)); |
| 9170 | } |
| 9171 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9172 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9173 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 9174 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9175 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9176 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9177 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 9178 | bool no_ht = false; |
| 9179 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 9180 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9181 | if (IS_ERR(connkeys)) |
| 9182 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 9183 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 9184 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 9185 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 9186 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 9187 | return -EINVAL; |
| 9188 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9189 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9190 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 9191 | ibss.control_port = |
| 9192 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 9193 | |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 9194 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 9195 | int r = validate_pae_over_nl80211(rdev, info); |
| 9196 | |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 9197 | if (r < 0) { |
| 9198 | kzfree(connkeys); |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 9199 | return r; |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 9200 | } |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 9201 | |
| 9202 | ibss.control_port_over_nl80211 = true; |
| 9203 | } |
| 9204 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 9205 | ibss.userspace_handles_dfs = |
| 9206 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 9207 | |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 9208 | wdev_lock(dev->ieee80211_ptr); |
| 9209 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9210 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9211 | kzfree(connkeys); |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 9212 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 9213 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 9214 | wdev_unlock(dev->ieee80211_ptr); |
| 9215 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9216 | return err; |
| 9217 | } |
| 9218 | |
| 9219 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 9220 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9221 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9222 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9223 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9224 | if (!rdev->ops->leave_ibss) |
| 9225 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9226 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9227 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 9228 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9229 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9230 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9231 | } |
| 9232 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9233 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 9234 | { |
| 9235 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9236 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9237 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9238 | u32 nla_rate; |
| 9239 | int err; |
| 9240 | |
| 9241 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 9242 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 9243 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9244 | return -EOPNOTSUPP; |
| 9245 | |
| 9246 | if (!rdev->ops->set_mcast_rate) |
| 9247 | return -EOPNOTSUPP; |
| 9248 | |
| 9249 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 9250 | |
| 9251 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 9252 | return -EINVAL; |
| 9253 | |
| 9254 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 9255 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 9256 | return -EINVAL; |
| 9257 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 9258 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9259 | |
| 9260 | return err; |
| 9261 | } |
| 9262 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9263 | static struct sk_buff * |
| 9264 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9265 | struct wireless_dev *wdev, int approxlen, |
| 9266 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9267 | enum nl80211_attrs attr, |
| 9268 | const struct nl80211_vendor_cmd_info *info, |
| 9269 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9270 | { |
| 9271 | struct sk_buff *skb; |
| 9272 | void *hdr; |
| 9273 | struct nlattr *data; |
| 9274 | |
| 9275 | skb = nlmsg_new(approxlen + 100, gfp); |
| 9276 | if (!skb) |
| 9277 | return NULL; |
| 9278 | |
| 9279 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 9280 | if (!hdr) { |
| 9281 | kfree_skb(skb); |
| 9282 | return NULL; |
| 9283 | } |
| 9284 | |
| 9285 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 9286 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9287 | |
| 9288 | if (info) { |
| 9289 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 9290 | info->vendor_id)) |
| 9291 | goto nla_put_failure; |
| 9292 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 9293 | info->subcmd)) |
| 9294 | goto nla_put_failure; |
| 9295 | } |
| 9296 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9297 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9298 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 9299 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9300 | goto nla_put_failure; |
| 9301 | if (wdev->netdev && |
| 9302 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 9303 | wdev->netdev->ifindex)) |
| 9304 | goto nla_put_failure; |
| 9305 | } |
| 9306 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9307 | data = nla_nest_start(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9308 | if (!data) |
| 9309 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9310 | |
| 9311 | ((void **)skb->cb)[0] = rdev; |
| 9312 | ((void **)skb->cb)[1] = hdr; |
| 9313 | ((void **)skb->cb)[2] = data; |
| 9314 | |
| 9315 | return skb; |
| 9316 | |
| 9317 | nla_put_failure: |
| 9318 | kfree_skb(skb); |
| 9319 | return NULL; |
| 9320 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9321 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9322 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9323 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9324 | enum nl80211_commands cmd, |
| 9325 | enum nl80211_attrs attr, |
| 9326 | int vendor_event_idx, |
| 9327 | int approxlen, gfp_t gfp) |
| 9328 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9329 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9330 | const struct nl80211_vendor_cmd_info *info; |
| 9331 | |
| 9332 | switch (cmd) { |
| 9333 | case NL80211_CMD_TESTMODE: |
| 9334 | if (WARN_ON(vendor_event_idx != -1)) |
| 9335 | return NULL; |
| 9336 | info = NULL; |
| 9337 | break; |
| 9338 | case NL80211_CMD_VENDOR: |
| 9339 | if (WARN_ON(vendor_event_idx < 0 || |
| 9340 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 9341 | return NULL; |
| 9342 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 9343 | break; |
| 9344 | default: |
| 9345 | WARN_ON(1); |
| 9346 | return NULL; |
| 9347 | } |
| 9348 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9349 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9350 | cmd, attr, info, gfp); |
| 9351 | } |
| 9352 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 9353 | |
| 9354 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 9355 | { |
| 9356 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9357 | void *hdr = ((void **)skb->cb)[1]; |
| 9358 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9359 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 9360 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9361 | /* clear CB data for netlink core to own from now on */ |
| 9362 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 9363 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9364 | nla_nest_end(skb, data); |
| 9365 | genlmsg_end(skb, hdr); |
| 9366 | |
| 9367 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 9368 | mcgrp = NL80211_MCGRP_VENDOR; |
| 9369 | |
| 9370 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 9371 | mcgrp, gfp); |
| 9372 | } |
| 9373 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 9374 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9375 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9376 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 9377 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 9379 | struct wireless_dev *wdev = |
| 9380 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9381 | int err; |
| 9382 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 9383 | if (!rdev->ops->testmode_cmd) |
| 9384 | return -EOPNOTSUPP; |
| 9385 | |
| 9386 | if (IS_ERR(wdev)) { |
| 9387 | err = PTR_ERR(wdev); |
| 9388 | if (err != -EINVAL) |
| 9389 | return err; |
| 9390 | wdev = NULL; |
| 9391 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9392 | return -EINVAL; |
| 9393 | } |
| 9394 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9395 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 9396 | return -EINVAL; |
| 9397 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9398 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 9399 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9400 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 9401 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9402 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9403 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9404 | return err; |
| 9405 | } |
| 9406 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9407 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 9408 | struct netlink_callback *cb) |
| 9409 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 9410 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9411 | int err; |
| 9412 | long phy_idx; |
| 9413 | void *data = NULL; |
| 9414 | int data_len = 0; |
| 9415 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9416 | rtnl_lock(); |
| 9417 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9418 | if (cb->args[0]) { |
| 9419 | /* |
| 9420 | * 0 is a valid index, but not valid for args[0], |
| 9421 | * so we need to offset by 1. |
| 9422 | */ |
| 9423 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 9424 | |
| 9425 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 9426 | if (!rdev) { |
| 9427 | err = -ENOENT; |
| 9428 | goto out_err; |
| 9429 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9430 | } else { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9431 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
| 9432 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9433 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 9434 | attrbuf, nl80211_fam.maxattr, |
| 9435 | nl80211_policy, NULL); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9436 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9437 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 9438 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9439 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 9440 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9441 | err = PTR_ERR(rdev); |
| 9442 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 9443 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 9444 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 9445 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9446 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 9447 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9448 | } |
| 9449 | |
| 9450 | if (cb->args[1]) { |
| 9451 | data = nla_data((void *)cb->args[1]); |
| 9452 | data_len = nla_len((void *)cb->args[1]); |
| 9453 | } |
| 9454 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 9455 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9456 | err = -EOPNOTSUPP; |
| 9457 | goto out_err; |
| 9458 | } |
| 9459 | |
| 9460 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9461 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9462 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 9463 | NL80211_CMD_TESTMODE); |
| 9464 | struct nlattr *tmdata; |
| 9465 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9466 | if (!hdr) |
| 9467 | break; |
| 9468 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9469 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9470 | genlmsg_cancel(skb, hdr); |
| 9471 | break; |
| 9472 | } |
| 9473 | |
| 9474 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 9475 | if (!tmdata) { |
| 9476 | genlmsg_cancel(skb, hdr); |
| 9477 | break; |
| 9478 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9479 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9480 | nla_nest_end(skb, tmdata); |
| 9481 | |
| 9482 | if (err == -ENOBUFS || err == -ENOENT) { |
| 9483 | genlmsg_cancel(skb, hdr); |
| 9484 | break; |
| 9485 | } else if (err) { |
| 9486 | genlmsg_cancel(skb, hdr); |
| 9487 | goto out_err; |
| 9488 | } |
| 9489 | |
| 9490 | genlmsg_end(skb, hdr); |
| 9491 | } |
| 9492 | |
| 9493 | err = skb->len; |
| 9494 | /* see above */ |
| 9495 | cb->args[0] = phy_idx + 1; |
| 9496 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9497 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9498 | return err; |
| 9499 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9500 | #endif |
| 9501 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9502 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 9503 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9505 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9506 | struct cfg80211_connect_params connect; |
| 9507 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9508 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9509 | int err; |
| 9510 | |
| 9511 | memset(&connect, 0, sizeof(connect)); |
| 9512 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9513 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 9514 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 9515 | return -EINVAL; |
| 9516 | |
| 9517 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 9518 | connect.auth_type = |
| 9519 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9520 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 9521 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9522 | return -EINVAL; |
| 9523 | } else |
| 9524 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 9525 | |
| 9526 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 9527 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 9528 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 9529 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9530 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 9531 | return -EINVAL; |
| 9532 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 9533 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9534 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 9535 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9536 | if (err) |
| 9537 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9538 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9539 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9540 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9541 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9542 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 9543 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9544 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 9545 | connect.bg_scan_period = -1; |
| 9546 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 9547 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 9548 | connect.bg_scan_period = |
| 9549 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 9550 | } |
| 9551 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9552 | if (info->attrs[NL80211_ATTR_MAC]) |
| 9553 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 9554 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 9555 | connect.bssid_hint = |
| 9556 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9557 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9558 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9559 | |
| 9560 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9561 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9562 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9563 | } |
| 9564 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 9565 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 9566 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 9567 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
| 9568 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9569 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) |
| 9570 | return -EOPNOTSUPP; |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 9571 | } else { |
| 9572 | connect.mfp = NL80211_MFP_NO; |
| 9573 | } |
| 9574 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 9575 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 9576 | connect.prev_bssid = |
| 9577 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 9578 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9579 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9580 | connect.channel = nl80211_get_valid_chan( |
| 9581 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 9582 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9583 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 9584 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9585 | connect.channel_hint = nl80211_get_valid_chan( |
| 9586 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 9587 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 9588 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9589 | } |
| 9590 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9591 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 9592 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9593 | if (IS_ERR(connkeys)) |
| 9594 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9595 | } |
| 9596 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9597 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 9598 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 9599 | |
| 9600 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9601 | memcpy(&connect.ht_capa_mask, |
| 9602 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9603 | sizeof(connect.ht_capa_mask)); |
| 9604 | |
| 9605 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 9606 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9607 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9608 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 9609 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9610 | memcpy(&connect.ht_capa, |
| 9611 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9612 | sizeof(connect.ht_capa)); |
| 9613 | } |
| 9614 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9615 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 9616 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 9617 | |
| 9618 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 9619 | memcpy(&connect.vht_capa_mask, |
| 9620 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 9621 | sizeof(connect.vht_capa_mask)); |
| 9622 | |
| 9623 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 9624 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9625 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9626 | return -EINVAL; |
| 9627 | } |
| 9628 | memcpy(&connect.vht_capa, |
| 9629 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 9630 | sizeof(connect.vht_capa)); |
| 9631 | } |
| 9632 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9633 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 9634 | if (!((rdev->wiphy.features & |
| 9635 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 9636 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 9637 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9638 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 9639 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9640 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 9641 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9642 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 9643 | } |
| 9644 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 9645 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9646 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 9647 | kzfree(connkeys); |
| 9648 | return -EOPNOTSUPP; |
| 9649 | } |
| 9650 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 9651 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 9652 | /* bss selection makes no sense if bssid is set */ |
| 9653 | if (connect.bssid) { |
| 9654 | kzfree(connkeys); |
| 9655 | return -EINVAL; |
| 9656 | } |
| 9657 | |
| 9658 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 9659 | wiphy, &connect.bss_select); |
| 9660 | if (err) { |
| 9661 | kzfree(connkeys); |
| 9662 | return err; |
| 9663 | } |
| 9664 | } |
| 9665 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9666 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 9667 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 9668 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 9669 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 9670 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 9671 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9672 | connect.fils_erp_username = |
| 9673 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9674 | connect.fils_erp_username_len = |
| 9675 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9676 | connect.fils_erp_realm = |
| 9677 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9678 | connect.fils_erp_realm_len = |
| 9679 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9680 | connect.fils_erp_next_seq_num = |
| 9681 | nla_get_u16( |
| 9682 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 9683 | connect.fils_erp_rrk = |
| 9684 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9685 | connect.fils_erp_rrk_len = |
| 9686 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9687 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 9688 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 9689 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 9690 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9691 | kzfree(connkeys); |
| 9692 | return -EINVAL; |
| 9693 | } |
| 9694 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 9695 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
| 9696 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
Srinivas Dasari | 2f0605a | 2018-04-20 11:41:14 +0530 | [diff] [blame] | 9697 | kzfree(connkeys); |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 9698 | GENL_SET_ERR_MSG(info, |
| 9699 | "external auth requires connection ownership"); |
| 9700 | return -EINVAL; |
| 9701 | } |
| 9702 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; |
| 9703 | } |
| 9704 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9705 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9706 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 9707 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 9708 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9709 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9710 | kzfree(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9711 | |
| 9712 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9713 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 9714 | if (connect.bssid) |
| 9715 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 9716 | connect.bssid, ETH_ALEN); |
| 9717 | else |
| 9718 | memset(dev->ieee80211_ptr->disconnect_bssid, |
| 9719 | 0, ETH_ALEN); |
| 9720 | } |
| 9721 | |
| 9722 | wdev_unlock(dev->ieee80211_ptr); |
| 9723 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9724 | return err; |
| 9725 | } |
| 9726 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 9727 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 9728 | struct genl_info *info) |
| 9729 | { |
| 9730 | struct cfg80211_connect_params connect = {}; |
| 9731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9732 | struct net_device *dev = info->user_ptr[1]; |
| 9733 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 9734 | bool fils_sk_offload; |
| 9735 | u32 auth_type; |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 9736 | u32 changed = 0; |
| 9737 | int ret; |
| 9738 | |
| 9739 | if (!rdev->ops->update_connect_params) |
| 9740 | return -EOPNOTSUPP; |
| 9741 | |
| 9742 | if (info->attrs[NL80211_ATTR_IE]) { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 9743 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9744 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9745 | changed |= UPDATE_ASSOC_IES; |
| 9746 | } |
| 9747 | |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 9748 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, |
| 9749 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); |
| 9750 | |
| 9751 | /* |
| 9752 | * when driver supports fils-sk offload all attributes must be |
| 9753 | * provided. So the else covers "fils-sk-not-all" and |
| 9754 | * "no-fils-sk-any". |
| 9755 | */ |
| 9756 | if (fils_sk_offload && |
| 9757 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 9758 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 9759 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 9760 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9761 | connect.fils_erp_username = |
| 9762 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9763 | connect.fils_erp_username_len = |
| 9764 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9765 | connect.fils_erp_realm = |
| 9766 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9767 | connect.fils_erp_realm_len = |
| 9768 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9769 | connect.fils_erp_next_seq_num = |
| 9770 | nla_get_u16( |
| 9771 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 9772 | connect.fils_erp_rrk = |
| 9773 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9774 | connect.fils_erp_rrk_len = |
| 9775 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9776 | changed |= UPDATE_FILS_ERP_INFO; |
| 9777 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 9778 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 9779 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 9780 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9781 | return -EINVAL; |
| 9782 | } |
| 9783 | |
| 9784 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 9785 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 9786 | if (!nl80211_valid_auth_type(rdev, auth_type, |
| 9787 | NL80211_CMD_CONNECT)) |
| 9788 | return -EINVAL; |
| 9789 | |
| 9790 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && |
| 9791 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) |
| 9792 | return -EINVAL; |
| 9793 | |
| 9794 | connect.auth_type = auth_type; |
| 9795 | changed |= UPDATE_AUTH_TYPE; |
| 9796 | } |
| 9797 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 9798 | wdev_lock(dev->ieee80211_ptr); |
| 9799 | if (!wdev->current_bss) |
| 9800 | ret = -ENOLINK; |
| 9801 | else |
| 9802 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 9803 | wdev_unlock(dev->ieee80211_ptr); |
| 9804 | |
| 9805 | return ret; |
| 9806 | } |
| 9807 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9808 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 9809 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9811 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9812 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9813 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9814 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9815 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9816 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9817 | return -EPERM; |
| 9818 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9819 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9820 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 9821 | else |
| 9822 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9823 | |
| 9824 | if (reason == 0) |
| 9825 | return -EINVAL; |
| 9826 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9827 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9828 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9829 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9830 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9831 | wdev_lock(dev->ieee80211_ptr); |
| 9832 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 9833 | wdev_unlock(dev->ieee80211_ptr); |
| 9834 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9835 | } |
| 9836 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9837 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 9838 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9839 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9840 | struct net *net; |
| 9841 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9842 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9843 | if (info->attrs[NL80211_ATTR_PID]) { |
| 9844 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 9845 | |
| 9846 | net = get_net_ns_by_pid(pid); |
| 9847 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 9848 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 9849 | |
| 9850 | net = get_net_ns_by_fd(fd); |
| 9851 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9852 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9853 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9854 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9855 | if (IS_ERR(net)) |
| 9856 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9857 | |
| 9858 | err = 0; |
| 9859 | |
| 9860 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9861 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 9862 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9863 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9864 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9865 | return err; |
| 9866 | } |
| 9867 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9868 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9869 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9870 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9871 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 9872 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9873 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9874 | struct cfg80211_pmksa pmksa; |
| 9875 | |
| 9876 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 9877 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9878 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 9879 | return -EINVAL; |
| 9880 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9881 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9882 | |
| 9883 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 9884 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9885 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 9886 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 9887 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 9888 | info->attrs[NL80211_ATTR_PMK])) { |
| 9889 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9890 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9891 | pmksa.cache_id = |
| 9892 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 9893 | } else { |
| 9894 | return -EINVAL; |
| 9895 | } |
| 9896 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9897 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9898 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 9899 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9900 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9901 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9902 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9903 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9904 | |
| 9905 | switch (info->genlhdr->cmd) { |
| 9906 | case NL80211_CMD_SET_PMKSA: |
| 9907 | rdev_ops = rdev->ops->set_pmksa; |
| 9908 | break; |
| 9909 | case NL80211_CMD_DEL_PMKSA: |
| 9910 | rdev_ops = rdev->ops->del_pmksa; |
| 9911 | break; |
| 9912 | default: |
| 9913 | WARN_ON(1); |
| 9914 | break; |
| 9915 | } |
| 9916 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9917 | if (!rdev_ops) |
| 9918 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9920 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9921 | } |
| 9922 | |
| 9923 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9924 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9926 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9927 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9928 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9929 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9930 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9931 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9932 | if (!rdev->ops->flush_pmksa) |
| 9933 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9934 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9935 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9936 | } |
| 9937 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9938 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 9939 | { |
| 9940 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9941 | struct net_device *dev = info->user_ptr[1]; |
| 9942 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9943 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9944 | u16 status_code; |
| 9945 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9946 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9947 | |
| 9948 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9949 | !rdev->ops->tdls_mgmt) |
| 9950 | return -EOPNOTSUPP; |
| 9951 | |
| 9952 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 9953 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 9954 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 9955 | !info->attrs[NL80211_ATTR_IE] || |
| 9956 | !info->attrs[NL80211_ATTR_MAC]) |
| 9957 | return -EINVAL; |
| 9958 | |
| 9959 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9960 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 9961 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 9962 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9963 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9964 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 9965 | peer_capability = |
| 9966 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9967 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9968 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9969 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9970 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9971 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 9972 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9973 | } |
| 9974 | |
| 9975 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 9976 | { |
| 9977 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9978 | struct net_device *dev = info->user_ptr[1]; |
| 9979 | enum nl80211_tdls_operation operation; |
| 9980 | u8 *peer; |
| 9981 | |
| 9982 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9983 | !rdev->ops->tdls_oper) |
| 9984 | return -EOPNOTSUPP; |
| 9985 | |
| 9986 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 9987 | !info->attrs[NL80211_ATTR_MAC]) |
| 9988 | return -EINVAL; |
| 9989 | |
| 9990 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 9991 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9992 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9993 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9994 | } |
| 9995 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9996 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 9997 | struct genl_info *info) |
| 9998 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9999 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10000 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10001 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10002 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10003 | struct sk_buff *msg; |
| 10004 | void *hdr; |
| 10005 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10006 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10007 | int err; |
| 10008 | |
| 10009 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 10010 | !info->attrs[NL80211_ATTR_DURATION]) |
| 10011 | return -EINVAL; |
| 10012 | |
| 10013 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 10014 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10015 | if (!rdev->ops->remain_on_channel || |
| 10016 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10017 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10018 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10019 | /* |
| 10020 | * We should be on that channel for at least a minimum amount of |
| 10021 | * time (10ms) but no longer than the driver supports. |
| 10022 | */ |
| 10023 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 10024 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 10025 | return -EINVAL; |
| 10026 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10027 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10028 | if (err) |
| 10029 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10030 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10031 | wdev_lock(wdev); |
| 10032 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 10033 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 10034 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 10035 | &chandef); |
| 10036 | if (compat_chandef != &chandef) { |
| 10037 | wdev_unlock(wdev); |
| 10038 | return -EBUSY; |
| 10039 | } |
| 10040 | } |
| 10041 | wdev_unlock(wdev); |
| 10042 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10043 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10044 | if (!msg) |
| 10045 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10046 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10047 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10048 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10049 | if (!hdr) { |
| 10050 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10051 | goto free_msg; |
| 10052 | } |
| 10053 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10054 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 10055 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10056 | |
| 10057 | if (err) |
| 10058 | goto free_msg; |
| 10059 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10060 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10061 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10062 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10063 | |
| 10064 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10065 | |
| 10066 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10067 | |
| 10068 | nla_put_failure: |
| 10069 | err = -ENOBUFS; |
| 10070 | free_msg: |
| 10071 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10072 | return err; |
| 10073 | } |
| 10074 | |
| 10075 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 10076 | struct genl_info *info) |
| 10077 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10078 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10079 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10080 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10081 | |
| 10082 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 10083 | return -EINVAL; |
| 10084 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10085 | if (!rdev->ops->cancel_remain_on_channel) |
| 10086 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10087 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10088 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 10089 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10090 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10091 | } |
| 10092 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10093 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 10094 | struct genl_info *info) |
| 10095 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10096 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10098 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10099 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10100 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10101 | if (!rdev->ops->set_bitrate_mask) |
| 10102 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10103 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10104 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
| 10105 | if (err) |
| 10106 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 10107 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10108 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10109 | } |
| 10110 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10111 | 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] | 10112 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10114 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10115 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10116 | |
| 10117 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 10118 | return -EINVAL; |
| 10119 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10120 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 10121 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10122 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10123 | switch (wdev->iftype) { |
| 10124 | case NL80211_IFTYPE_STATION: |
| 10125 | case NL80211_IFTYPE_ADHOC: |
| 10126 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10127 | case NL80211_IFTYPE_AP: |
| 10128 | case NL80211_IFTYPE_AP_VLAN: |
| 10129 | case NL80211_IFTYPE_MESH_POINT: |
| 10130 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10131 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10132 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10133 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10134 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10135 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10136 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10137 | |
| 10138 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10139 | if (!rdev->ops->mgmt_tx) |
| 10140 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10141 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10142 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10143 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 10144 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10145 | } |
| 10146 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10147 | 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] | 10148 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10150 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10151 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10152 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 10153 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10154 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10155 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10156 | struct cfg80211_mgmt_tx_params params = { |
| 10157 | .dont_wait_for_ack = |
| 10158 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 10159 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10160 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10161 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10162 | return -EINVAL; |
| 10163 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10164 | if (!rdev->ops->mgmt_tx) |
| 10165 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10166 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10167 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10168 | case NL80211_IFTYPE_P2P_DEVICE: |
| 10169 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 10170 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10171 | case NL80211_IFTYPE_STATION: |
| 10172 | case NL80211_IFTYPE_ADHOC: |
| 10173 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10174 | case NL80211_IFTYPE_AP: |
| 10175 | case NL80211_IFTYPE_AP_VLAN: |
| 10176 | case NL80211_IFTYPE_MESH_POINT: |
| 10177 | case NL80211_IFTYPE_P2P_GO: |
| 10178 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10179 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10180 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10181 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10182 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10183 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10184 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10185 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10186 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10187 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10188 | |
| 10189 | /* |
| 10190 | * We should wait on the channel for at least a minimum amount |
| 10191 | * of time (10ms) but no longer than the driver supports. |
| 10192 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10193 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 10194 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10195 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10196 | } |
| 10197 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10198 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10199 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10200 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10201 | return -EINVAL; |
| 10202 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10203 | 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] | 10204 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10205 | /* get the channel if any has been specified, otherwise pass NULL to |
| 10206 | * the driver. The latter will use the current one |
| 10207 | */ |
| 10208 | chandef.chan = NULL; |
| 10209 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 10210 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10211 | if (err) |
| 10212 | return err; |
| 10213 | } |
| 10214 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10215 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10216 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10217 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10218 | wdev_lock(wdev); |
| 10219 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 10220 | wdev_unlock(wdev); |
| 10221 | return -EBUSY; |
| 10222 | } |
| 10223 | wdev_unlock(wdev); |
| 10224 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 10225 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 10226 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 10227 | |
| 10228 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 10229 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 10230 | int i; |
| 10231 | |
| 10232 | if (len % sizeof(u16)) |
| 10233 | return -EINVAL; |
| 10234 | |
| 10235 | params.n_csa_offsets = len / sizeof(u16); |
| 10236 | params.csa_offsets = |
| 10237 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 10238 | |
| 10239 | /* check that all the offsets fit the frame */ |
| 10240 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 10241 | if (params.csa_offsets[i] >= params.len) |
| 10242 | return -EINVAL; |
| 10243 | } |
| 10244 | } |
| 10245 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10246 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10247 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10248 | if (!msg) |
| 10249 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10250 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10251 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10252 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10253 | if (!hdr) { |
| 10254 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10255 | goto free_msg; |
| 10256 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10257 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10258 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10259 | params.chan = chandef.chan; |
| 10260 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10261 | if (err) |
| 10262 | goto free_msg; |
| 10263 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10264 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10265 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10266 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10267 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10268 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10269 | genlmsg_end(msg, hdr); |
| 10270 | return genlmsg_reply(msg, info); |
| 10271 | } |
| 10272 | |
| 10273 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10274 | |
| 10275 | nla_put_failure: |
| 10276 | err = -ENOBUFS; |
| 10277 | free_msg: |
| 10278 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10279 | return err; |
| 10280 | } |
| 10281 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10282 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 10283 | { |
| 10284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10285 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10286 | u64 cookie; |
| 10287 | |
| 10288 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 10289 | return -EINVAL; |
| 10290 | |
| 10291 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 10292 | return -EOPNOTSUPP; |
| 10293 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10294 | switch (wdev->iftype) { |
| 10295 | case NL80211_IFTYPE_STATION: |
| 10296 | case NL80211_IFTYPE_ADHOC: |
| 10297 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10298 | case NL80211_IFTYPE_AP: |
| 10299 | case NL80211_IFTYPE_AP_VLAN: |
| 10300 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10301 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10302 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10303 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10304 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10305 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10306 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10307 | |
| 10308 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 10309 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10310 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10311 | } |
| 10312 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10313 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 10314 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10315 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10316 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10317 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10318 | u8 ps_state; |
| 10319 | bool state; |
| 10320 | int err; |
| 10321 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10322 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 10323 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10324 | |
| 10325 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 10326 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10327 | wdev = dev->ieee80211_ptr; |
| 10328 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10329 | if (!rdev->ops->set_power_mgmt) |
| 10330 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10331 | |
| 10332 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 10333 | |
| 10334 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10335 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10336 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10337 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10338 | if (!err) |
| 10339 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10340 | return err; |
| 10341 | } |
| 10342 | |
| 10343 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 10344 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10345 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10346 | enum nl80211_ps_state ps_state; |
| 10347 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10348 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10349 | struct sk_buff *msg; |
| 10350 | void *hdr; |
| 10351 | int err; |
| 10352 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10353 | wdev = dev->ieee80211_ptr; |
| 10354 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10355 | if (!rdev->ops->set_power_mgmt) |
| 10356 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10357 | |
| 10358 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10359 | if (!msg) |
| 10360 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10361 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10362 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10363 | NL80211_CMD_GET_POWER_SAVE); |
| 10364 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10365 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10366 | goto free_msg; |
| 10367 | } |
| 10368 | |
| 10369 | if (wdev->ps) |
| 10370 | ps_state = NL80211_PS_ENABLED; |
| 10371 | else |
| 10372 | ps_state = NL80211_PS_DISABLED; |
| 10373 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10374 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 10375 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10376 | |
| 10377 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10378 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10379 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10380 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10381 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10382 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10383 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10384 | return err; |
| 10385 | } |
| 10386 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 10387 | static const struct nla_policy |
| 10388 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10389 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10390 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 10391 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10392 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 10393 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 10394 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 10395 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10396 | }; |
| 10397 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10398 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 10399 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10400 | { |
| 10401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10402 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10403 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10404 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 10405 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10406 | return -EINVAL; |
| 10407 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10408 | if (!rdev->ops->set_cqm_txe_config) |
| 10409 | return -EOPNOTSUPP; |
| 10410 | |
| 10411 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 10412 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10413 | return -EOPNOTSUPP; |
| 10414 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10415 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10416 | } |
| 10417 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10418 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 10419 | struct net_device *dev) |
| 10420 | { |
| 10421 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10422 | s32 last, low, high; |
| 10423 | u32 hyst; |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 10424 | int i, n, low_index; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10425 | int err; |
| 10426 | |
| 10427 | /* RSSI reporting disabled? */ |
| 10428 | if (!wdev->cqm_config) |
| 10429 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 10430 | |
| 10431 | /* |
| 10432 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 10433 | * event has been received yet, we should receive an event after a |
| 10434 | * connection is established and enough beacons received to calculate |
| 10435 | * the average. |
| 10436 | */ |
| 10437 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 10438 | rdev->ops->get_station) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 10439 | struct station_info sinfo = {}; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10440 | u8 *mac_addr; |
| 10441 | |
| 10442 | mac_addr = wdev->current_bss->pub.bssid; |
| 10443 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 10444 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 10445 | if (err) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10446 | return err; |
| 10447 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 10448 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10449 | wdev->cqm_config->last_rssi_event_value = |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 10450 | (s8) sinfo.rx_beacon_signal_avg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10451 | } |
| 10452 | |
| 10453 | last = wdev->cqm_config->last_rssi_event_value; |
| 10454 | hyst = wdev->cqm_config->rssi_hyst; |
| 10455 | n = wdev->cqm_config->n_rssi_thresholds; |
| 10456 | |
| 10457 | for (i = 0; i < n; i++) |
| 10458 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 10459 | break; |
| 10460 | |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 10461 | low_index = i - 1; |
| 10462 | if (low_index >= 0) { |
| 10463 | low_index = array_index_nospec(low_index, n); |
| 10464 | low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; |
| 10465 | } else { |
| 10466 | low = S32_MIN; |
| 10467 | } |
| 10468 | if (i < n) { |
| 10469 | i = array_index_nospec(i, n); |
| 10470 | high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; |
| 10471 | } else { |
| 10472 | high = S32_MAX; |
| 10473 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10474 | |
| 10475 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 10476 | } |
| 10477 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10478 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10479 | const s32 *thresholds, int n_thresholds, |
| 10480 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10481 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10483 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10484 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10485 | int i, err; |
| 10486 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10487 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10488 | /* Check all values negative and sorted */ |
| 10489 | for (i = 0; i < n_thresholds; i++) { |
| 10490 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 10491 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10492 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10493 | prev = thresholds[i]; |
| 10494 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10495 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10496 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10497 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10498 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10499 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10500 | wdev_lock(wdev); |
| 10501 | cfg80211_cqm_config_free(wdev); |
| 10502 | wdev_unlock(wdev); |
| 10503 | |
| 10504 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 10505 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 10506 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 10507 | |
| 10508 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 10509 | thresholds[0], hysteresis); |
| 10510 | } |
| 10511 | |
| 10512 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 10513 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 10514 | return -EOPNOTSUPP; |
| 10515 | |
| 10516 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 10517 | n_thresholds = 0; |
| 10518 | |
| 10519 | wdev_lock(wdev); |
| 10520 | if (n_thresholds) { |
| 10521 | struct cfg80211_cqm_config *cqm_config; |
| 10522 | |
| 10523 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 10524 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 10525 | if (!cqm_config) { |
| 10526 | err = -ENOMEM; |
| 10527 | goto unlock; |
| 10528 | } |
| 10529 | |
| 10530 | cqm_config->rssi_hyst = hysteresis; |
| 10531 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 10532 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 10533 | n_thresholds * sizeof(s32)); |
| 10534 | |
| 10535 | wdev->cqm_config = cqm_config; |
| 10536 | } |
| 10537 | |
| 10538 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 10539 | |
| 10540 | unlock: |
| 10541 | wdev_unlock(wdev); |
| 10542 | |
| 10543 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10544 | } |
| 10545 | |
| 10546 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 10547 | { |
| 10548 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 10549 | struct nlattr *cqm; |
| 10550 | int err; |
| 10551 | |
| 10552 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10553 | if (!cqm) |
| 10554 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10555 | |
| 10556 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10557 | nl80211_attr_cqm_policy, info->extack); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10558 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10559 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10560 | |
| 10561 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 10562 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10563 | const s32 *thresholds = |
| 10564 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 10565 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10566 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10567 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10568 | if (len % 4) |
| 10569 | return -EINVAL; |
| 10570 | |
| 10571 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 10572 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10573 | } |
| 10574 | |
| 10575 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 10576 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 10577 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 10578 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 10579 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 10580 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 10581 | |
| 10582 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 10583 | } |
| 10584 | |
| 10585 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10586 | } |
| 10587 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 10588 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 10589 | { |
| 10590 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10591 | struct net_device *dev = info->user_ptr[1]; |
| 10592 | struct ocb_setup setup = {}; |
| 10593 | int err; |
| 10594 | |
| 10595 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 10596 | if (err) |
| 10597 | return err; |
| 10598 | |
| 10599 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 10600 | } |
| 10601 | |
| 10602 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 10603 | { |
| 10604 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10605 | struct net_device *dev = info->user_ptr[1]; |
| 10606 | |
| 10607 | return cfg80211_leave_ocb(rdev, dev); |
| 10608 | } |
| 10609 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10610 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 10611 | { |
| 10612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10613 | struct net_device *dev = info->user_ptr[1]; |
| 10614 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10615 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10616 | int err; |
| 10617 | |
| 10618 | /* start with default */ |
| 10619 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10620 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10621 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10622 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10623 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10624 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10625 | if (err) |
| 10626 | return err; |
| 10627 | } |
| 10628 | |
| 10629 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 10630 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 10631 | return -EINVAL; |
| 10632 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10633 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 10634 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 10635 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 10636 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 10637 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 10638 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 10639 | return -EINVAL; |
| 10640 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 10641 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 10642 | setup.beacon_interval = |
| 10643 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10644 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 10645 | err = cfg80211_validate_beacon_int(rdev, |
| 10646 | NL80211_IFTYPE_MESH_POINT, |
| 10647 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10648 | if (err) |
| 10649 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 10650 | } |
| 10651 | |
| 10652 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 10653 | setup.dtim_period = |
| 10654 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 10655 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 10656 | return -EINVAL; |
| 10657 | } |
| 10658 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10659 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 10660 | /* parse additional setup parameters if given */ |
| 10661 | err = nl80211_parse_mesh_setup(info, &setup); |
| 10662 | if (err) |
| 10663 | return err; |
| 10664 | } |
| 10665 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 10666 | if (setup.user_mpm) |
| 10667 | cfg.auto_open_plinks = false; |
| 10668 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 10669 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10670 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 10671 | if (err) |
| 10672 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 10673 | } else { |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 10674 | /* __cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10675 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 10676 | } |
| 10677 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 10678 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 10679 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10680 | int n_rates = |
| 10681 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10682 | struct ieee80211_supported_band *sband; |
| 10683 | |
| 10684 | if (!setup.chandef.chan) |
| 10685 | return -EINVAL; |
| 10686 | |
| 10687 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 10688 | |
| 10689 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 10690 | &setup.basic_rates); |
| 10691 | if (err) |
| 10692 | return err; |
| 10693 | } |
| 10694 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 10695 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 10696 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); |
| 10697 | if (err) |
| 10698 | return err; |
| 10699 | |
Johannes Berg | 265698d | 2017-09-18 22:46:36 +0200 | [diff] [blame] | 10700 | if (!setup.chandef.chan) |
| 10701 | return -EINVAL; |
| 10702 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 10703 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 10704 | &setup.beacon_rate); |
| 10705 | if (err) |
| 10706 | return err; |
| 10707 | } |
| 10708 | |
Benjamin Berg | d37d49c | 2017-05-16 11:23:11 +0200 | [diff] [blame] | 10709 | setup.userspace_handles_dfs = |
| 10710 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 10711 | |
Denis Kenzior | 1224f58 | 2018-03-26 12:52:49 -0500 | [diff] [blame] | 10712 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 10713 | int r = validate_pae_over_nl80211(rdev, info); |
| 10714 | |
| 10715 | if (r < 0) |
| 10716 | return r; |
| 10717 | |
| 10718 | setup.control_port_over_nl80211 = true; |
| 10719 | } |
| 10720 | |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 10721 | wdev_lock(dev->ieee80211_ptr); |
| 10722 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
| 10723 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 10724 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10725 | wdev_unlock(dev->ieee80211_ptr); |
| 10726 | |
| 10727 | return err; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10728 | } |
| 10729 | |
| 10730 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 10731 | { |
| 10732 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10733 | struct net_device *dev = info->user_ptr[1]; |
| 10734 | |
| 10735 | return cfg80211_leave_mesh(rdev, dev); |
| 10736 | } |
| 10737 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10738 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10739 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 10740 | struct cfg80211_registered_device *rdev) |
| 10741 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10742 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10743 | struct nlattr *nl_pats, *nl_pat; |
| 10744 | int i, pat_len; |
| 10745 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10746 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10747 | return 0; |
| 10748 | |
| 10749 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 10750 | if (!nl_pats) |
| 10751 | return -ENOBUFS; |
| 10752 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10753 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10754 | nl_pat = nla_nest_start(msg, i + 1); |
| 10755 | if (!nl_pat) |
| 10756 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10757 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10758 | 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] | 10759 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10760 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10761 | wowlan->patterns[i].pattern) || |
| 10762 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10763 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10764 | return -ENOBUFS; |
| 10765 | nla_nest_end(msg, nl_pat); |
| 10766 | } |
| 10767 | nla_nest_end(msg, nl_pats); |
| 10768 | |
| 10769 | return 0; |
| 10770 | } |
| 10771 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10772 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 10773 | struct cfg80211_wowlan_tcp *tcp) |
| 10774 | { |
| 10775 | struct nlattr *nl_tcp; |
| 10776 | |
| 10777 | if (!tcp) |
| 10778 | return 0; |
| 10779 | |
| 10780 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 10781 | if (!nl_tcp) |
| 10782 | return -ENOBUFS; |
| 10783 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 10784 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 10785 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10786 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 10787 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 10788 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 10789 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 10790 | tcp->payload_len, tcp->payload) || |
| 10791 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 10792 | tcp->data_interval) || |
| 10793 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 10794 | tcp->wake_len, tcp->wake_data) || |
| 10795 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 10796 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 10797 | return -ENOBUFS; |
| 10798 | |
| 10799 | if (tcp->payload_seq.len && |
| 10800 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 10801 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 10802 | return -ENOBUFS; |
| 10803 | |
| 10804 | if (tcp->payload_tok.len && |
| 10805 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 10806 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 10807 | &tcp->payload_tok)) |
| 10808 | return -ENOBUFS; |
| 10809 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 10810 | nla_nest_end(msg, nl_tcp); |
| 10811 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10812 | return 0; |
| 10813 | } |
| 10814 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10815 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 10816 | struct cfg80211_sched_scan_request *req) |
| 10817 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10818 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10819 | int i; |
| 10820 | |
| 10821 | if (!req) |
| 10822 | return 0; |
| 10823 | |
| 10824 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 10825 | if (!nd) |
| 10826 | return -ENOBUFS; |
| 10827 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10828 | if (req->n_scan_plans == 1 && |
| 10829 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 10830 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10831 | return -ENOBUFS; |
| 10832 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 10833 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 10834 | return -ENOBUFS; |
| 10835 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 10836 | if (req->relative_rssi_set) { |
| 10837 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 10838 | |
| 10839 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 10840 | req->relative_rssi)) |
| 10841 | return -ENOBUFS; |
| 10842 | |
| 10843 | rssi_adjust.band = req->rssi_adjust.band; |
| 10844 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 10845 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 10846 | sizeof(rssi_adjust), &rssi_adjust)) |
| 10847 | return -ENOBUFS; |
| 10848 | } |
| 10849 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10850 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10851 | if (!freqs) |
| 10852 | return -ENOBUFS; |
| 10853 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10854 | for (i = 0; i < req->n_channels; i++) { |
| 10855 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10856 | return -ENOBUFS; |
| 10857 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10858 | |
| 10859 | nla_nest_end(msg, freqs); |
| 10860 | |
| 10861 | if (req->n_match_sets) { |
| 10862 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10863 | if (!matches) |
| 10864 | return -ENOBUFS; |
| 10865 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10866 | for (i = 0; i < req->n_match_sets; i++) { |
| 10867 | match = nla_nest_start(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10868 | if (!match) |
| 10869 | return -ENOBUFS; |
| 10870 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10871 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 10872 | req->match_sets[i].ssid.ssid_len, |
| 10873 | req->match_sets[i].ssid.ssid)) |
| 10874 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10875 | nla_nest_end(msg, match); |
| 10876 | } |
| 10877 | nla_nest_end(msg, matches); |
| 10878 | } |
| 10879 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10880 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 10881 | if (!scan_plans) |
| 10882 | return -ENOBUFS; |
| 10883 | |
| 10884 | for (i = 0; i < req->n_scan_plans; i++) { |
| 10885 | scan_plan = nla_nest_start(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10886 | if (!scan_plan) |
| 10887 | return -ENOBUFS; |
| 10888 | |
Colin Ian King | 6762696 | 2018-09-06 10:58:44 +0100 | [diff] [blame] | 10889 | if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10890 | req->scan_plans[i].interval) || |
| 10891 | (req->scan_plans[i].iterations && |
| 10892 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 10893 | req->scan_plans[i].iterations))) |
| 10894 | return -ENOBUFS; |
| 10895 | nla_nest_end(msg, scan_plan); |
| 10896 | } |
| 10897 | nla_nest_end(msg, scan_plans); |
| 10898 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10899 | nla_nest_end(msg, nd); |
| 10900 | |
| 10901 | return 0; |
| 10902 | } |
| 10903 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10904 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10905 | { |
| 10906 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10907 | struct sk_buff *msg; |
| 10908 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10909 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10910 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10911 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10912 | return -EOPNOTSUPP; |
| 10913 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10914 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10915 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10916 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 10917 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 10918 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 10919 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10920 | } |
| 10921 | |
| 10922 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10923 | if (!msg) |
| 10924 | return -ENOMEM; |
| 10925 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10926 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10927 | NL80211_CMD_GET_WOWLAN); |
| 10928 | if (!hdr) |
| 10929 | goto nla_put_failure; |
| 10930 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10931 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10932 | struct nlattr *nl_wowlan; |
| 10933 | |
| 10934 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10935 | if (!nl_wowlan) |
| 10936 | goto nla_put_failure; |
| 10937 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10938 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10939 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10940 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10941 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10942 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10943 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10944 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10945 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10946 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10947 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10948 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10949 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10950 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10951 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 10952 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10953 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10954 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 10955 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10956 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10957 | if (nl80211_send_wowlan_tcp(msg, |
| 10958 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10959 | goto nla_put_failure; |
| 10960 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10961 | if (nl80211_send_wowlan_nd( |
| 10962 | msg, |
| 10963 | rdev->wiphy.wowlan_config->nd_config)) |
| 10964 | goto nla_put_failure; |
| 10965 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10966 | nla_nest_end(msg, nl_wowlan); |
| 10967 | } |
| 10968 | |
| 10969 | genlmsg_end(msg, hdr); |
| 10970 | return genlmsg_reply(msg, info); |
| 10971 | |
| 10972 | nla_put_failure: |
| 10973 | nlmsg_free(msg); |
| 10974 | return -ENOBUFS; |
| 10975 | } |
| 10976 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10977 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 10978 | struct nlattr *attr, |
| 10979 | struct cfg80211_wowlan *trig) |
| 10980 | { |
| 10981 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 10982 | struct cfg80211_wowlan_tcp *cfg; |
| 10983 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 10984 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 10985 | u32 size; |
| 10986 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 10987 | int err, port; |
| 10988 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10989 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10990 | return -EINVAL; |
| 10991 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10992 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10993 | nl80211_wowlan_tcp_policy, NULL); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10994 | if (err) |
| 10995 | return err; |
| 10996 | |
| 10997 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 10998 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 10999 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 11000 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 11001 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 11002 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 11003 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 11004 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 11005 | return -EINVAL; |
| 11006 | |
| 11007 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11008 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11009 | return -EINVAL; |
| 11010 | |
| 11011 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11012 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 11013 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11014 | return -EINVAL; |
| 11015 | |
| 11016 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11017 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11018 | return -EINVAL; |
| 11019 | |
| 11020 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 11021 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 11022 | return -EINVAL; |
| 11023 | |
| 11024 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 11025 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 11026 | |
| 11027 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 11028 | tokens_size = tokln - sizeof(*tok); |
| 11029 | |
| 11030 | if (!tok->len || tokens_size % tok->len) |
| 11031 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11032 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11033 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11034 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11035 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11036 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11037 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11038 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11039 | return -EINVAL; |
| 11040 | if (tok->offset + tok->len > data_size) |
| 11041 | return -EINVAL; |
| 11042 | } |
| 11043 | |
| 11044 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 11045 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11046 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11047 | return -EINVAL; |
| 11048 | if (seq->len == 0 || seq->len > 4) |
| 11049 | return -EINVAL; |
| 11050 | if (seq->len + seq->offset > data_size) |
| 11051 | return -EINVAL; |
| 11052 | } |
| 11053 | |
| 11054 | size = sizeof(*cfg); |
| 11055 | size += data_size; |
| 11056 | size += wake_size + wake_mask_size; |
| 11057 | size += tokens_size; |
| 11058 | |
| 11059 | cfg = kzalloc(size, GFP_KERNEL); |
| 11060 | if (!cfg) |
| 11061 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 11062 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 11063 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11064 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 11065 | ETH_ALEN); |
| 11066 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 11067 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 11068 | else |
| 11069 | port = 0; |
| 11070 | #ifdef CONFIG_INET |
| 11071 | /* allocate a socket and port for it and use it */ |
| 11072 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 11073 | IPPROTO_TCP, &cfg->sock, 1); |
| 11074 | if (err) { |
| 11075 | kfree(cfg); |
| 11076 | return err; |
| 11077 | } |
| 11078 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 11079 | sock_release(cfg->sock); |
| 11080 | kfree(cfg); |
| 11081 | return -EADDRINUSE; |
| 11082 | } |
| 11083 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 11084 | #else |
| 11085 | if (!port) { |
| 11086 | kfree(cfg); |
| 11087 | return -EINVAL; |
| 11088 | } |
| 11089 | cfg->src_port = port; |
| 11090 | #endif |
| 11091 | |
| 11092 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 11093 | cfg->payload_len = data_size; |
| 11094 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 11095 | memcpy((void *)cfg->payload, |
| 11096 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 11097 | data_size); |
| 11098 | if (seq) |
| 11099 | cfg->payload_seq = *seq; |
| 11100 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 11101 | cfg->wake_len = wake_size; |
| 11102 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 11103 | memcpy((void *)cfg->wake_data, |
| 11104 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 11105 | wake_size); |
| 11106 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 11107 | data_size + wake_size; |
| 11108 | memcpy((void *)cfg->wake_mask, |
| 11109 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 11110 | wake_mask_size); |
| 11111 | if (tok) { |
| 11112 | cfg->tokens_size = tokens_size; |
| 11113 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 11114 | } |
| 11115 | |
| 11116 | trig->tcp = cfg; |
| 11117 | |
| 11118 | return 0; |
| 11119 | } |
| 11120 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11121 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 11122 | const struct wiphy_wowlan_support *wowlan, |
| 11123 | struct nlattr *attr, |
| 11124 | struct cfg80211_wowlan *trig) |
| 11125 | { |
| 11126 | struct nlattr **tb; |
| 11127 | int err; |
| 11128 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 11129 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11130 | if (!tb) |
| 11131 | return -ENOMEM; |
| 11132 | |
| 11133 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 11134 | err = -EOPNOTSUPP; |
| 11135 | goto out; |
| 11136 | } |
| 11137 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 11138 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy, |
| 11139 | NULL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11140 | if (err) |
| 11141 | goto out; |
| 11142 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 11143 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 11144 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11145 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 11146 | if (err) |
| 11147 | trig->nd_config = NULL; |
| 11148 | |
| 11149 | out: |
| 11150 | kfree(tb); |
| 11151 | return err; |
| 11152 | } |
| 11153 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11154 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 11155 | { |
| 11156 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11157 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11158 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11159 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11160 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11161 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11162 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11163 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11164 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11165 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11166 | return -EOPNOTSUPP; |
| 11167 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11168 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 11169 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11170 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11171 | goto set_wakeup; |
| 11172 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11173 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11174 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG, |
| 11175 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11176 | nl80211_wowlan_policy, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11177 | if (err) |
| 11178 | return err; |
| 11179 | |
| 11180 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 11181 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 11182 | return -EINVAL; |
| 11183 | new_triggers.any = true; |
| 11184 | } |
| 11185 | |
| 11186 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 11187 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 11188 | return -EINVAL; |
| 11189 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11190 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11191 | } |
| 11192 | |
| 11193 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 11194 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 11195 | return -EINVAL; |
| 11196 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11197 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11198 | } |
| 11199 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11200 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 11201 | return -EINVAL; |
| 11202 | |
| 11203 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 11204 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 11205 | return -EINVAL; |
| 11206 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11207 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11208 | } |
| 11209 | |
| 11210 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 11211 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 11212 | return -EINVAL; |
| 11213 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11214 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11215 | } |
| 11216 | |
| 11217 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 11218 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 11219 | return -EINVAL; |
| 11220 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11221 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11222 | } |
| 11223 | |
| 11224 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 11225 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 11226 | return -EINVAL; |
| 11227 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11228 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11229 | } |
| 11230 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11231 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 11232 | struct nlattr *pat; |
| 11233 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11234 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11235 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11236 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11237 | regular = true; |
| 11238 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11239 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 11240 | rem) |
| 11241 | n_patterns++; |
| 11242 | if (n_patterns > wowlan->n_patterns) |
| 11243 | return -EINVAL; |
| 11244 | |
| 11245 | new_triggers.patterns = kcalloc(n_patterns, |
| 11246 | sizeof(new_triggers.patterns[0]), |
| 11247 | GFP_KERNEL); |
| 11248 | if (!new_triggers.patterns) |
| 11249 | return -ENOMEM; |
| 11250 | |
| 11251 | new_triggers.n_patterns = n_patterns; |
| 11252 | i = 0; |
| 11253 | |
| 11254 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 11255 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11256 | u8 *mask_pat; |
| 11257 | |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 11258 | err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
| 11259 | nl80211_packet_pattern_policy, |
| 11260 | info->extack); |
| 11261 | if (err) |
| 11262 | goto error; |
| 11263 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11264 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11265 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 11266 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11267 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11268 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11269 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11270 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11271 | goto error; |
| 11272 | if (pat_len > wowlan->pattern_max_len || |
| 11273 | pat_len < wowlan->pattern_min_len) |
| 11274 | goto error; |
| 11275 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11276 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11277 | pkt_offset = 0; |
| 11278 | else |
| 11279 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11280 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11281 | if (pkt_offset > wowlan->max_pkt_offset) |
| 11282 | goto error; |
| 11283 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 11284 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11285 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 11286 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11287 | err = -ENOMEM; |
| 11288 | goto error; |
| 11289 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11290 | new_triggers.patterns[i].mask = mask_pat; |
| 11291 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11292 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11293 | mask_pat += mask_len; |
| 11294 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11295 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11296 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11297 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11298 | pat_len); |
| 11299 | i++; |
| 11300 | } |
| 11301 | } |
| 11302 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11303 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11304 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11305 | err = nl80211_parse_wowlan_tcp( |
| 11306 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 11307 | &new_triggers); |
| 11308 | if (err) |
| 11309 | goto error; |
| 11310 | } |
| 11311 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11312 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11313 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11314 | err = nl80211_parse_wowlan_nd( |
| 11315 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 11316 | &new_triggers); |
| 11317 | if (err) |
| 11318 | goto error; |
| 11319 | } |
| 11320 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11321 | /* The 'any' trigger means the device continues operating more or less |
| 11322 | * as in its normal operation mode and wakes up the host on most of the |
| 11323 | * normal interrupts (like packet RX, ...) |
| 11324 | * It therefore makes little sense to combine with the more constrained |
| 11325 | * wakeup trigger modes. |
| 11326 | */ |
| 11327 | if (new_triggers.any && regular) { |
| 11328 | err = -EINVAL; |
| 11329 | goto error; |
| 11330 | } |
| 11331 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11332 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 11333 | if (!ntrig) { |
| 11334 | err = -ENOMEM; |
| 11335 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11336 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11337 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11338 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11339 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11340 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11341 | if (rdev->ops->set_wakeup && |
| 11342 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 11343 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 11344 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11345 | return 0; |
| 11346 | error: |
| 11347 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 11348 | kfree(new_triggers.patterns[i].mask); |
| 11349 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11350 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 11351 | sock_release(new_triggers.tcp->sock); |
| 11352 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 11353 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11354 | return err; |
| 11355 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11356 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11357 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11358 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 11359 | struct cfg80211_registered_device *rdev) |
| 11360 | { |
| 11361 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 11362 | int i, j, pat_len; |
| 11363 | struct cfg80211_coalesce_rules *rule; |
| 11364 | |
| 11365 | if (!rdev->coalesce->n_rules) |
| 11366 | return 0; |
| 11367 | |
| 11368 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 11369 | if (!nl_rules) |
| 11370 | return -ENOBUFS; |
| 11371 | |
| 11372 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 11373 | nl_rule = nla_nest_start(msg, i + 1); |
| 11374 | if (!nl_rule) |
| 11375 | return -ENOBUFS; |
| 11376 | |
| 11377 | rule = &rdev->coalesce->rules[i]; |
| 11378 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 11379 | rule->delay)) |
| 11380 | return -ENOBUFS; |
| 11381 | |
| 11382 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 11383 | rule->condition)) |
| 11384 | return -ENOBUFS; |
| 11385 | |
| 11386 | nl_pats = nla_nest_start(msg, |
| 11387 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 11388 | if (!nl_pats) |
| 11389 | return -ENOBUFS; |
| 11390 | |
| 11391 | for (j = 0; j < rule->n_patterns; j++) { |
| 11392 | nl_pat = nla_nest_start(msg, j + 1); |
| 11393 | if (!nl_pat) |
| 11394 | return -ENOBUFS; |
| 11395 | pat_len = rule->patterns[j].pattern_len; |
| 11396 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 11397 | DIV_ROUND_UP(pat_len, 8), |
| 11398 | rule->patterns[j].mask) || |
| 11399 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 11400 | rule->patterns[j].pattern) || |
| 11401 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 11402 | rule->patterns[j].pkt_offset)) |
| 11403 | return -ENOBUFS; |
| 11404 | nla_nest_end(msg, nl_pat); |
| 11405 | } |
| 11406 | nla_nest_end(msg, nl_pats); |
| 11407 | nla_nest_end(msg, nl_rule); |
| 11408 | } |
| 11409 | nla_nest_end(msg, nl_rules); |
| 11410 | |
| 11411 | return 0; |
| 11412 | } |
| 11413 | |
| 11414 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 11415 | { |
| 11416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11417 | struct sk_buff *msg; |
| 11418 | void *hdr; |
| 11419 | |
| 11420 | if (!rdev->wiphy.coalesce) |
| 11421 | return -EOPNOTSUPP; |
| 11422 | |
| 11423 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11424 | if (!msg) |
| 11425 | return -ENOMEM; |
| 11426 | |
| 11427 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11428 | NL80211_CMD_GET_COALESCE); |
| 11429 | if (!hdr) |
| 11430 | goto nla_put_failure; |
| 11431 | |
| 11432 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 11433 | goto nla_put_failure; |
| 11434 | |
| 11435 | genlmsg_end(msg, hdr); |
| 11436 | return genlmsg_reply(msg, info); |
| 11437 | |
| 11438 | nla_put_failure: |
| 11439 | nlmsg_free(msg); |
| 11440 | return -ENOBUFS; |
| 11441 | } |
| 11442 | |
| 11443 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 11444 | { |
| 11445 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 11446 | int i, j; |
| 11447 | struct cfg80211_coalesce_rules *rule; |
| 11448 | |
| 11449 | if (!coalesce) |
| 11450 | return; |
| 11451 | |
| 11452 | for (i = 0; i < coalesce->n_rules; i++) { |
| 11453 | rule = &coalesce->rules[i]; |
| 11454 | for (j = 0; j < rule->n_patterns; j++) |
| 11455 | kfree(rule->patterns[j].mask); |
| 11456 | kfree(rule->patterns); |
| 11457 | } |
| 11458 | kfree(coalesce->rules); |
| 11459 | kfree(coalesce); |
| 11460 | rdev->coalesce = NULL; |
| 11461 | } |
| 11462 | |
| 11463 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 11464 | struct nlattr *rule, |
| 11465 | struct cfg80211_coalesce_rules *new_rule) |
| 11466 | { |
| 11467 | int err, i; |
| 11468 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 11469 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 11470 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 11471 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 11472 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11473 | err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 11474 | nl80211_coalesce_policy, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11475 | if (err) |
| 11476 | return err; |
| 11477 | |
| 11478 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 11479 | new_rule->delay = |
| 11480 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 11481 | if (new_rule->delay > coalesce->max_delay) |
| 11482 | return -EINVAL; |
| 11483 | |
| 11484 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 11485 | new_rule->condition = |
| 11486 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11487 | |
| 11488 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 11489 | return -EINVAL; |
| 11490 | |
| 11491 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 11492 | rem) |
| 11493 | n_patterns++; |
| 11494 | if (n_patterns > coalesce->n_patterns) |
| 11495 | return -EINVAL; |
| 11496 | |
| 11497 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 11498 | GFP_KERNEL); |
| 11499 | if (!new_rule->patterns) |
| 11500 | return -ENOMEM; |
| 11501 | |
| 11502 | new_rule->n_patterns = n_patterns; |
| 11503 | i = 0; |
| 11504 | |
| 11505 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 11506 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11507 | u8 *mask_pat; |
| 11508 | |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 11509 | err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
| 11510 | nl80211_packet_pattern_policy, NULL); |
| 11511 | if (err) |
| 11512 | return err; |
| 11513 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11514 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 11515 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 11516 | return -EINVAL; |
| 11517 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 11518 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 11519 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 11520 | return -EINVAL; |
| 11521 | if (pat_len > coalesce->pattern_max_len || |
| 11522 | pat_len < coalesce->pattern_min_len) |
| 11523 | return -EINVAL; |
| 11524 | |
| 11525 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 11526 | pkt_offset = 0; |
| 11527 | else |
| 11528 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 11529 | if (pkt_offset > coalesce->max_pkt_offset) |
| 11530 | return -EINVAL; |
| 11531 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 11532 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11533 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 11534 | if (!mask_pat) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11535 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11536 | |
| 11537 | new_rule->patterns[i].mask = mask_pat; |
| 11538 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 11539 | mask_len); |
| 11540 | |
| 11541 | mask_pat += mask_len; |
| 11542 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11543 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11544 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 11545 | pat_len); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11546 | i++; |
| 11547 | } |
| 11548 | |
| 11549 | return 0; |
| 11550 | } |
| 11551 | |
| 11552 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 11553 | { |
| 11554 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11555 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 11556 | struct cfg80211_coalesce new_coalesce = {}; |
| 11557 | struct cfg80211_coalesce *n_coalesce; |
| 11558 | int err, rem_rule, n_rules = 0, i, j; |
| 11559 | struct nlattr *rule; |
| 11560 | struct cfg80211_coalesce_rules *tmp_rule; |
| 11561 | |
| 11562 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 11563 | return -EOPNOTSUPP; |
| 11564 | |
| 11565 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 11566 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 11567 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11568 | return 0; |
| 11569 | } |
| 11570 | |
| 11571 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 11572 | rem_rule) |
| 11573 | n_rules++; |
| 11574 | if (n_rules > coalesce->n_rules) |
| 11575 | return -EINVAL; |
| 11576 | |
| 11577 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 11578 | GFP_KERNEL); |
| 11579 | if (!new_coalesce.rules) |
| 11580 | return -ENOMEM; |
| 11581 | |
| 11582 | new_coalesce.n_rules = n_rules; |
| 11583 | i = 0; |
| 11584 | |
| 11585 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 11586 | rem_rule) { |
| 11587 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 11588 | &new_coalesce.rules[i]); |
| 11589 | if (err) |
| 11590 | goto error; |
| 11591 | |
| 11592 | i++; |
| 11593 | } |
| 11594 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 11595 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11596 | if (err) |
| 11597 | goto error; |
| 11598 | |
| 11599 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 11600 | if (!n_coalesce) { |
| 11601 | err = -ENOMEM; |
| 11602 | goto error; |
| 11603 | } |
| 11604 | cfg80211_rdev_free_coalesce(rdev); |
| 11605 | rdev->coalesce = n_coalesce; |
| 11606 | |
| 11607 | return 0; |
| 11608 | error: |
| 11609 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 11610 | tmp_rule = &new_coalesce.rules[i]; |
| 11611 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 11612 | kfree(tmp_rule->patterns[j].mask); |
| 11613 | kfree(tmp_rule->patterns); |
| 11614 | } |
| 11615 | kfree(new_coalesce.rules); |
| 11616 | |
| 11617 | return err; |
| 11618 | } |
| 11619 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11620 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 11621 | { |
| 11622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11623 | struct net_device *dev = info->user_ptr[1]; |
| 11624 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11625 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 11626 | struct cfg80211_gtk_rekey_data rekey_data; |
| 11627 | int err; |
| 11628 | |
| 11629 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 11630 | return -EINVAL; |
| 11631 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11632 | err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA, |
| 11633 | info->attrs[NL80211_ATTR_REKEY_DATA], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11634 | nl80211_rekey_policy, info->extack); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11635 | if (err) |
| 11636 | return err; |
| 11637 | |
Vladis Dronov | e785fa0 | 2017-09-13 00:21:21 +0200 | [diff] [blame] | 11638 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
| 11639 | !tb[NL80211_REKEY_DATA_KCK]) |
| 11640 | return -EINVAL; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11641 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 11642 | return -ERANGE; |
| 11643 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 11644 | return -ERANGE; |
| 11645 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 11646 | return -ERANGE; |
| 11647 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 11648 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 11649 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 11650 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11651 | |
| 11652 | wdev_lock(wdev); |
| 11653 | if (!wdev->current_bss) { |
| 11654 | err = -ENOTCONN; |
| 11655 | goto out; |
| 11656 | } |
| 11657 | |
| 11658 | if (!rdev->ops->set_rekey_data) { |
| 11659 | err = -EOPNOTSUPP; |
| 11660 | goto out; |
| 11661 | } |
| 11662 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11663 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11664 | out: |
| 11665 | wdev_unlock(wdev); |
| 11666 | return err; |
| 11667 | } |
| 11668 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11669 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 11670 | struct genl_info *info) |
| 11671 | { |
| 11672 | struct net_device *dev = info->user_ptr[1]; |
| 11673 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11674 | |
| 11675 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 11676 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 11677 | return -EINVAL; |
| 11678 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11679 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11680 | return -EBUSY; |
| 11681 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11682 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11683 | return 0; |
| 11684 | } |
| 11685 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11686 | static int nl80211_probe_client(struct sk_buff *skb, |
| 11687 | struct genl_info *info) |
| 11688 | { |
| 11689 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11690 | struct net_device *dev = info->user_ptr[1]; |
| 11691 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11692 | struct sk_buff *msg; |
| 11693 | void *hdr; |
| 11694 | const u8 *addr; |
| 11695 | u64 cookie; |
| 11696 | int err; |
| 11697 | |
| 11698 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 11699 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 11700 | return -EOPNOTSUPP; |
| 11701 | |
| 11702 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 11703 | return -EINVAL; |
| 11704 | |
| 11705 | if (!rdev->ops->probe_client) |
| 11706 | return -EOPNOTSUPP; |
| 11707 | |
| 11708 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11709 | if (!msg) |
| 11710 | return -ENOMEM; |
| 11711 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11712 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11713 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 11714 | if (!hdr) { |
| 11715 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11716 | goto free_msg; |
| 11717 | } |
| 11718 | |
| 11719 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11720 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11721 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11722 | if (err) |
| 11723 | goto free_msg; |
| 11724 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11725 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11726 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11727 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11728 | |
| 11729 | genlmsg_end(msg, hdr); |
| 11730 | |
| 11731 | return genlmsg_reply(msg, info); |
| 11732 | |
| 11733 | nla_put_failure: |
| 11734 | err = -ENOBUFS; |
| 11735 | free_msg: |
| 11736 | nlmsg_free(msg); |
| 11737 | return err; |
| 11738 | } |
| 11739 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11740 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 11741 | { |
| 11742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11743 | struct cfg80211_beacon_registration *reg, *nreg; |
| 11744 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11745 | |
| 11746 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 11747 | return -EOPNOTSUPP; |
| 11748 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11749 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 11750 | if (!nreg) |
| 11751 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11752 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11753 | /* First, check if already registered. */ |
| 11754 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11755 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11756 | if (reg->nlportid == info->snd_portid) { |
| 11757 | rv = -EALREADY; |
| 11758 | goto out_err; |
| 11759 | } |
| 11760 | } |
| 11761 | /* Add it to the list */ |
| 11762 | nreg->nlportid = info->snd_portid; |
| 11763 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 11764 | |
| 11765 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11766 | |
| 11767 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11768 | out_err: |
| 11769 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11770 | kfree(nreg); |
| 11771 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11772 | } |
| 11773 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11774 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 11775 | { |
| 11776 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11777 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11778 | int err; |
| 11779 | |
| 11780 | if (!rdev->ops->start_p2p_device) |
| 11781 | return -EOPNOTSUPP; |
| 11782 | |
| 11783 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 11784 | return -EOPNOTSUPP; |
| 11785 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11786 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11787 | return 0; |
| 11788 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 11789 | if (rfkill_blocked(rdev->rfkill)) |
| 11790 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11791 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 11792 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11793 | if (err) |
| 11794 | return err; |
| 11795 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11796 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11797 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11798 | |
| 11799 | return 0; |
| 11800 | } |
| 11801 | |
| 11802 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 11803 | { |
| 11804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11805 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11806 | |
| 11807 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 11808 | return -EOPNOTSUPP; |
| 11809 | |
| 11810 | if (!rdev->ops->stop_p2p_device) |
| 11811 | return -EOPNOTSUPP; |
| 11812 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 11813 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11814 | |
| 11815 | return 0; |
| 11816 | } |
| 11817 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11818 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 11819 | { |
| 11820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11821 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11822 | struct cfg80211_nan_conf conf = {}; |
| 11823 | int err; |
| 11824 | |
| 11825 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11826 | return -EOPNOTSUPP; |
| 11827 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 11828 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11829 | return -EEXIST; |
| 11830 | |
| 11831 | if (rfkill_blocked(rdev->rfkill)) |
| 11832 | return -ERFKILL; |
| 11833 | |
| 11834 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 11835 | return -EINVAL; |
| 11836 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11837 | conf.master_pref = |
| 11838 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11839 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 11840 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 11841 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 11842 | |
| 11843 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 11844 | return -EOPNOTSUPP; |
| 11845 | |
| 11846 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 11847 | return -EINVAL; |
| 11848 | |
| 11849 | conf.bands = bands; |
| 11850 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11851 | |
| 11852 | err = rdev_start_nan(rdev, wdev, &conf); |
| 11853 | if (err) |
| 11854 | return err; |
| 11855 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11856 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11857 | rdev->opencount++; |
| 11858 | |
| 11859 | return 0; |
| 11860 | } |
| 11861 | |
| 11862 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 11863 | { |
| 11864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11865 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11866 | |
| 11867 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11868 | return -EOPNOTSUPP; |
| 11869 | |
| 11870 | cfg80211_stop_nan(rdev, wdev); |
| 11871 | |
| 11872 | return 0; |
| 11873 | } |
| 11874 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11875 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 11876 | { |
| 11877 | struct nlattr *attr; |
| 11878 | int len = 0, n_entries = 0, rem; |
| 11879 | |
| 11880 | nla_for_each_nested(attr, filter_attr, rem) { |
| 11881 | len += nla_len(attr); |
| 11882 | n_entries++; |
| 11883 | } |
| 11884 | |
| 11885 | if (len >= U8_MAX) |
| 11886 | return -EINVAL; |
| 11887 | |
| 11888 | return n_entries; |
| 11889 | } |
| 11890 | |
| 11891 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 11892 | struct cfg80211_nan_func *func, |
| 11893 | bool tx) |
| 11894 | { |
| 11895 | struct nlattr *attr; |
| 11896 | int n_entries, rem, i; |
| 11897 | struct cfg80211_nan_func_filter *filter; |
| 11898 | |
| 11899 | n_entries = validate_nan_filter(attr_filter); |
| 11900 | if (n_entries < 0) |
| 11901 | return n_entries; |
| 11902 | |
| 11903 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 11904 | |
| 11905 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 11906 | if (!filter) |
| 11907 | return -ENOMEM; |
| 11908 | |
| 11909 | i = 0; |
| 11910 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 11911 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11912 | filter[i].len = nla_len(attr); |
| 11913 | i++; |
| 11914 | } |
| 11915 | if (tx) { |
| 11916 | func->num_tx_filters = n_entries; |
| 11917 | func->tx_filters = filter; |
| 11918 | } else { |
| 11919 | func->num_rx_filters = n_entries; |
| 11920 | func->rx_filters = filter; |
| 11921 | } |
| 11922 | |
| 11923 | return 0; |
| 11924 | } |
| 11925 | |
| 11926 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 11927 | struct genl_info *info) |
| 11928 | { |
| 11929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11930 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11931 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 11932 | struct cfg80211_nan_func *func; |
| 11933 | struct sk_buff *msg = NULL; |
| 11934 | void *hdr = NULL; |
| 11935 | int err = 0; |
| 11936 | |
| 11937 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11938 | return -EOPNOTSUPP; |
| 11939 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11940 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11941 | return -ENOTCONN; |
| 11942 | |
| 11943 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 11944 | return -EINVAL; |
| 11945 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11946 | err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 11947 | info->attrs[NL80211_ATTR_NAN_FUNC], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11948 | nl80211_nan_func_policy, info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11949 | if (err) |
| 11950 | return err; |
| 11951 | |
| 11952 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 11953 | if (!func) |
| 11954 | return -ENOMEM; |
| 11955 | |
Johannes Berg | b60ad34 | 2018-10-01 11:52:07 +0200 | [diff] [blame] | 11956 | func->cookie = cfg80211_assign_cookie(rdev); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11957 | |
| 11958 | if (!tb[NL80211_NAN_FUNC_TYPE] || |
| 11959 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { |
| 11960 | err = -EINVAL; |
| 11961 | goto out; |
| 11962 | } |
| 11963 | |
| 11964 | |
| 11965 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 11966 | |
| 11967 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 11968 | err = -EINVAL; |
| 11969 | goto out; |
| 11970 | } |
| 11971 | |
| 11972 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 11973 | sizeof(func->service_id)); |
| 11974 | |
| 11975 | func->close_range = |
| 11976 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 11977 | |
| 11978 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 11979 | func->serv_spec_info_len = |
| 11980 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 11981 | func->serv_spec_info = |
| 11982 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 11983 | func->serv_spec_info_len, |
| 11984 | GFP_KERNEL); |
| 11985 | if (!func->serv_spec_info) { |
| 11986 | err = -ENOMEM; |
| 11987 | goto out; |
| 11988 | } |
| 11989 | } |
| 11990 | |
| 11991 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 11992 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 11993 | |
| 11994 | switch (func->type) { |
| 11995 | case NL80211_NAN_FUNC_PUBLISH: |
| 11996 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 11997 | err = -EINVAL; |
| 11998 | goto out; |
| 11999 | } |
| 12000 | |
| 12001 | func->publish_type = |
| 12002 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 12003 | func->publish_bcast = |
| 12004 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 12005 | |
| 12006 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 12007 | func->publish_bcast) { |
| 12008 | err = -EINVAL; |
| 12009 | goto out; |
| 12010 | } |
| 12011 | break; |
| 12012 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 12013 | func->subscribe_active = |
| 12014 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 12015 | break; |
| 12016 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 12017 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
Hao Chen | 3ea1545 | 2018-01-03 11:00:31 +0800 | [diff] [blame] | 12018 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
| 12019 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12020 | err = -EINVAL; |
| 12021 | goto out; |
| 12022 | } |
| 12023 | |
| 12024 | func->followup_id = |
| 12025 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 12026 | func->followup_reqid = |
| 12027 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 12028 | memcpy(func->followup_dest.addr, |
| 12029 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 12030 | sizeof(func->followup_dest.addr)); |
| 12031 | if (func->ttl) { |
| 12032 | err = -EINVAL; |
| 12033 | goto out; |
| 12034 | } |
| 12035 | break; |
| 12036 | default: |
| 12037 | err = -EINVAL; |
| 12038 | goto out; |
| 12039 | } |
| 12040 | |
| 12041 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 12042 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 12043 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 12044 | err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX, |
| 12045 | tb[NL80211_NAN_FUNC_SRF], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 12046 | nl80211_nan_srf_policy, info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12047 | if (err) |
| 12048 | goto out; |
| 12049 | |
| 12050 | func->srf_include = |
| 12051 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 12052 | |
| 12053 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 12054 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 12055 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 12056 | err = -EINVAL; |
| 12057 | goto out; |
| 12058 | } |
| 12059 | |
| 12060 | func->srf_bf_len = |
| 12061 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 12062 | func->srf_bf = |
| 12063 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 12064 | func->srf_bf_len, GFP_KERNEL); |
| 12065 | if (!func->srf_bf) { |
| 12066 | err = -ENOMEM; |
| 12067 | goto out; |
| 12068 | } |
| 12069 | |
| 12070 | func->srf_bf_idx = |
| 12071 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 12072 | } else { |
| 12073 | struct nlattr *attr, *mac_attr = |
| 12074 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 12075 | int n_entries, rem, i = 0; |
| 12076 | |
| 12077 | if (!mac_attr) { |
| 12078 | err = -EINVAL; |
| 12079 | goto out; |
| 12080 | } |
| 12081 | |
| 12082 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 12083 | if (n_entries <= 0) { |
| 12084 | err = -EINVAL; |
| 12085 | goto out; |
| 12086 | } |
| 12087 | |
| 12088 | func->srf_num_macs = n_entries; |
| 12089 | func->srf_macs = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 12090 | kcalloc(n_entries, sizeof(*func->srf_macs), |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12091 | GFP_KERNEL); |
| 12092 | if (!func->srf_macs) { |
| 12093 | err = -ENOMEM; |
| 12094 | goto out; |
| 12095 | } |
| 12096 | |
| 12097 | nla_for_each_nested(attr, mac_attr, rem) |
| 12098 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 12099 | sizeof(*func->srf_macs)); |
| 12100 | } |
| 12101 | } |
| 12102 | |
| 12103 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 12104 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 12105 | func, true); |
| 12106 | if (err) |
| 12107 | goto out; |
| 12108 | } |
| 12109 | |
| 12110 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 12111 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 12112 | func, false); |
| 12113 | if (err) |
| 12114 | goto out; |
| 12115 | } |
| 12116 | |
| 12117 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12118 | if (!msg) { |
| 12119 | err = -ENOMEM; |
| 12120 | goto out; |
| 12121 | } |
| 12122 | |
| 12123 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12124 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 12125 | /* This can't really happen - we just allocated 4KB */ |
| 12126 | if (WARN_ON(!hdr)) { |
| 12127 | err = -ENOMEM; |
| 12128 | goto out; |
| 12129 | } |
| 12130 | |
| 12131 | err = rdev_add_nan_func(rdev, wdev, func); |
| 12132 | out: |
| 12133 | if (err < 0) { |
| 12134 | cfg80211_free_nan_func(func); |
| 12135 | nlmsg_free(msg); |
| 12136 | return err; |
| 12137 | } |
| 12138 | |
| 12139 | /* propagate the instance id and cookie to userspace */ |
| 12140 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 12141 | NL80211_ATTR_PAD)) |
| 12142 | goto nla_put_failure; |
| 12143 | |
| 12144 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 12145 | if (!func_attr) |
| 12146 | goto nla_put_failure; |
| 12147 | |
| 12148 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 12149 | func->instance_id)) |
| 12150 | goto nla_put_failure; |
| 12151 | |
| 12152 | nla_nest_end(msg, func_attr); |
| 12153 | |
| 12154 | genlmsg_end(msg, hdr); |
| 12155 | return genlmsg_reply(msg, info); |
| 12156 | |
| 12157 | nla_put_failure: |
| 12158 | nlmsg_free(msg); |
| 12159 | return -ENOBUFS; |
| 12160 | } |
| 12161 | |
| 12162 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 12163 | struct genl_info *info) |
| 12164 | { |
| 12165 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12166 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12167 | u64 cookie; |
| 12168 | |
| 12169 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12170 | return -EOPNOTSUPP; |
| 12171 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12172 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12173 | return -ENOTCONN; |
| 12174 | |
| 12175 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 12176 | return -EINVAL; |
| 12177 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12178 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 12179 | |
| 12180 | rdev_del_nan_func(rdev, wdev, cookie); |
| 12181 | |
| 12182 | return 0; |
| 12183 | } |
| 12184 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12185 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 12186 | struct genl_info *info) |
| 12187 | { |
| 12188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12189 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12190 | struct cfg80211_nan_conf conf = {}; |
| 12191 | u32 changed = 0; |
| 12192 | |
| 12193 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12194 | return -EOPNOTSUPP; |
| 12195 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12196 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12197 | return -ENOTCONN; |
| 12198 | |
| 12199 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 12200 | conf.master_pref = |
| 12201 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 12202 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 12203 | return -EINVAL; |
| 12204 | |
| 12205 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 12206 | } |
| 12207 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 12208 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 12209 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 12210 | |
| 12211 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 12212 | return -EOPNOTSUPP; |
| 12213 | |
| 12214 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 12215 | return -EINVAL; |
| 12216 | |
| 12217 | conf.bands = bands; |
| 12218 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12219 | } |
| 12220 | |
| 12221 | if (!changed) |
| 12222 | return -EINVAL; |
| 12223 | |
| 12224 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 12225 | } |
| 12226 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 12227 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 12228 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 12229 | { |
| 12230 | struct wiphy *wiphy = wdev->wiphy; |
| 12231 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12232 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 12233 | struct sk_buff *msg; |
| 12234 | void *hdr; |
| 12235 | |
| 12236 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 12237 | return; |
| 12238 | |
| 12239 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12240 | if (!msg) |
| 12241 | return; |
| 12242 | |
| 12243 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 12244 | if (!hdr) { |
| 12245 | nlmsg_free(msg); |
| 12246 | return; |
| 12247 | } |
| 12248 | |
| 12249 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12250 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12251 | wdev->netdev->ifindex)) || |
| 12252 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12253 | NL80211_ATTR_PAD)) |
| 12254 | goto nla_put_failure; |
| 12255 | |
| 12256 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 12257 | NL80211_ATTR_PAD) || |
| 12258 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 12259 | goto nla_put_failure; |
| 12260 | |
| 12261 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); |
| 12262 | if (!match_attr) |
| 12263 | goto nla_put_failure; |
| 12264 | |
| 12265 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); |
| 12266 | if (!local_func_attr) |
| 12267 | goto nla_put_failure; |
| 12268 | |
| 12269 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 12270 | goto nla_put_failure; |
| 12271 | |
| 12272 | nla_nest_end(msg, local_func_attr); |
| 12273 | |
| 12274 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); |
| 12275 | if (!peer_func_attr) |
| 12276 | goto nla_put_failure; |
| 12277 | |
| 12278 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 12279 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 12280 | goto nla_put_failure; |
| 12281 | |
| 12282 | if (match->info && match->info_len && |
| 12283 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 12284 | match->info)) |
| 12285 | goto nla_put_failure; |
| 12286 | |
| 12287 | nla_nest_end(msg, peer_func_attr); |
| 12288 | nla_nest_end(msg, match_attr); |
| 12289 | genlmsg_end(msg, hdr); |
| 12290 | |
| 12291 | if (!wdev->owner_nlportid) |
| 12292 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 12293 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 12294 | else |
| 12295 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 12296 | wdev->owner_nlportid); |
| 12297 | |
| 12298 | return; |
| 12299 | |
| 12300 | nla_put_failure: |
| 12301 | nlmsg_free(msg); |
| 12302 | } |
| 12303 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 12304 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 12305 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 12306 | u8 inst_id, |
| 12307 | enum nl80211_nan_func_term_reason reason, |
| 12308 | u64 cookie, gfp_t gfp) |
| 12309 | { |
| 12310 | struct wiphy *wiphy = wdev->wiphy; |
| 12311 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12312 | struct sk_buff *msg; |
| 12313 | struct nlattr *func_attr; |
| 12314 | void *hdr; |
| 12315 | |
| 12316 | if (WARN_ON(!inst_id)) |
| 12317 | return; |
| 12318 | |
| 12319 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12320 | if (!msg) |
| 12321 | return; |
| 12322 | |
| 12323 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 12324 | if (!hdr) { |
| 12325 | nlmsg_free(msg); |
| 12326 | return; |
| 12327 | } |
| 12328 | |
| 12329 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12330 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12331 | wdev->netdev->ifindex)) || |
| 12332 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12333 | NL80211_ATTR_PAD)) |
| 12334 | goto nla_put_failure; |
| 12335 | |
| 12336 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12337 | NL80211_ATTR_PAD)) |
| 12338 | goto nla_put_failure; |
| 12339 | |
| 12340 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 12341 | if (!func_attr) |
| 12342 | goto nla_put_failure; |
| 12343 | |
| 12344 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 12345 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 12346 | goto nla_put_failure; |
| 12347 | |
| 12348 | nla_nest_end(msg, func_attr); |
| 12349 | genlmsg_end(msg, hdr); |
| 12350 | |
| 12351 | if (!wdev->owner_nlportid) |
| 12352 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 12353 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 12354 | else |
| 12355 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 12356 | wdev->owner_nlportid); |
| 12357 | |
| 12358 | return; |
| 12359 | |
| 12360 | nla_put_failure: |
| 12361 | nlmsg_free(msg); |
| 12362 | } |
| 12363 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 12364 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 12365 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 12366 | struct genl_info *info) |
| 12367 | { |
| 12368 | void *hdr; |
| 12369 | struct sk_buff *msg; |
| 12370 | |
| 12371 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12372 | if (!msg) |
| 12373 | return -ENOMEM; |
| 12374 | |
| 12375 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12376 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 12377 | if (!hdr) |
| 12378 | goto nla_put_failure; |
| 12379 | |
| 12380 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 12381 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 12382 | goto nla_put_failure; |
| 12383 | |
| 12384 | genlmsg_end(msg, hdr); |
| 12385 | return genlmsg_reply(msg, info); |
| 12386 | |
| 12387 | nla_put_failure: |
| 12388 | kfree_skb(msg); |
| 12389 | return -ENOBUFS; |
| 12390 | } |
| 12391 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12392 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 12393 | { |
| 12394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12395 | struct cfg80211_update_ft_ies_params ft_params; |
| 12396 | struct net_device *dev = info->user_ptr[1]; |
| 12397 | |
| 12398 | if (!rdev->ops->update_ft_ies) |
| 12399 | return -EOPNOTSUPP; |
| 12400 | |
| 12401 | if (!info->attrs[NL80211_ATTR_MDID] || |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 12402 | !info->attrs[NL80211_ATTR_IE]) |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12403 | return -EINVAL; |
| 12404 | |
| 12405 | memset(&ft_params, 0, sizeof(ft_params)); |
| 12406 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 12407 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 12408 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 12409 | |
| 12410 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 12411 | } |
| 12412 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12413 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 12414 | struct genl_info *info) |
| 12415 | { |
| 12416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12417 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12418 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 12419 | u16 duration; |
| 12420 | int ret; |
| 12421 | |
| 12422 | if (!rdev->ops->crit_proto_start) |
| 12423 | return -EOPNOTSUPP; |
| 12424 | |
| 12425 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 12426 | return -EINVAL; |
| 12427 | |
| 12428 | if (rdev->crit_proto_nlportid) |
| 12429 | return -EBUSY; |
| 12430 | |
| 12431 | /* determine protocol if provided */ |
| 12432 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 12433 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 12434 | |
| 12435 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 12436 | return -EINVAL; |
| 12437 | |
| 12438 | /* timeout must be provided */ |
| 12439 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 12440 | return -EINVAL; |
| 12441 | |
| 12442 | duration = |
| 12443 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 12444 | |
| 12445 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 12446 | return -ERANGE; |
| 12447 | |
| 12448 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 12449 | if (!ret) |
| 12450 | rdev->crit_proto_nlportid = info->snd_portid; |
| 12451 | |
| 12452 | return ret; |
| 12453 | } |
| 12454 | |
| 12455 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 12456 | struct genl_info *info) |
| 12457 | { |
| 12458 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12459 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12460 | |
| 12461 | if (!rdev->ops->crit_proto_stop) |
| 12462 | return -EOPNOTSUPP; |
| 12463 | |
| 12464 | if (rdev->crit_proto_nlportid) { |
| 12465 | rdev->crit_proto_nlportid = 0; |
| 12466 | rdev_crit_proto_stop(rdev, wdev); |
| 12467 | } |
| 12468 | return 0; |
| 12469 | } |
| 12470 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12471 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 12472 | { |
| 12473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12474 | struct wireless_dev *wdev = |
| 12475 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 12476 | int i, err; |
| 12477 | u32 vid, subcmd; |
| 12478 | |
| 12479 | if (!rdev->wiphy.vendor_commands) |
| 12480 | return -EOPNOTSUPP; |
| 12481 | |
| 12482 | if (IS_ERR(wdev)) { |
| 12483 | err = PTR_ERR(wdev); |
| 12484 | if (err != -EINVAL) |
| 12485 | return err; |
| 12486 | wdev = NULL; |
| 12487 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 12488 | return -EINVAL; |
| 12489 | } |
| 12490 | |
| 12491 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 12492 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 12493 | return -EINVAL; |
| 12494 | |
| 12495 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 12496 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 12497 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 12498 | const struct wiphy_vendor_command *vcmd; |
| 12499 | void *data = NULL; |
| 12500 | int len = 0; |
| 12501 | |
| 12502 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 12503 | |
| 12504 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 12505 | continue; |
| 12506 | |
| 12507 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 12508 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 12509 | if (!wdev) |
| 12510 | return -EINVAL; |
| 12511 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 12512 | !wdev->netdev) |
| 12513 | return -EINVAL; |
| 12514 | |
| 12515 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12516 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12517 | return -ENETDOWN; |
| 12518 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12519 | |
| 12520 | if (!vcmd->doit) |
| 12521 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12522 | } else { |
| 12523 | wdev = NULL; |
| 12524 | } |
| 12525 | |
| 12526 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 12527 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 12528 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 12529 | } |
| 12530 | |
| 12531 | rdev->cur_cmd_info = info; |
| 12532 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 12533 | data, len); |
| 12534 | rdev->cur_cmd_info = NULL; |
| 12535 | return err; |
| 12536 | } |
| 12537 | |
| 12538 | return -EOPNOTSUPP; |
| 12539 | } |
| 12540 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12541 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 12542 | struct netlink_callback *cb, |
| 12543 | struct cfg80211_registered_device **rdev, |
| 12544 | struct wireless_dev **wdev) |
| 12545 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12546 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12547 | u32 vid, subcmd; |
| 12548 | unsigned int i; |
| 12549 | int vcmd_idx = -1; |
| 12550 | int err; |
| 12551 | void *data = NULL; |
| 12552 | unsigned int data_len = 0; |
| 12553 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12554 | if (cb->args[0]) { |
| 12555 | /* subtract the 1 again here */ |
| 12556 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 12557 | struct wireless_dev *tmp; |
| 12558 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12559 | if (!wiphy) |
| 12560 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12561 | *rdev = wiphy_to_rdev(wiphy); |
| 12562 | *wdev = NULL; |
| 12563 | |
| 12564 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 12565 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12566 | if (tmp->identifier == cb->args[1] - 1) { |
| 12567 | *wdev = tmp; |
| 12568 | break; |
| 12569 | } |
| 12570 | } |
| 12571 | } |
| 12572 | |
| 12573 | /* keep rtnl locked in successful case */ |
| 12574 | return 0; |
| 12575 | } |
| 12576 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 12577 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf, |
| 12578 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12579 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12580 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12581 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12582 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12583 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) |
| 12584 | return -EINVAL; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12585 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12586 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12587 | if (IS_ERR(*wdev)) |
| 12588 | *wdev = NULL; |
| 12589 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12590 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12591 | if (IS_ERR(*rdev)) |
| 12592 | return PTR_ERR(*rdev); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12593 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12594 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 12595 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12596 | |
| 12597 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 12598 | const struct wiphy_vendor_command *vcmd; |
| 12599 | |
| 12600 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 12601 | |
| 12602 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 12603 | continue; |
| 12604 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12605 | if (!vcmd->dumpit) |
| 12606 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12607 | |
| 12608 | vcmd_idx = i; |
| 12609 | break; |
| 12610 | } |
| 12611 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12612 | if (vcmd_idx < 0) |
| 12613 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12614 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12615 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 12616 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 12617 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12618 | } |
| 12619 | |
| 12620 | /* 0 is the first index - add 1 to parse only once */ |
| 12621 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 12622 | /* add 1 to know if it was NULL */ |
| 12623 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 12624 | cb->args[2] = vcmd_idx; |
| 12625 | cb->args[3] = (unsigned long)data; |
| 12626 | cb->args[4] = data_len; |
| 12627 | |
| 12628 | /* keep rtnl locked in successful case */ |
| 12629 | return 0; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12630 | } |
| 12631 | |
| 12632 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 12633 | struct netlink_callback *cb) |
| 12634 | { |
| 12635 | struct cfg80211_registered_device *rdev; |
| 12636 | struct wireless_dev *wdev; |
| 12637 | unsigned int vcmd_idx; |
| 12638 | const struct wiphy_vendor_command *vcmd; |
| 12639 | void *data; |
| 12640 | int data_len; |
| 12641 | int err; |
| 12642 | struct nlattr *vendor_data; |
| 12643 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12644 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12645 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 12646 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12647 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12648 | |
| 12649 | vcmd_idx = cb->args[2]; |
| 12650 | data = (void *)cb->args[3]; |
| 12651 | data_len = cb->args[4]; |
| 12652 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 12653 | |
| 12654 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 12655 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12656 | if (!wdev) { |
| 12657 | err = -EINVAL; |
| 12658 | goto out; |
| 12659 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12660 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12661 | !wdev->netdev) { |
| 12662 | err = -EINVAL; |
| 12663 | goto out; |
| 12664 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12665 | |
| 12666 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12667 | if (!wdev_running(wdev)) { |
| 12668 | err = -ENETDOWN; |
| 12669 | goto out; |
| 12670 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12671 | } |
| 12672 | } |
| 12673 | |
| 12674 | while (1) { |
| 12675 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 12676 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 12677 | NL80211_CMD_VENDOR); |
| 12678 | if (!hdr) |
| 12679 | break; |
| 12680 | |
| 12681 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12682 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 12683 | wdev_id(wdev), |
| 12684 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12685 | genlmsg_cancel(skb, hdr); |
| 12686 | break; |
| 12687 | } |
| 12688 | |
| 12689 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 12690 | if (!vendor_data) { |
| 12691 | genlmsg_cancel(skb, hdr); |
| 12692 | break; |
| 12693 | } |
| 12694 | |
| 12695 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 12696 | (unsigned long *)&cb->args[5]); |
| 12697 | nla_nest_end(skb, vendor_data); |
| 12698 | |
| 12699 | if (err == -ENOBUFS || err == -ENOENT) { |
| 12700 | genlmsg_cancel(skb, hdr); |
| 12701 | break; |
| 12702 | } else if (err) { |
| 12703 | genlmsg_cancel(skb, hdr); |
| 12704 | goto out; |
| 12705 | } |
| 12706 | |
| 12707 | genlmsg_end(skb, hdr); |
| 12708 | } |
| 12709 | |
| 12710 | err = skb->len; |
| 12711 | out: |
| 12712 | rtnl_unlock(); |
| 12713 | return err; |
| 12714 | } |
| 12715 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12716 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 12717 | enum nl80211_commands cmd, |
| 12718 | enum nl80211_attrs attr, |
| 12719 | int approxlen) |
| 12720 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12721 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12722 | |
| 12723 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 12724 | return NULL; |
| 12725 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 12726 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12727 | rdev->cur_cmd_info->snd_portid, |
| 12728 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 12729 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12730 | } |
| 12731 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 12732 | |
| 12733 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 12734 | { |
| 12735 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 12736 | void *hdr = ((void **)skb->cb)[1]; |
| 12737 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 12738 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 12739 | /* clear CB data for netlink core to own from now on */ |
| 12740 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 12741 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12742 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 12743 | kfree_skb(skb); |
| 12744 | return -EINVAL; |
| 12745 | } |
| 12746 | |
| 12747 | nla_nest_end(skb, data); |
| 12748 | genlmsg_end(skb, hdr); |
| 12749 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 12750 | } |
| 12751 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 12752 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12753 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 12754 | struct genl_info *info) |
| 12755 | { |
| 12756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12757 | struct cfg80211_qos_map *qos_map = NULL; |
| 12758 | struct net_device *dev = info->user_ptr[1]; |
| 12759 | u8 *pos, len, num_des, des_len, des; |
| 12760 | int ret; |
| 12761 | |
| 12762 | if (!rdev->ops->set_qos_map) |
| 12763 | return -EOPNOTSUPP; |
| 12764 | |
| 12765 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 12766 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 12767 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 12768 | |
| 12769 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 12770 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 12771 | return -EINVAL; |
| 12772 | |
| 12773 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 12774 | if (!qos_map) |
| 12775 | return -ENOMEM; |
| 12776 | |
| 12777 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 12778 | if (num_des) { |
| 12779 | des_len = num_des * |
| 12780 | sizeof(struct cfg80211_dscp_exception); |
| 12781 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 12782 | qos_map->num_des = num_des; |
| 12783 | for (des = 0; des < num_des; des++) { |
| 12784 | if (qos_map->dscp_exception[des].up > 7) { |
| 12785 | kfree(qos_map); |
| 12786 | return -EINVAL; |
| 12787 | } |
| 12788 | } |
| 12789 | pos += des_len; |
| 12790 | } |
| 12791 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 12792 | } |
| 12793 | |
| 12794 | wdev_lock(dev->ieee80211_ptr); |
| 12795 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 12796 | if (!ret) |
| 12797 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 12798 | wdev_unlock(dev->ieee80211_ptr); |
| 12799 | |
| 12800 | kfree(qos_map); |
| 12801 | return ret; |
| 12802 | } |
| 12803 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12804 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12805 | { |
| 12806 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12807 | struct net_device *dev = info->user_ptr[1]; |
| 12808 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12809 | const u8 *peer; |
| 12810 | u8 tsid, up; |
| 12811 | u16 admitted_time = 0; |
| 12812 | int err; |
| 12813 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12814 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12815 | return -EOPNOTSUPP; |
| 12816 | |
| 12817 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 12818 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 12819 | return -EINVAL; |
| 12820 | |
| 12821 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12822 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12823 | |
| 12824 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12825 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12826 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12827 | * need more attributes for that (e.g. BA session requirement); |
| 12828 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12829 | */ |
| 12830 | return -EINVAL; |
| 12831 | } |
| 12832 | |
| 12833 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12834 | |
| 12835 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 12836 | admitted_time = |
| 12837 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 12838 | if (!admitted_time) |
| 12839 | return -EINVAL; |
| 12840 | } |
| 12841 | |
| 12842 | wdev_lock(wdev); |
| 12843 | switch (wdev->iftype) { |
| 12844 | case NL80211_IFTYPE_STATION: |
| 12845 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12846 | if (wdev->current_bss) |
| 12847 | break; |
| 12848 | err = -ENOTCONN; |
| 12849 | goto out; |
| 12850 | default: |
| 12851 | err = -EOPNOTSUPP; |
| 12852 | goto out; |
| 12853 | } |
| 12854 | |
| 12855 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 12856 | |
| 12857 | out: |
| 12858 | wdev_unlock(wdev); |
| 12859 | return err; |
| 12860 | } |
| 12861 | |
| 12862 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12863 | { |
| 12864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12865 | struct net_device *dev = info->user_ptr[1]; |
| 12866 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12867 | const u8 *peer; |
| 12868 | u8 tsid; |
| 12869 | int err; |
| 12870 | |
| 12871 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 12872 | return -EINVAL; |
| 12873 | |
| 12874 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12875 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12876 | |
| 12877 | wdev_lock(wdev); |
| 12878 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 12879 | wdev_unlock(wdev); |
| 12880 | |
| 12881 | return err; |
| 12882 | } |
| 12883 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12884 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 12885 | struct genl_info *info) |
| 12886 | { |
| 12887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12888 | struct net_device *dev = info->user_ptr[1]; |
| 12889 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12890 | struct cfg80211_chan_def chandef = {}; |
| 12891 | const u8 *addr; |
| 12892 | u8 oper_class; |
| 12893 | int err; |
| 12894 | |
| 12895 | if (!rdev->ops->tdls_channel_switch || |
| 12896 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12897 | return -EOPNOTSUPP; |
| 12898 | |
| 12899 | switch (dev->ieee80211_ptr->iftype) { |
| 12900 | case NL80211_IFTYPE_STATION: |
| 12901 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12902 | break; |
| 12903 | default: |
| 12904 | return -EOPNOTSUPP; |
| 12905 | } |
| 12906 | |
| 12907 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 12908 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 12909 | return -EINVAL; |
| 12910 | |
| 12911 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 12912 | if (err) |
| 12913 | return err; |
| 12914 | |
| 12915 | /* |
| 12916 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 12917 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 12918 | * specification is not defined for them. |
| 12919 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 12920 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12921 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 12922 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 12923 | return -EINVAL; |
| 12924 | |
| 12925 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 12926 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 12927 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12928 | return -EINVAL; |
| 12929 | |
| 12930 | /* don't allow switching to DFS channels */ |
| 12931 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 12932 | return -EINVAL; |
| 12933 | |
| 12934 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12935 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 12936 | |
| 12937 | wdev_lock(wdev); |
| 12938 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 12939 | wdev_unlock(wdev); |
| 12940 | |
| 12941 | return err; |
| 12942 | } |
| 12943 | |
| 12944 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 12945 | struct genl_info *info) |
| 12946 | { |
| 12947 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12948 | struct net_device *dev = info->user_ptr[1]; |
| 12949 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12950 | const u8 *addr; |
| 12951 | |
| 12952 | if (!rdev->ops->tdls_channel_switch || |
| 12953 | !rdev->ops->tdls_cancel_channel_switch || |
| 12954 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12955 | return -EOPNOTSUPP; |
| 12956 | |
| 12957 | switch (dev->ieee80211_ptr->iftype) { |
| 12958 | case NL80211_IFTYPE_STATION: |
| 12959 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12960 | break; |
| 12961 | default: |
| 12962 | return -EOPNOTSUPP; |
| 12963 | } |
| 12964 | |
| 12965 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12966 | return -EINVAL; |
| 12967 | |
| 12968 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12969 | |
| 12970 | wdev_lock(wdev); |
| 12971 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 12972 | wdev_unlock(wdev); |
| 12973 | |
| 12974 | return 0; |
| 12975 | } |
| 12976 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12977 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 12978 | struct genl_info *info) |
| 12979 | { |
| 12980 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12981 | struct net_device *dev = info->user_ptr[1]; |
| 12982 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12983 | const struct nlattr *nla; |
| 12984 | bool enabled; |
| 12985 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12986 | if (!rdev->ops->set_multicast_to_unicast) |
| 12987 | return -EOPNOTSUPP; |
| 12988 | |
| 12989 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12990 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12991 | return -EOPNOTSUPP; |
| 12992 | |
| 12993 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 12994 | enabled = nla_get_flag(nla); |
| 12995 | |
| 12996 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 12997 | } |
| 12998 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 12999 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 13000 | { |
| 13001 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13002 | struct net_device *dev = info->user_ptr[1]; |
| 13003 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13004 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 13005 | int ret; |
| 13006 | |
| 13007 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 13008 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 13009 | return -EOPNOTSUPP; |
| 13010 | |
| 13011 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 13012 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 13013 | return -EOPNOTSUPP; |
| 13014 | |
| 13015 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 13016 | return -EINVAL; |
| 13017 | |
| 13018 | wdev_lock(wdev); |
| 13019 | if (!wdev->current_bss) { |
| 13020 | ret = -ENOTCONN; |
| 13021 | goto out; |
| 13022 | } |
| 13023 | |
| 13024 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13025 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 13026 | ret = -EINVAL; |
| 13027 | goto out; |
| 13028 | } |
| 13029 | |
| 13030 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 13031 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 13032 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 13033 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 13034 | ret = -EINVAL; |
| 13035 | goto out; |
| 13036 | } |
| 13037 | |
| 13038 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { |
| 13039 | int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 13040 | |
| 13041 | if (r0_name_len != WLAN_PMK_NAME_LEN) { |
| 13042 | ret = -EINVAL; |
| 13043 | goto out; |
| 13044 | } |
| 13045 | |
| 13046 | pmk_conf.pmk_r0_name = |
| 13047 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 13048 | } |
| 13049 | |
| 13050 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 13051 | out: |
| 13052 | wdev_unlock(wdev); |
| 13053 | return ret; |
| 13054 | } |
| 13055 | |
| 13056 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 13057 | { |
| 13058 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13059 | struct net_device *dev = info->user_ptr[1]; |
| 13060 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13061 | const u8 *aa; |
| 13062 | int ret; |
| 13063 | |
| 13064 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 13065 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 13066 | return -EOPNOTSUPP; |
| 13067 | |
| 13068 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 13069 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 13070 | return -EOPNOTSUPP; |
| 13071 | |
| 13072 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 13073 | return -EINVAL; |
| 13074 | |
| 13075 | wdev_lock(wdev); |
| 13076 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13077 | ret = rdev_del_pmk(rdev, dev, aa); |
| 13078 | wdev_unlock(wdev); |
| 13079 | |
| 13080 | return ret; |
| 13081 | } |
| 13082 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13083 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
| 13084 | { |
| 13085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13086 | struct net_device *dev = info->user_ptr[1]; |
| 13087 | struct cfg80211_external_auth_params params; |
| 13088 | |
Srinivas Dasari | db8d93a | 2018-02-02 11:15:27 +0200 | [diff] [blame] | 13089 | if (!rdev->ops->external_auth) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13090 | return -EOPNOTSUPP; |
| 13091 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame^] | 13092 | if (!info->attrs[NL80211_ATTR_SSID] && |
| 13093 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 13094 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13095 | return -EINVAL; |
| 13096 | |
| 13097 | if (!info->attrs[NL80211_ATTR_BSSID]) |
| 13098 | return -EINVAL; |
| 13099 | |
| 13100 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) |
| 13101 | return -EINVAL; |
| 13102 | |
| 13103 | memset(¶ms, 0, sizeof(params)); |
| 13104 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame^] | 13105 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 13106 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 13107 | if (params.ssid.ssid_len == 0 || |
| 13108 | params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 13109 | return -EINVAL; |
| 13110 | memcpy(params.ssid.ssid, |
| 13111 | nla_data(info->attrs[NL80211_ATTR_SSID]), |
| 13112 | params.ssid.ssid_len); |
| 13113 | } |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13114 | |
| 13115 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), |
| 13116 | ETH_ALEN); |
| 13117 | |
| 13118 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 13119 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame^] | 13120 | if (info->attrs[NL80211_ATTR_PMKID]) |
| 13121 | params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 13122 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13123 | return rdev_external_auth(rdev, dev, ¶ms); |
| 13124 | } |
| 13125 | |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 13126 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) |
| 13127 | { |
| 13128 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13129 | struct net_device *dev = info->user_ptr[1]; |
| 13130 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13131 | const u8 *buf; |
| 13132 | size_t len; |
| 13133 | u8 *dest; |
| 13134 | u16 proto; |
| 13135 | bool noencrypt; |
| 13136 | int err; |
| 13137 | |
| 13138 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 13139 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 13140 | return -EOPNOTSUPP; |
| 13141 | |
| 13142 | if (!rdev->ops->tx_control_port) |
| 13143 | return -EOPNOTSUPP; |
| 13144 | |
| 13145 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 13146 | !info->attrs[NL80211_ATTR_MAC] || |
| 13147 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 13148 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); |
| 13149 | return -EINVAL; |
| 13150 | } |
| 13151 | |
| 13152 | wdev_lock(wdev); |
| 13153 | |
| 13154 | switch (wdev->iftype) { |
| 13155 | case NL80211_IFTYPE_AP: |
| 13156 | case NL80211_IFTYPE_P2P_GO: |
| 13157 | case NL80211_IFTYPE_MESH_POINT: |
| 13158 | break; |
| 13159 | case NL80211_IFTYPE_ADHOC: |
| 13160 | case NL80211_IFTYPE_STATION: |
| 13161 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13162 | if (wdev->current_bss) |
| 13163 | break; |
| 13164 | err = -ENOTCONN; |
| 13165 | goto out; |
| 13166 | default: |
| 13167 | err = -EOPNOTSUPP; |
| 13168 | goto out; |
| 13169 | } |
| 13170 | |
| 13171 | wdev_unlock(wdev); |
| 13172 | |
| 13173 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 13174 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 13175 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13176 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 13177 | noencrypt = |
| 13178 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); |
| 13179 | |
| 13180 | return rdev_tx_control_port(rdev, dev, buf, len, |
| 13181 | dest, cpu_to_be16(proto), noencrypt); |
| 13182 | |
| 13183 | out: |
| 13184 | wdev_unlock(wdev); |
| 13185 | return err; |
| 13186 | } |
| 13187 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 13188 | static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, |
| 13189 | struct genl_info *info) |
| 13190 | { |
| 13191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13192 | struct net_device *dev = info->user_ptr[1]; |
| 13193 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13194 | struct cfg80211_ftm_responder_stats ftm_stats = {}; |
| 13195 | struct sk_buff *msg; |
| 13196 | void *hdr; |
| 13197 | struct nlattr *ftm_stats_attr; |
| 13198 | int err; |
| 13199 | |
| 13200 | if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) |
| 13201 | return -EOPNOTSUPP; |
| 13202 | |
| 13203 | err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); |
| 13204 | if (err) |
| 13205 | return err; |
| 13206 | |
| 13207 | if (!ftm_stats.filled) |
| 13208 | return -ENODATA; |
| 13209 | |
| 13210 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13211 | if (!msg) |
| 13212 | return -ENOMEM; |
| 13213 | |
| 13214 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13215 | NL80211_CMD_GET_FTM_RESPONDER_STATS); |
| 13216 | if (!hdr) |
| 13217 | return -ENOBUFS; |
| 13218 | |
| 13219 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 13220 | goto nla_put_failure; |
| 13221 | |
| 13222 | ftm_stats_attr = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER_STATS); |
| 13223 | if (!ftm_stats_attr) |
| 13224 | goto nla_put_failure; |
| 13225 | |
| 13226 | #define SET_FTM(field, name, type) \ |
| 13227 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 13228 | nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ |
| 13229 | ftm_stats.field)) \ |
| 13230 | goto nla_put_failure; } while (0) |
| 13231 | #define SET_FTM_U64(field, name) \ |
| 13232 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 13233 | nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ |
| 13234 | ftm_stats.field, NL80211_FTM_STATS_PAD)) \ |
| 13235 | goto nla_put_failure; } while (0) |
| 13236 | |
| 13237 | SET_FTM(success_num, SUCCESS_NUM, u32); |
| 13238 | SET_FTM(partial_num, PARTIAL_NUM, u32); |
| 13239 | SET_FTM(failed_num, FAILED_NUM, u32); |
| 13240 | SET_FTM(asap_num, ASAP_NUM, u32); |
| 13241 | SET_FTM(non_asap_num, NON_ASAP_NUM, u32); |
| 13242 | SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); |
| 13243 | SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); |
| 13244 | SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); |
| 13245 | SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); |
| 13246 | #undef SET_FTM |
| 13247 | |
| 13248 | nla_nest_end(msg, ftm_stats_attr); |
| 13249 | |
| 13250 | genlmsg_end(msg, hdr); |
| 13251 | return genlmsg_reply(msg, info); |
| 13252 | |
| 13253 | nla_put_failure: |
| 13254 | nlmsg_free(msg); |
| 13255 | return -ENOBUFS; |
| 13256 | } |
| 13257 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13258 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 13259 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 13260 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13261 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 13262 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 13263 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13264 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13265 | /* 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] | 13266 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 13267 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13268 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13269 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 13270 | 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] | 13271 | struct genl_info *info) |
| 13272 | { |
| 13273 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13274 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13275 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13276 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 13277 | |
| 13278 | if (rtnl) |
| 13279 | rtnl_lock(); |
| 13280 | |
| 13281 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 13282 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13283 | if (IS_ERR(rdev)) { |
| 13284 | if (rtnl) |
| 13285 | rtnl_unlock(); |
| 13286 | return PTR_ERR(rdev); |
| 13287 | } |
| 13288 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13289 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 13290 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 13291 | ASSERT_RTNL(); |
| 13292 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13293 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 13294 | info->attrs); |
| 13295 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13296 | if (rtnl) |
| 13297 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13298 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13299 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13300 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13301 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13302 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13303 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13304 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 13305 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13306 | if (rtnl) |
| 13307 | rtnl_unlock(); |
| 13308 | return -EINVAL; |
| 13309 | } |
| 13310 | |
| 13311 | info->user_ptr[1] = dev; |
| 13312 | } else { |
| 13313 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13314 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13315 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13316 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 13317 | !wdev_running(wdev)) { |
| 13318 | if (rtnl) |
| 13319 | rtnl_unlock(); |
| 13320 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13321 | } |
| 13322 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13323 | if (dev) |
| 13324 | dev_hold(dev); |
| 13325 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13326 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13327 | } |
| 13328 | |
| 13329 | return 0; |
| 13330 | } |
| 13331 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 13332 | 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] | 13333 | struct genl_info *info) |
| 13334 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13335 | if (info->user_ptr[1]) { |
| 13336 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 13337 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13338 | |
| 13339 | if (wdev->netdev) |
| 13340 | dev_put(wdev->netdev); |
| 13341 | } else { |
| 13342 | dev_put(info->user_ptr[1]); |
| 13343 | } |
| 13344 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13345 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13346 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 13347 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13348 | |
| 13349 | /* If needed, clear the netlink message payload from the SKB |
| 13350 | * as it might contain key data that shouldn't stick around on |
| 13351 | * the heap after the SKB is freed. The netlink message header |
| 13352 | * is still needed for further processing, so leave it intact. |
| 13353 | */ |
| 13354 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 13355 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 13356 | |
| 13357 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 13358 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13359 | } |
| 13360 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 13361 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13362 | { |
| 13363 | .cmd = NL80211_CMD_GET_WIPHY, |
| 13364 | .doit = nl80211_get_wiphy, |
| 13365 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 13366 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13367 | .policy = nl80211_policy, |
| 13368 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 13369 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13370 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13371 | }, |
| 13372 | { |
| 13373 | .cmd = NL80211_CMD_SET_WIPHY, |
| 13374 | .doit = nl80211_set_wiphy, |
| 13375 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13376 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13377 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13378 | }, |
| 13379 | { |
| 13380 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 13381 | .doit = nl80211_get_interface, |
| 13382 | .dumpit = nl80211_dump_interface, |
| 13383 | .policy = nl80211_policy, |
| 13384 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 13385 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13386 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13387 | }, |
| 13388 | { |
| 13389 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 13390 | .doit = nl80211_set_interface, |
| 13391 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13392 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13393 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13394 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13395 | }, |
| 13396 | { |
| 13397 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 13398 | .doit = nl80211_new_interface, |
| 13399 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13400 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13401 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13402 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13403 | }, |
| 13404 | { |
| 13405 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 13406 | .doit = nl80211_del_interface, |
| 13407 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13408 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 13409 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13410 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13411 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 13412 | { |
| 13413 | .cmd = NL80211_CMD_GET_KEY, |
| 13414 | .doit = nl80211_get_key, |
| 13415 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13416 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13417 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13418 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 13419 | }, |
| 13420 | { |
| 13421 | .cmd = NL80211_CMD_SET_KEY, |
| 13422 | .doit = nl80211_set_key, |
| 13423 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13424 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13425 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13426 | NL80211_FLAG_NEED_RTNL | |
| 13427 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 13428 | }, |
| 13429 | { |
| 13430 | .cmd = NL80211_CMD_NEW_KEY, |
| 13431 | .doit = nl80211_new_key, |
| 13432 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13433 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13434 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13435 | NL80211_FLAG_NEED_RTNL | |
| 13436 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 13437 | }, |
| 13438 | { |
| 13439 | .cmd = NL80211_CMD_DEL_KEY, |
| 13440 | .doit = nl80211_del_key, |
| 13441 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13442 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13443 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13444 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 13445 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13446 | { |
| 13447 | .cmd = NL80211_CMD_SET_BEACON, |
| 13448 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13449 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 13450 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13451 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13452 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13453 | }, |
| 13454 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 13455 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13456 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13457 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 13458 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13459 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13460 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13461 | }, |
| 13462 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 13463 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13464 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13465 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 13466 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13467 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13468 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13469 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13470 | { |
| 13471 | .cmd = NL80211_CMD_GET_STATION, |
| 13472 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13473 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13474 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13475 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13476 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13477 | }, |
| 13478 | { |
| 13479 | .cmd = NL80211_CMD_SET_STATION, |
| 13480 | .doit = nl80211_set_station, |
| 13481 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13482 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13483 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13484 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13485 | }, |
| 13486 | { |
| 13487 | .cmd = NL80211_CMD_NEW_STATION, |
| 13488 | .doit = nl80211_new_station, |
| 13489 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13490 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13491 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13492 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13493 | }, |
| 13494 | { |
| 13495 | .cmd = NL80211_CMD_DEL_STATION, |
| 13496 | .doit = nl80211_del_station, |
| 13497 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13498 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13500 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13501 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13502 | { |
| 13503 | .cmd = NL80211_CMD_GET_MPATH, |
| 13504 | .doit = nl80211_get_mpath, |
| 13505 | .dumpit = nl80211_dump_mpath, |
| 13506 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13507 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13508 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13509 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13510 | }, |
| 13511 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 13512 | .cmd = NL80211_CMD_GET_MPP, |
| 13513 | .doit = nl80211_get_mpp, |
| 13514 | .dumpit = nl80211_dump_mpp, |
| 13515 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13516 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 13517 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13518 | NL80211_FLAG_NEED_RTNL, |
| 13519 | }, |
| 13520 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13521 | .cmd = NL80211_CMD_SET_MPATH, |
| 13522 | .doit = nl80211_set_mpath, |
| 13523 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13524 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13525 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13526 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13527 | }, |
| 13528 | { |
| 13529 | .cmd = NL80211_CMD_NEW_MPATH, |
| 13530 | .doit = nl80211_new_mpath, |
| 13531 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13532 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13533 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13534 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13535 | }, |
| 13536 | { |
| 13537 | .cmd = NL80211_CMD_DEL_MPATH, |
| 13538 | .doit = nl80211_del_mpath, |
| 13539 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13540 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13541 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13542 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13543 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 13544 | { |
| 13545 | .cmd = NL80211_CMD_SET_BSS, |
| 13546 | .doit = nl80211_set_bss, |
| 13547 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13548 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13549 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13550 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 13551 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 13552 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 13553 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13554 | .doit = nl80211_get_reg_do, |
| 13555 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 13556 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 13557 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 13558 | /* can be retrieved by unprivileged users */ |
| 13559 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 13560 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 13561 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 13562 | .cmd = NL80211_CMD_SET_REG, |
| 13563 | .doit = nl80211_set_reg, |
| 13564 | .policy = nl80211_policy, |
| 13565 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 13566 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 13567 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 13568 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 13569 | { |
| 13570 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 13571 | .doit = nl80211_req_set_reg, |
| 13572 | .policy = nl80211_policy, |
| 13573 | .flags = GENL_ADMIN_PERM, |
| 13574 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 13575 | { |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 13576 | .cmd = NL80211_CMD_RELOAD_REGDB, |
| 13577 | .doit = nl80211_reload_regdb, |
| 13578 | .policy = nl80211_policy, |
| 13579 | .flags = GENL_ADMIN_PERM, |
| 13580 | }, |
| 13581 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 13582 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 13583 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 13584 | .policy = nl80211_policy, |
| 13585 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13587 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 13588 | }, |
| 13589 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 13590 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 13591 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 13592 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13593 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13594 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13595 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 13596 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 13597 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13598 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 13599 | .doit = nl80211_trigger_scan, |
| 13600 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13601 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13602 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13603 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13604 | }, |
| 13605 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 13606 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 13607 | .doit = nl80211_abort_scan, |
| 13608 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13609 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 13610 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13611 | NL80211_FLAG_NEED_RTNL, |
| 13612 | }, |
| 13613 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13614 | .cmd = NL80211_CMD_GET_SCAN, |
| 13615 | .policy = nl80211_policy, |
| 13616 | .dumpit = nl80211_dump_scan, |
| 13617 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13618 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13619 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 13620 | .doit = nl80211_start_sched_scan, |
| 13621 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13622 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13623 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13624 | NL80211_FLAG_NEED_RTNL, |
| 13625 | }, |
| 13626 | { |
| 13627 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 13628 | .doit = nl80211_stop_sched_scan, |
| 13629 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13630 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13631 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13632 | NL80211_FLAG_NEED_RTNL, |
| 13633 | }, |
| 13634 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13635 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 13636 | .doit = nl80211_authenticate, |
| 13637 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13638 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13639 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13640 | NL80211_FLAG_NEED_RTNL | |
| 13641 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13642 | }, |
| 13643 | { |
| 13644 | .cmd = NL80211_CMD_ASSOCIATE, |
| 13645 | .doit = nl80211_associate, |
| 13646 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13647 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13648 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13649 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13650 | }, |
| 13651 | { |
| 13652 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 13653 | .doit = nl80211_deauthenticate, |
| 13654 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13655 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13656 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13657 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13658 | }, |
| 13659 | { |
| 13660 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 13661 | .doit = nl80211_disassociate, |
| 13662 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13663 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13664 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13665 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13666 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13667 | { |
| 13668 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 13669 | .doit = nl80211_join_ibss, |
| 13670 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13671 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13672 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13673 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13674 | }, |
| 13675 | { |
| 13676 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 13677 | .doit = nl80211_leave_ibss, |
| 13678 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13679 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13680 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13681 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13682 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 13683 | #ifdef CONFIG_NL80211_TESTMODE |
| 13684 | { |
| 13685 | .cmd = NL80211_CMD_TESTMODE, |
| 13686 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 13687 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 13688 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13689 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13690 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13691 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 13692 | }, |
| 13693 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13694 | { |
| 13695 | .cmd = NL80211_CMD_CONNECT, |
| 13696 | .doit = nl80211_connect, |
| 13697 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13698 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13699 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13700 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13701 | }, |
| 13702 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 13703 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
| 13704 | .doit = nl80211_update_connect_params, |
| 13705 | .policy = nl80211_policy, |
| 13706 | .flags = GENL_ADMIN_PERM, |
| 13707 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13708 | NL80211_FLAG_NEED_RTNL, |
| 13709 | }, |
| 13710 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13711 | .cmd = NL80211_CMD_DISCONNECT, |
| 13712 | .doit = nl80211_disconnect, |
| 13713 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13714 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13715 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13716 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13717 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13718 | { |
| 13719 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 13720 | .doit = nl80211_wiphy_netns, |
| 13721 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13722 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13723 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13724 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13725 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 13726 | { |
| 13727 | .cmd = NL80211_CMD_GET_SURVEY, |
| 13728 | .policy = nl80211_policy, |
| 13729 | .dumpit = nl80211_dump_survey, |
| 13730 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 13731 | { |
| 13732 | .cmd = NL80211_CMD_SET_PMKSA, |
| 13733 | .doit = nl80211_setdel_pmksa, |
| 13734 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13735 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13736 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13737 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 13738 | }, |
| 13739 | { |
| 13740 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 13741 | .doit = nl80211_setdel_pmksa, |
| 13742 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13743 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13744 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13745 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 13746 | }, |
| 13747 | { |
| 13748 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 13749 | .doit = nl80211_flush_pmksa, |
| 13750 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13751 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13752 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13753 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 13754 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13755 | { |
| 13756 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 13757 | .doit = nl80211_remain_on_channel, |
| 13758 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13759 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13760 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13761 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13762 | }, |
| 13763 | { |
| 13764 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 13765 | .doit = nl80211_cancel_remain_on_channel, |
| 13766 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13767 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13768 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13769 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13770 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 13771 | { |
| 13772 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 13773 | .doit = nl80211_set_tx_bitrate_mask, |
| 13774 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13775 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13776 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13777 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 13778 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13779 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 13780 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 13781 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13782 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13783 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13784 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13785 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13786 | }, |
| 13787 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 13788 | .cmd = NL80211_CMD_FRAME, |
| 13789 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13790 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13791 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13792 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13793 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13794 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 13795 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 13796 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 13797 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 13798 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13799 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13800 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 13801 | NL80211_FLAG_NEED_RTNL, |
| 13802 | }, |
| 13803 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 13804 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 13805 | .doit = nl80211_set_power_save, |
| 13806 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13807 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13808 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13809 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 13810 | }, |
| 13811 | { |
| 13812 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 13813 | .doit = nl80211_get_power_save, |
| 13814 | .policy = nl80211_policy, |
| 13815 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13816 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13817 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 13818 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13819 | { |
| 13820 | .cmd = NL80211_CMD_SET_CQM, |
| 13821 | .doit = nl80211_set_cqm, |
| 13822 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13823 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13824 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13825 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13826 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 13827 | { |
| 13828 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 13829 | .doit = nl80211_set_channel, |
| 13830 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13831 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13832 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13833 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 13834 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 13835 | { |
| 13836 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 13837 | .doit = nl80211_set_wds_peer, |
| 13838 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13839 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 13840 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13841 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 13842 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13843 | { |
| 13844 | .cmd = NL80211_CMD_JOIN_MESH, |
| 13845 | .doit = nl80211_join_mesh, |
| 13846 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13847 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13848 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13849 | NL80211_FLAG_NEED_RTNL, |
| 13850 | }, |
| 13851 | { |
| 13852 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 13853 | .doit = nl80211_leave_mesh, |
| 13854 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13855 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13856 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13857 | NL80211_FLAG_NEED_RTNL, |
| 13858 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 13859 | { |
| 13860 | .cmd = NL80211_CMD_JOIN_OCB, |
| 13861 | .doit = nl80211_join_ocb, |
| 13862 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13863 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 13864 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13865 | NL80211_FLAG_NEED_RTNL, |
| 13866 | }, |
| 13867 | { |
| 13868 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 13869 | .doit = nl80211_leave_ocb, |
| 13870 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13871 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 13872 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13873 | NL80211_FLAG_NEED_RTNL, |
| 13874 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 13875 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 13876 | { |
| 13877 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 13878 | .doit = nl80211_get_wowlan, |
| 13879 | .policy = nl80211_policy, |
| 13880 | /* can be retrieved by unprivileged users */ |
| 13881 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13882 | NL80211_FLAG_NEED_RTNL, |
| 13883 | }, |
| 13884 | { |
| 13885 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 13886 | .doit = nl80211_set_wowlan, |
| 13887 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13888 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 13889 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13890 | NL80211_FLAG_NEED_RTNL, |
| 13891 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 13892 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13893 | { |
| 13894 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 13895 | .doit = nl80211_set_rekey_data, |
| 13896 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13897 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13898 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13899 | NL80211_FLAG_NEED_RTNL | |
| 13900 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13901 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13902 | { |
| 13903 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 13904 | .doit = nl80211_tdls_mgmt, |
| 13905 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13906 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13907 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13908 | NL80211_FLAG_NEED_RTNL, |
| 13909 | }, |
| 13910 | { |
| 13911 | .cmd = NL80211_CMD_TDLS_OPER, |
| 13912 | .doit = nl80211_tdls_oper, |
| 13913 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13914 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13915 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13916 | NL80211_FLAG_NEED_RTNL, |
| 13917 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13918 | { |
| 13919 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 13920 | .doit = nl80211_register_unexpected_frame, |
| 13921 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13922 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13923 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13924 | NL80211_FLAG_NEED_RTNL, |
| 13925 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13926 | { |
| 13927 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 13928 | .doit = nl80211_probe_client, |
| 13929 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13930 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13931 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13932 | NL80211_FLAG_NEED_RTNL, |
| 13933 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13934 | { |
| 13935 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 13936 | .doit = nl80211_register_beacons, |
| 13937 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13938 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13939 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13940 | NL80211_FLAG_NEED_RTNL, |
| 13941 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 13942 | { |
| 13943 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 13944 | .doit = nl80211_set_noack_map, |
| 13945 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13946 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 13947 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13948 | NL80211_FLAG_NEED_RTNL, |
| 13949 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13950 | { |
| 13951 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 13952 | .doit = nl80211_start_p2p_device, |
| 13953 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13954 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13955 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13956 | NL80211_FLAG_NEED_RTNL, |
| 13957 | }, |
| 13958 | { |
| 13959 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 13960 | .doit = nl80211_stop_p2p_device, |
| 13961 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13962 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13963 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13964 | NL80211_FLAG_NEED_RTNL, |
| 13965 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13966 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13967 | .cmd = NL80211_CMD_START_NAN, |
| 13968 | .doit = nl80211_start_nan, |
| 13969 | .policy = nl80211_policy, |
| 13970 | .flags = GENL_ADMIN_PERM, |
| 13971 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13972 | NL80211_FLAG_NEED_RTNL, |
| 13973 | }, |
| 13974 | { |
| 13975 | .cmd = NL80211_CMD_STOP_NAN, |
| 13976 | .doit = nl80211_stop_nan, |
| 13977 | .policy = nl80211_policy, |
| 13978 | .flags = GENL_ADMIN_PERM, |
| 13979 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13980 | NL80211_FLAG_NEED_RTNL, |
| 13981 | }, |
| 13982 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13983 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
| 13984 | .doit = nl80211_nan_add_func, |
| 13985 | .policy = nl80211_policy, |
| 13986 | .flags = GENL_ADMIN_PERM, |
| 13987 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13988 | NL80211_FLAG_NEED_RTNL, |
| 13989 | }, |
| 13990 | { |
| 13991 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
| 13992 | .doit = nl80211_nan_del_func, |
| 13993 | .policy = nl80211_policy, |
| 13994 | .flags = GENL_ADMIN_PERM, |
| 13995 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13996 | NL80211_FLAG_NEED_RTNL, |
| 13997 | }, |
| 13998 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13999 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
| 14000 | .doit = nl80211_nan_change_config, |
| 14001 | .policy = nl80211_policy, |
| 14002 | .flags = GENL_ADMIN_PERM, |
| 14003 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14004 | NL80211_FLAG_NEED_RTNL, |
| 14005 | }, |
| 14006 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 14007 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 14008 | .doit = nl80211_set_mcast_rate, |
| 14009 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14010 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 14011 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14012 | NL80211_FLAG_NEED_RTNL, |
| 14013 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 14014 | { |
| 14015 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 14016 | .doit = nl80211_set_mac_acl, |
| 14017 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14018 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 14019 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14020 | NL80211_FLAG_NEED_RTNL, |
| 14021 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14022 | { |
| 14023 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 14024 | .doit = nl80211_start_radar_detection, |
| 14025 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14026 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14028 | NL80211_FLAG_NEED_RTNL, |
| 14029 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 14030 | { |
| 14031 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 14032 | .doit = nl80211_get_protocol_features, |
| 14033 | .policy = nl80211_policy, |
| 14034 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14035 | { |
| 14036 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 14037 | .doit = nl80211_update_ft_ies, |
| 14038 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14039 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14040 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14041 | NL80211_FLAG_NEED_RTNL, |
| 14042 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14043 | { |
| 14044 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 14045 | .doit = nl80211_crit_protocol_start, |
| 14046 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14047 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14048 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14049 | NL80211_FLAG_NEED_RTNL, |
| 14050 | }, |
| 14051 | { |
| 14052 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 14053 | .doit = nl80211_crit_protocol_stop, |
| 14054 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14055 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14056 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14057 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 14058 | }, |
| 14059 | { |
| 14060 | .cmd = NL80211_CMD_GET_COALESCE, |
| 14061 | .doit = nl80211_get_coalesce, |
| 14062 | .policy = nl80211_policy, |
| 14063 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14064 | NL80211_FLAG_NEED_RTNL, |
| 14065 | }, |
| 14066 | { |
| 14067 | .cmd = NL80211_CMD_SET_COALESCE, |
| 14068 | .doit = nl80211_set_coalesce, |
| 14069 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14070 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 14071 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14072 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 14073 | }, |
| 14074 | { |
| 14075 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 14076 | .doit = nl80211_channel_switch, |
| 14077 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14078 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 14079 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14080 | NL80211_FLAG_NEED_RTNL, |
| 14081 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14082 | { |
| 14083 | .cmd = NL80211_CMD_VENDOR, |
| 14084 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14085 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14086 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14087 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14088 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14089 | NL80211_FLAG_NEED_RTNL, |
| 14090 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 14091 | { |
| 14092 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 14093 | .doit = nl80211_set_qos_map, |
| 14094 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14095 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 14096 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14097 | NL80211_FLAG_NEED_RTNL, |
| 14098 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14099 | { |
| 14100 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 14101 | .doit = nl80211_add_tx_ts, |
| 14102 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14103 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14104 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14105 | NL80211_FLAG_NEED_RTNL, |
| 14106 | }, |
| 14107 | { |
| 14108 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 14109 | .doit = nl80211_del_tx_ts, |
| 14110 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14111 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14112 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14113 | NL80211_FLAG_NEED_RTNL, |
| 14114 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14115 | { |
| 14116 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 14117 | .doit = nl80211_tdls_channel_switch, |
| 14118 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14119 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14120 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14121 | NL80211_FLAG_NEED_RTNL, |
| 14122 | }, |
| 14123 | { |
| 14124 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 14125 | .doit = nl80211_tdls_cancel_channel_switch, |
| 14126 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14127 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14128 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14129 | NL80211_FLAG_NEED_RTNL, |
| 14130 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 14131 | { |
| 14132 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
| 14133 | .doit = nl80211_set_multicast_to_unicast, |
| 14134 | .policy = nl80211_policy, |
| 14135 | .flags = GENL_UNS_ADMIN_PERM, |
| 14136 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14137 | NL80211_FLAG_NEED_RTNL, |
| 14138 | }, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14139 | { |
| 14140 | .cmd = NL80211_CMD_SET_PMK, |
| 14141 | .doit = nl80211_set_pmk, |
| 14142 | .policy = nl80211_policy, |
| 14143 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14144 | NL80211_FLAG_NEED_RTNL, |
| 14145 | }, |
| 14146 | { |
| 14147 | .cmd = NL80211_CMD_DEL_PMK, |
| 14148 | .doit = nl80211_del_pmk, |
| 14149 | .policy = nl80211_policy, |
| 14150 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14151 | NL80211_FLAG_NEED_RTNL, |
| 14152 | }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14153 | { |
| 14154 | .cmd = NL80211_CMD_EXTERNAL_AUTH, |
| 14155 | .doit = nl80211_external_auth, |
| 14156 | .policy = nl80211_policy, |
| 14157 | .flags = GENL_ADMIN_PERM, |
| 14158 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14159 | NL80211_FLAG_NEED_RTNL, |
| 14160 | }, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14161 | { |
| 14162 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, |
| 14163 | .doit = nl80211_tx_control_port, |
| 14164 | .policy = nl80211_policy, |
| 14165 | .flags = GENL_UNS_ADMIN_PERM, |
| 14166 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14167 | NL80211_FLAG_NEED_RTNL, |
| 14168 | }, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 14169 | { |
| 14170 | .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, |
| 14171 | .doit = nl80211_get_ftm_responder_stats, |
| 14172 | .policy = nl80211_policy, |
| 14173 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14174 | NL80211_FLAG_NEED_RTNL, |
| 14175 | }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 14176 | { |
| 14177 | .cmd = NL80211_CMD_PEER_MEASUREMENT_START, |
| 14178 | .doit = nl80211_pmsr_start, |
| 14179 | .policy = nl80211_policy, |
| 14180 | .flags = GENL_UNS_ADMIN_PERM, |
| 14181 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14182 | NL80211_FLAG_NEED_RTNL, |
| 14183 | }, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 14184 | { |
| 14185 | .cmd = NL80211_CMD_NOTIFY_RADAR, |
| 14186 | .doit = nl80211_notify_radar_detection, |
| 14187 | .policy = nl80211_policy, |
| 14188 | .flags = GENL_UNS_ADMIN_PERM, |
| 14189 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14190 | NL80211_FLAG_NEED_RTNL, |
| 14191 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14192 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14193 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 14194 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 14195 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 14196 | .hdrsize = 0, /* no private header */ |
| 14197 | .version = 1, /* no particular meaning now */ |
| 14198 | .maxattr = NL80211_ATTR_MAX, |
| 14199 | .netnsok = true, |
| 14200 | .pre_doit = nl80211_pre_doit, |
| 14201 | .post_doit = nl80211_post_doit, |
| 14202 | .module = THIS_MODULE, |
| 14203 | .ops = nl80211_ops, |
| 14204 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| 14205 | .mcgrps = nl80211_mcgrps, |
| 14206 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
| 14207 | }; |
| 14208 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14209 | /* notification functions */ |
| 14210 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 14211 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 14212 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14213 | { |
| 14214 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 14215 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14216 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 14217 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 14218 | cmd != NL80211_CMD_DEL_WIPHY); |
| 14219 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 14220 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14221 | if (!msg) |
| 14222 | return; |
| 14223 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 14224 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14225 | nlmsg_free(msg); |
| 14226 | return; |
| 14227 | } |
| 14228 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14229 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14230 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14231 | } |
| 14232 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 14233 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 14234 | struct wireless_dev *wdev, |
| 14235 | enum nl80211_commands cmd) |
| 14236 | { |
| 14237 | struct sk_buff *msg; |
| 14238 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 14239 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14240 | if (!msg) |
| 14241 | return; |
| 14242 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 14243 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 14244 | nlmsg_free(msg); |
| 14245 | return; |
| 14246 | } |
| 14247 | |
| 14248 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 14249 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 14250 | } |
| 14251 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 14252 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 14253 | struct cfg80211_registered_device *rdev) |
| 14254 | { |
| 14255 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 14256 | struct nlattr *nest; |
| 14257 | int i; |
| 14258 | |
| 14259 | if (WARN_ON(!req)) |
| 14260 | return 0; |
| 14261 | |
| 14262 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 14263 | if (!nest) |
| 14264 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14265 | for (i = 0; i < req->n_ssids; i++) { |
| 14266 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 14267 | goto nla_put_failure; |
| 14268 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 14269 | nla_nest_end(msg, nest); |
| 14270 | |
| 14271 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 14272 | if (!nest) |
| 14273 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14274 | for (i = 0; i < req->n_channels; i++) { |
| 14275 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 14276 | goto nla_put_failure; |
| 14277 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 14278 | nla_nest_end(msg, nest); |
| 14279 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14280 | if (req->ie && |
| 14281 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 14282 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 14283 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14284 | if (req->flags && |
| 14285 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 14286 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 14287 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 14288 | if (req->info.scan_start_tsf && |
| 14289 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 14290 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 14291 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 14292 | req->info.tsf_bssid))) |
| 14293 | goto nla_put_failure; |
| 14294 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 14295 | return 0; |
| 14296 | nla_put_failure: |
| 14297 | return -ENOBUFS; |
| 14298 | } |
| 14299 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 14300 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14301 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 14302 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14303 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14304 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14305 | { |
| 14306 | void *hdr; |
| 14307 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14308 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14309 | if (!hdr) |
| 14310 | return -1; |
| 14311 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14312 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 14313 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14314 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14315 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14316 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14317 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14318 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 14319 | /* ignore errors and send incomplete event anyway */ |
| 14320 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14321 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 14322 | genlmsg_end(msg, hdr); |
| 14323 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14324 | |
| 14325 | nla_put_failure: |
| 14326 | genlmsg_cancel(msg, hdr); |
| 14327 | return -EMSGSIZE; |
| 14328 | } |
| 14329 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14330 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 14331 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14332 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14333 | { |
| 14334 | void *hdr; |
| 14335 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14336 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14337 | if (!hdr) |
| 14338 | return -1; |
| 14339 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14340 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 14341 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 14342 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 14343 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 14344 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14345 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14346 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 14347 | genlmsg_end(msg, hdr); |
| 14348 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14349 | |
| 14350 | nla_put_failure: |
| 14351 | genlmsg_cancel(msg, hdr); |
| 14352 | return -EMSGSIZE; |
| 14353 | } |
| 14354 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14355 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 14356 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14357 | { |
| 14358 | struct sk_buff *msg; |
| 14359 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14360 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14361 | if (!msg) |
| 14362 | return; |
| 14363 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 14364 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14365 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 14366 | nlmsg_free(msg); |
| 14367 | return; |
| 14368 | } |
| 14369 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14370 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14371 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14372 | } |
| 14373 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 14374 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 14375 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14376 | { |
| 14377 | struct sk_buff *msg; |
| 14378 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 14379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14380 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 14381 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14382 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 14383 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 14384 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 14385 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14386 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 14387 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14388 | } |
| 14389 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 14390 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14391 | } |
| 14392 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 14393 | /* send message created by nl80211_build_scan_msg() */ |
| 14394 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 14395 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14396 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14397 | if (!msg) |
| 14398 | return; |
| 14399 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14400 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14401 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14402 | } |
| 14403 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14404 | 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] | 14405 | { |
| 14406 | struct sk_buff *msg; |
| 14407 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14408 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14409 | if (!msg) |
| 14410 | return; |
| 14411 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14412 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14413 | nlmsg_free(msg); |
| 14414 | return; |
| 14415 | } |
| 14416 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14417 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14418 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14419 | } |
| 14420 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 14421 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 14422 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14423 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14424 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14425 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 14426 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14427 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14428 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 14429 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 14430 | NL80211_REGDOM_TYPE_WORLD)) |
| 14431 | goto nla_put_failure; |
| 14432 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 14433 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 14434 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 14435 | goto nla_put_failure; |
| 14436 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 14437 | request->intersect) { |
| 14438 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 14439 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 14440 | goto nla_put_failure; |
| 14441 | } else { |
| 14442 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 14443 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 14444 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 14445 | request->alpha2)) |
| 14446 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14447 | } |
| 14448 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 14449 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 14450 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 14451 | |
| 14452 | if (wiphy && |
| 14453 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 14454 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 14455 | |
| 14456 | if (wiphy && |
| 14457 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 14458 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 14459 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 14460 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14461 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 14462 | return true; |
| 14463 | |
| 14464 | nla_put_failure: |
| 14465 | return false; |
| 14466 | } |
| 14467 | |
| 14468 | /* |
| 14469 | * This can happen on global regulatory changes or device specific settings |
| 14470 | * based on custom regulatory domains. |
| 14471 | */ |
| 14472 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 14473 | struct regulatory_request *request) |
| 14474 | { |
| 14475 | struct sk_buff *msg; |
| 14476 | void *hdr; |
| 14477 | |
| 14478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14479 | if (!msg) |
| 14480 | return; |
| 14481 | |
| 14482 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 14483 | if (!hdr) { |
| 14484 | nlmsg_free(msg); |
| 14485 | return; |
| 14486 | } |
| 14487 | |
| 14488 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 14489 | goto nla_put_failure; |
| 14490 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14491 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14492 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 14493 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14494 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14495 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 14496 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14497 | |
| 14498 | return; |
| 14499 | |
| 14500 | nla_put_failure: |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14501 | nlmsg_free(msg); |
| 14502 | } |
| 14503 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14504 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 14505 | struct net_device *netdev, |
| 14506 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14507 | enum nl80211_commands cmd, gfp_t gfp, |
| 14508 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14509 | { |
| 14510 | struct sk_buff *msg; |
| 14511 | void *hdr; |
| 14512 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14513 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14514 | if (!msg) |
| 14515 | return; |
| 14516 | |
| 14517 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 14518 | if (!hdr) { |
| 14519 | nlmsg_free(msg); |
| 14520 | return; |
| 14521 | } |
| 14522 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14523 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14524 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14525 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 14526 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14527 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14528 | if (uapsd_queues >= 0) { |
| 14529 | struct nlattr *nla_wmm = |
| 14530 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 14531 | if (!nla_wmm) |
| 14532 | goto nla_put_failure; |
| 14533 | |
| 14534 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 14535 | uapsd_queues)) |
| 14536 | goto nla_put_failure; |
| 14537 | |
| 14538 | nla_nest_end(msg, nla_wmm); |
| 14539 | } |
| 14540 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14541 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14542 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14543 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14544 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14545 | return; |
| 14546 | |
| 14547 | nla_put_failure: |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14548 | nlmsg_free(msg); |
| 14549 | } |
| 14550 | |
| 14551 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14552 | struct net_device *netdev, const u8 *buf, |
| 14553 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14554 | { |
| 14555 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14556 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14557 | } |
| 14558 | |
| 14559 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 14560 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14561 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14562 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14563 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14564 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14565 | } |
| 14566 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 14567 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14568 | struct net_device *netdev, const u8 *buf, |
| 14569 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14570 | { |
| 14571 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14572 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14573 | } |
| 14574 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 14575 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 14576 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14577 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14578 | { |
| 14579 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14580 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14581 | } |
| 14582 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 14583 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 14584 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 14585 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14586 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14587 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14588 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 14589 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 14590 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 14591 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 14592 | if (WARN_ON(len < 2)) |
| 14593 | return; |
| 14594 | |
| 14595 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 14596 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 14597 | else |
| 14598 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 14599 | |
| 14600 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14601 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 14602 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 14603 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 14604 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 14605 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 14606 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14607 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14608 | { |
| 14609 | struct sk_buff *msg; |
| 14610 | void *hdr; |
| 14611 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14612 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14613 | if (!msg) |
| 14614 | return; |
| 14615 | |
| 14616 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 14617 | if (!hdr) { |
| 14618 | nlmsg_free(msg); |
| 14619 | return; |
| 14620 | } |
| 14621 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14622 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14623 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14624 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 14625 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 14626 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14627 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14628 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14629 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14630 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14631 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14632 | return; |
| 14633 | |
| 14634 | nla_put_failure: |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14635 | nlmsg_free(msg); |
| 14636 | } |
| 14637 | |
| 14638 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14639 | struct net_device *netdev, const u8 *addr, |
| 14640 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14641 | { |
| 14642 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14643 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14644 | } |
| 14645 | |
| 14646 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14647 | struct net_device *netdev, const u8 *addr, |
| 14648 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14649 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14650 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 14651 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14652 | } |
| 14653 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14654 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 14655 | struct net_device *netdev, |
| 14656 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 14657 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14658 | { |
| 14659 | struct sk_buff *msg; |
| 14660 | void *hdr; |
| 14661 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 14662 | 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] | 14663 | cr->fils.kek_len + cr->fils.pmk_len + |
| 14664 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14665 | if (!msg) |
| 14666 | return; |
| 14667 | |
| 14668 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 14669 | if (!hdr) { |
| 14670 | nlmsg_free(msg); |
| 14671 | return; |
| 14672 | } |
| 14673 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14674 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14675 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 14676 | (cr->bssid && |
| 14677 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 14678 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 14679 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 14680 | cr->status) || |
| 14681 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 14682 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 14683 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 14684 | cr->timeout_reason))) || |
| 14685 | (cr->req_ie && |
| 14686 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 14687 | (cr->resp_ie && |
| 14688 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 14689 | cr->resp_ie)) || |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 14690 | (cr->fils.update_erp_next_seq_num && |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 14691 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 14692 | cr->fils.erp_next_seq_num)) || |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 14693 | (cr->status == WLAN_STATUS_SUCCESS && |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 14694 | ((cr->fils.kek && |
| 14695 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, |
| 14696 | cr->fils.kek)) || |
| 14697 | (cr->fils.pmk && |
| 14698 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || |
| 14699 | (cr->fils.pmkid && |
| 14700 | 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] | 14701 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14702 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14703 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14704 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14705 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14706 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14707 | return; |
| 14708 | |
| 14709 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14710 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14711 | } |
| 14712 | |
| 14713 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 14714 | struct net_device *netdev, |
| 14715 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14716 | { |
| 14717 | struct sk_buff *msg; |
| 14718 | void *hdr; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 14719 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14720 | |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 14721 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + |
| 14722 | info->fils.kek_len + info->fils.pmk_len + |
| 14723 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14724 | if (!msg) |
| 14725 | return; |
| 14726 | |
| 14727 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 14728 | if (!hdr) { |
| 14729 | nlmsg_free(msg); |
| 14730 | return; |
| 14731 | } |
| 14732 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14733 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14734 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14735 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 14736 | (info->req_ie && |
| 14737 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 14738 | info->req_ie)) || |
| 14739 | (info->resp_ie && |
| 14740 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 14741 | info->resp_ie)) || |
| 14742 | (info->fils.update_erp_next_seq_num && |
| 14743 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 14744 | info->fils.erp_next_seq_num)) || |
| 14745 | (info->fils.kek && |
| 14746 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, |
| 14747 | info->fils.kek)) || |
| 14748 | (info->fils.pmk && |
| 14749 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || |
| 14750 | (info->fils.pmkid && |
| 14751 | 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] | 14752 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14753 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14754 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14755 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14756 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14757 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14758 | return; |
| 14759 | |
| 14760 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14761 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14762 | } |
| 14763 | |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 14764 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, |
| 14765 | struct net_device *netdev, const u8 *bssid) |
| 14766 | { |
| 14767 | struct sk_buff *msg; |
| 14768 | void *hdr; |
| 14769 | |
| 14770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14771 | if (!msg) |
| 14772 | return; |
| 14773 | |
| 14774 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); |
| 14775 | if (!hdr) { |
| 14776 | nlmsg_free(msg); |
| 14777 | return; |
| 14778 | } |
| 14779 | |
| 14780 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 14781 | goto nla_put_failure; |
| 14782 | |
| 14783 | genlmsg_end(msg, hdr); |
| 14784 | |
| 14785 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 14786 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 14787 | return; |
| 14788 | |
| 14789 | nla_put_failure: |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 14790 | nlmsg_free(msg); |
| 14791 | } |
| 14792 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14793 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 14794 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 14795 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14796 | { |
| 14797 | struct sk_buff *msg; |
| 14798 | void *hdr; |
| 14799 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14800 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14801 | if (!msg) |
| 14802 | return; |
| 14803 | |
| 14804 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 14805 | if (!hdr) { |
| 14806 | nlmsg_free(msg); |
| 14807 | return; |
| 14808 | } |
| 14809 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14810 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14811 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
David Spinadel | 86b6c46 | 2017-12-18 12:14:05 +0200 | [diff] [blame] | 14812 | (reason && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14813 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 14814 | (from_ap && |
| 14815 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 14816 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 14817 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14818 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14819 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14820 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14821 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14822 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14823 | return; |
| 14824 | |
| 14825 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14826 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14827 | } |
| 14828 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14829 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 14830 | struct net_device *netdev, const u8 *bssid, |
| 14831 | gfp_t gfp) |
| 14832 | { |
| 14833 | struct sk_buff *msg; |
| 14834 | void *hdr; |
| 14835 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 14836 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14837 | if (!msg) |
| 14838 | return; |
| 14839 | |
| 14840 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 14841 | if (!hdr) { |
| 14842 | nlmsg_free(msg); |
| 14843 | return; |
| 14844 | } |
| 14845 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14846 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14847 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14848 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 14849 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14850 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14851 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14852 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14853 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14854 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14855 | return; |
| 14856 | |
| 14857 | nla_put_failure: |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14858 | nlmsg_free(msg); |
| 14859 | } |
| 14860 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14861 | 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] | 14862 | const u8 *ie, u8 ie_len, |
| 14863 | int sig_dbm, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14864 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14865 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14866 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14867 | struct sk_buff *msg; |
| 14868 | void *hdr; |
| 14869 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14870 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 14871 | return; |
| 14872 | |
| 14873 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 14874 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14875 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14876 | if (!msg) |
| 14877 | return; |
| 14878 | |
| 14879 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 14880 | if (!hdr) { |
| 14881 | nlmsg_free(msg); |
| 14882 | return; |
| 14883 | } |
| 14884 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14885 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14886 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14887 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14888 | (ie_len && ie && |
Bob Copeland | ecbc12a | 2018-10-26 10:03:50 -0400 | [diff] [blame] | 14889 | nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || |
| 14890 | (sig_dbm && |
| 14891 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14892 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14893 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14894 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14895 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14896 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14897 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14898 | return; |
| 14899 | |
| 14900 | nla_put_failure: |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14901 | nlmsg_free(msg); |
| 14902 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14903 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14904 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14905 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 14906 | struct net_device *netdev, const u8 *addr, |
| 14907 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14908 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14909 | { |
| 14910 | struct sk_buff *msg; |
| 14911 | void *hdr; |
| 14912 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14913 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14914 | if (!msg) |
| 14915 | return; |
| 14916 | |
| 14917 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 14918 | if (!hdr) { |
| 14919 | nlmsg_free(msg); |
| 14920 | return; |
| 14921 | } |
| 14922 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14923 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14924 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14925 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 14926 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 14927 | (key_id != -1 && |
| 14928 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 14929 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 14930 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14931 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14932 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14933 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14934 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14935 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14936 | return; |
| 14937 | |
| 14938 | nla_put_failure: |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14939 | nlmsg_free(msg); |
| 14940 | } |
| 14941 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14942 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 14943 | struct ieee80211_channel *channel_before, |
| 14944 | struct ieee80211_channel *channel_after) |
| 14945 | { |
| 14946 | struct sk_buff *msg; |
| 14947 | void *hdr; |
| 14948 | struct nlattr *nl_freq; |
| 14949 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 14950 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14951 | if (!msg) |
| 14952 | return; |
| 14953 | |
| 14954 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 14955 | if (!hdr) { |
| 14956 | nlmsg_free(msg); |
| 14957 | return; |
| 14958 | } |
| 14959 | |
| 14960 | /* |
| 14961 | * Since we are applying the beacon hint to a wiphy we know its |
| 14962 | * wiphy_idx is valid |
| 14963 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14964 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 14965 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14966 | |
| 14967 | /* Before */ |
| 14968 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 14969 | if (!nl_freq) |
| 14970 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 14971 | |
| 14972 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14973 | goto nla_put_failure; |
| 14974 | nla_nest_end(msg, nl_freq); |
| 14975 | |
| 14976 | /* After */ |
| 14977 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 14978 | if (!nl_freq) |
| 14979 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 14980 | |
| 14981 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14982 | goto nla_put_failure; |
| 14983 | nla_nest_end(msg, nl_freq); |
| 14984 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14985 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14986 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14987 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14988 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14989 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14990 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14991 | |
| 14992 | return; |
| 14993 | |
| 14994 | nla_put_failure: |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14995 | nlmsg_free(msg); |
| 14996 | } |
| 14997 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14998 | static void nl80211_send_remain_on_chan_event( |
| 14999 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15000 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15001 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15002 | unsigned int duration, gfp_t gfp) |
| 15003 | { |
| 15004 | struct sk_buff *msg; |
| 15005 | void *hdr; |
| 15006 | |
| 15007 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15008 | if (!msg) |
| 15009 | return; |
| 15010 | |
| 15011 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15012 | if (!hdr) { |
| 15013 | nlmsg_free(msg); |
| 15014 | return; |
| 15015 | } |
| 15016 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15017 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15018 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15019 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15020 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15021 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15022 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 15023 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 15024 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15025 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 15026 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15027 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15028 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15029 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 15030 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 15031 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15032 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15033 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15034 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15035 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15036 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15037 | return; |
| 15038 | |
| 15039 | nla_put_failure: |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15040 | nlmsg_free(msg); |
| 15041 | } |
| 15042 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15043 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 15044 | struct ieee80211_channel *chan, |
| 15045 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15046 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15047 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15048 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15049 | |
| 15050 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15051 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15052 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 15053 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15054 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15055 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15056 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15057 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 15058 | struct ieee80211_channel *chan, |
| 15059 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15060 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15061 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15062 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15063 | |
| 15064 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15065 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 15066 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15067 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15068 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15069 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15070 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 15071 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15072 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15073 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15074 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15075 | struct sk_buff *msg; |
| 15076 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15077 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 15078 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15079 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15080 | if (!msg) |
| 15081 | return; |
| 15082 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 15083 | 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] | 15084 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15085 | nlmsg_free(msg); |
| 15086 | return; |
| 15087 | } |
| 15088 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15089 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15090 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15091 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15092 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 15093 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 15094 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 15095 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15096 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15097 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15098 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15099 | struct sk_buff *msg; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 15100 | struct station_info empty_sinfo = {}; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 15101 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 15102 | if (!sinfo) |
| 15103 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15104 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15105 | trace_cfg80211_del_sta(dev, mac_addr); |
| 15106 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15107 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 15108 | if (!msg) { |
| 15109 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 15110 | return; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 15111 | } |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15112 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 15113 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 15114 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15115 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 15116 | return; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15117 | } |
| 15118 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15119 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15120 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15121 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 15122 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 15123 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15124 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 15125 | enum nl80211_connect_failed_reason reason, |
| 15126 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 15127 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15128 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15129 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 15130 | struct sk_buff *msg; |
| 15131 | void *hdr; |
| 15132 | |
| 15133 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 15134 | if (!msg) |
| 15135 | return; |
| 15136 | |
| 15137 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 15138 | if (!hdr) { |
| 15139 | nlmsg_free(msg); |
| 15140 | return; |
| 15141 | } |
| 15142 | |
| 15143 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15144 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 15145 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 15146 | goto nla_put_failure; |
| 15147 | |
| 15148 | genlmsg_end(msg, hdr); |
| 15149 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15150 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15151 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 15152 | return; |
| 15153 | |
| 15154 | nla_put_failure: |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 15155 | nlmsg_free(msg); |
| 15156 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15157 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 15158 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 15159 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 15160 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15161 | { |
| 15162 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15163 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15164 | struct sk_buff *msg; |
| 15165 | void *hdr; |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 15166 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15167 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15168 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15169 | return false; |
| 15170 | |
| 15171 | msg = nlmsg_new(100, gfp); |
| 15172 | if (!msg) |
| 15173 | return true; |
| 15174 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 15175 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15176 | if (!hdr) { |
| 15177 | nlmsg_free(msg); |
| 15178 | return true; |
| 15179 | } |
| 15180 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15181 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15182 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15183 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 15184 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15185 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15186 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15187 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15188 | return true; |
| 15189 | |
| 15190 | nla_put_failure: |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15191 | nlmsg_free(msg); |
| 15192 | return true; |
| 15193 | } |
| 15194 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15195 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 15196 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 15197 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15198 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15199 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 15200 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15201 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 15202 | |
| 15203 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 15204 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 15205 | trace_cfg80211_return_bool(false); |
| 15206 | return false; |
| 15207 | } |
| 15208 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 15209 | addr, gfp); |
| 15210 | trace_cfg80211_return_bool(ret); |
| 15211 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 15212 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15213 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 15214 | |
| 15215 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 15216 | const u8 *addr, gfp_t gfp) |
| 15217 | { |
| 15218 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15219 | bool ret; |
| 15220 | |
| 15221 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 15222 | |
| 15223 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 15224 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 15225 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 15226 | trace_cfg80211_return_bool(false); |
| 15227 | return false; |
| 15228 | } |
| 15229 | ret = __nl80211_unexpected_frame(dev, |
| 15230 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 15231 | addr, gfp); |
| 15232 | trace_cfg80211_return_bool(ret); |
| 15233 | return ret; |
| 15234 | } |
| 15235 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 15236 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15237 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15238 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 15239 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 15240 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15241 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15242 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15243 | struct sk_buff *msg; |
| 15244 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15245 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 15246 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15247 | if (!msg) |
| 15248 | return -ENOMEM; |
| 15249 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15250 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15251 | if (!hdr) { |
| 15252 | nlmsg_free(msg); |
| 15253 | return -ENOMEM; |
| 15254 | } |
| 15255 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15256 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15257 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15258 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15259 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15260 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15261 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 15262 | (sig_dbm && |
| 15263 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 15264 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 15265 | (flags && |
| 15266 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15267 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15268 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15269 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15270 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15271 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15272 | |
| 15273 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15274 | nlmsg_free(msg); |
| 15275 | return -ENOBUFS; |
| 15276 | } |
| 15277 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15278 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 15279 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15280 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15281 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15282 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15283 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15284 | struct sk_buff *msg; |
| 15285 | void *hdr; |
| 15286 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15287 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 15288 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 15289 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15290 | if (!msg) |
| 15291 | return; |
| 15292 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15293 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15294 | if (!hdr) { |
| 15295 | nlmsg_free(msg); |
| 15296 | return; |
| 15297 | } |
| 15298 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15299 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15300 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15301 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15302 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15303 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15304 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15305 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 15306 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15307 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 15308 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15309 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15310 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15311 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15312 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15313 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15314 | return; |
| 15315 | |
| 15316 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15317 | nlmsg_free(msg); |
| 15318 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15319 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15320 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 15321 | static int __nl80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 15322 | struct sk_buff *skb, |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 15323 | bool unencrypted, gfp_t gfp) |
| 15324 | { |
| 15325 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15326 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 15327 | struct ethhdr *ehdr = eth_hdr(skb); |
| 15328 | const u8 *addr = ehdr->h_source; |
| 15329 | u16 proto = be16_to_cpu(skb->protocol); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 15330 | struct sk_buff *msg; |
| 15331 | void *hdr; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 15332 | struct nlattr *frame; |
| 15333 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 15334 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); |
| 15335 | |
| 15336 | if (!nlportid) |
| 15337 | return -ENOENT; |
| 15338 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 15339 | msg = nlmsg_new(100 + skb->len, gfp); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 15340 | if (!msg) |
| 15341 | return -ENOMEM; |
| 15342 | |
| 15343 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 15344 | if (!hdr) { |
| 15345 | nlmsg_free(msg); |
| 15346 | return -ENOBUFS; |
| 15347 | } |
| 15348 | |
| 15349 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15350 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15351 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15352 | NL80211_ATTR_PAD) || |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 15353 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 15354 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 15355 | (unencrypted && nla_put_flag(msg, |
| 15356 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 15357 | goto nla_put_failure; |
| 15358 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 15359 | frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); |
| 15360 | if (!frame) |
| 15361 | goto nla_put_failure; |
| 15362 | |
| 15363 | skb_copy_bits(skb, 0, nla_data(frame), skb->len); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 15364 | genlmsg_end(msg, hdr); |
| 15365 | |
| 15366 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 15367 | |
| 15368 | nla_put_failure: |
| 15369 | nlmsg_free(msg); |
| 15370 | return -ENOBUFS; |
| 15371 | } |
| 15372 | |
| 15373 | bool cfg80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 15374 | struct sk_buff *skb, bool unencrypted) |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 15375 | { |
| 15376 | int ret; |
| 15377 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 15378 | trace_cfg80211_rx_control_port(dev, skb, unencrypted); |
| 15379 | ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 15380 | trace_cfg80211_return_bool(ret == 0); |
| 15381 | return ret == 0; |
| 15382 | } |
| 15383 | EXPORT_SYMBOL(cfg80211_rx_control_port); |
| 15384 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15385 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 15386 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15387 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15388 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15389 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 15390 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15391 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15392 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15393 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15394 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15395 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15396 | cb = (void **)msg->cb; |
| 15397 | |
| 15398 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 15399 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15400 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15401 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15402 | } |
| 15403 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15404 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15405 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15406 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15407 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15408 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15409 | goto nla_put_failure; |
| 15410 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15411 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 15412 | if (!cb[1]) |
| 15413 | goto nla_put_failure; |
| 15414 | |
| 15415 | cb[2] = rdev; |
| 15416 | |
| 15417 | return msg; |
| 15418 | nla_put_failure: |
| 15419 | nlmsg_free(msg); |
| 15420 | return NULL; |
| 15421 | } |
| 15422 | |
| 15423 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 15424 | { |
| 15425 | void **cb = (void **)msg->cb; |
| 15426 | struct cfg80211_registered_device *rdev = cb[2]; |
| 15427 | |
| 15428 | nla_nest_end(msg, cb[1]); |
| 15429 | genlmsg_end(msg, cb[0]); |
| 15430 | |
| 15431 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 15432 | |
| 15433 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15434 | NL80211_MCGRP_MLME, gfp); |
| 15435 | } |
| 15436 | |
| 15437 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 15438 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 15439 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15440 | { |
| 15441 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 15442 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15443 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15444 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 15445 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15446 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 15447 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 15448 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 15449 | return; |
| 15450 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 15451 | if (wdev->cqm_config) { |
| 15452 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 15453 | |
| 15454 | cfg80211_cqm_rssi_update(rdev, dev); |
| 15455 | |
| 15456 | if (rssi_level == 0) |
| 15457 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 15458 | } |
| 15459 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15460 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 15461 | if (!msg) |
| 15462 | return; |
| 15463 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15464 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 15465 | rssi_event)) |
| 15466 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15467 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 15468 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 15469 | rssi_level)) |
| 15470 | goto nla_put_failure; |
| 15471 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15472 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15473 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15474 | return; |
| 15475 | |
| 15476 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15477 | nlmsg_free(msg); |
| 15478 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15479 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15480 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15481 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 15482 | const u8 *peer, u32 num_packets, |
| 15483 | u32 rate, u32 intvl, gfp_t gfp) |
| 15484 | { |
| 15485 | struct sk_buff *msg; |
| 15486 | |
| 15487 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 15488 | if (!msg) |
| 15489 | return; |
| 15490 | |
| 15491 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 15492 | goto nla_put_failure; |
| 15493 | |
| 15494 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 15495 | goto nla_put_failure; |
| 15496 | |
| 15497 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 15498 | goto nla_put_failure; |
| 15499 | |
| 15500 | cfg80211_send_cqm(msg, gfp); |
| 15501 | return; |
| 15502 | |
| 15503 | nla_put_failure: |
| 15504 | nlmsg_free(msg); |
| 15505 | } |
| 15506 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 15507 | |
| 15508 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 15509 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 15510 | { |
| 15511 | struct sk_buff *msg; |
| 15512 | |
| 15513 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 15514 | |
| 15515 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 15516 | if (!msg) |
| 15517 | return; |
| 15518 | |
| 15519 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 15520 | goto nla_put_failure; |
| 15521 | |
| 15522 | cfg80211_send_cqm(msg, gfp); |
| 15523 | return; |
| 15524 | |
| 15525 | nla_put_failure: |
| 15526 | nlmsg_free(msg); |
| 15527 | } |
| 15528 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 15529 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 15530 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 15531 | { |
| 15532 | struct sk_buff *msg; |
| 15533 | |
| 15534 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 15535 | if (!msg) |
| 15536 | return; |
| 15537 | |
| 15538 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 15539 | goto nla_put_failure; |
| 15540 | |
| 15541 | cfg80211_send_cqm(msg, gfp); |
| 15542 | return; |
| 15543 | |
| 15544 | nla_put_failure: |
| 15545 | nlmsg_free(msg); |
| 15546 | } |
| 15547 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 15548 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15549 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 15550 | struct net_device *netdev, const u8 *bssid, |
| 15551 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15552 | { |
| 15553 | struct sk_buff *msg; |
| 15554 | struct nlattr *rekey_attr; |
| 15555 | void *hdr; |
| 15556 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15557 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15558 | if (!msg) |
| 15559 | return; |
| 15560 | |
| 15561 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 15562 | if (!hdr) { |
| 15563 | nlmsg_free(msg); |
| 15564 | return; |
| 15565 | } |
| 15566 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15567 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15568 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15569 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 15570 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15571 | |
| 15572 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 15573 | if (!rekey_attr) |
| 15574 | goto nla_put_failure; |
| 15575 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15576 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 15577 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 15578 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15579 | |
| 15580 | nla_nest_end(msg, rekey_attr); |
| 15581 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15582 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15583 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15584 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15585 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15586 | return; |
| 15587 | |
| 15588 | nla_put_failure: |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15589 | nlmsg_free(msg); |
| 15590 | } |
| 15591 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15592 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 15593 | const u8 *replay_ctr, gfp_t gfp) |
| 15594 | { |
| 15595 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15596 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15597 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15598 | |
| 15599 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 15600 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 15601 | } |
| 15602 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 15603 | |
| 15604 | static void |
| 15605 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 15606 | struct net_device *netdev, int index, |
| 15607 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15608 | { |
| 15609 | struct sk_buff *msg; |
| 15610 | struct nlattr *attr; |
| 15611 | void *hdr; |
| 15612 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15613 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15614 | if (!msg) |
| 15615 | return; |
| 15616 | |
| 15617 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 15618 | if (!hdr) { |
| 15619 | nlmsg_free(msg); |
| 15620 | return; |
| 15621 | } |
| 15622 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15623 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15624 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 15625 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15626 | |
| 15627 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 15628 | if (!attr) |
| 15629 | goto nla_put_failure; |
| 15630 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15631 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 15632 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 15633 | (preauth && |
| 15634 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 15635 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15636 | |
| 15637 | nla_nest_end(msg, attr); |
| 15638 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15639 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15640 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15641 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15642 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15643 | return; |
| 15644 | |
| 15645 | nla_put_failure: |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15646 | nlmsg_free(msg); |
| 15647 | } |
| 15648 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15649 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 15650 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 15651 | { |
| 15652 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15653 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15654 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15655 | |
| 15656 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 15657 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 15658 | } |
| 15659 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 15660 | |
| 15661 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 15662 | struct net_device *netdev, |
| 15663 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 15664 | gfp_t gfp, |
| 15665 | enum nl80211_commands notif, |
| 15666 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15667 | { |
| 15668 | struct sk_buff *msg; |
| 15669 | void *hdr; |
| 15670 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15671 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15672 | if (!msg) |
| 15673 | return; |
| 15674 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 15675 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15676 | if (!hdr) { |
| 15677 | nlmsg_free(msg); |
| 15678 | return; |
| 15679 | } |
| 15680 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 15681 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 15682 | goto nla_put_failure; |
| 15683 | |
| 15684 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 15685 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15686 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 15687 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 15688 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 15689 | goto nla_put_failure; |
| 15690 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15691 | genlmsg_end(msg, hdr); |
| 15692 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15693 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15694 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15695 | return; |
| 15696 | |
| 15697 | nla_put_failure: |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15698 | nlmsg_free(msg); |
| 15699 | } |
| 15700 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15701 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 15702 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 15703 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15704 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15705 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15706 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15707 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 15708 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15709 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 15710 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15711 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 15712 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 15713 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 15714 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 15715 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15716 | } |
| 15717 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 15718 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 15719 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 15720 | struct cfg80211_chan_def *chandef, |
| 15721 | u8 count) |
| 15722 | { |
| 15723 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15724 | struct wiphy *wiphy = wdev->wiphy; |
| 15725 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 15726 | |
| 15727 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 15728 | |
| 15729 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 15730 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 15731 | } |
| 15732 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 15733 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 15734 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15735 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 15736 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15737 | enum nl80211_radar_event event, |
| 15738 | struct net_device *netdev, gfp_t gfp) |
| 15739 | { |
| 15740 | struct sk_buff *msg; |
| 15741 | void *hdr; |
| 15742 | |
| 15743 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15744 | if (!msg) |
| 15745 | return; |
| 15746 | |
| 15747 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 15748 | if (!hdr) { |
| 15749 | nlmsg_free(msg); |
| 15750 | return; |
| 15751 | } |
| 15752 | |
| 15753 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 15754 | goto nla_put_failure; |
| 15755 | |
| 15756 | /* NOP and radar events don't need a netdev parameter */ |
| 15757 | if (netdev) { |
| 15758 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 15759 | |
| 15760 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15761 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15762 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15763 | goto nla_put_failure; |
| 15764 | } |
| 15765 | |
| 15766 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 15767 | goto nla_put_failure; |
| 15768 | |
| 15769 | if (nl80211_send_chandef(msg, chandef)) |
| 15770 | goto nla_put_failure; |
| 15771 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15772 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15773 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15774 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15775 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15776 | return; |
| 15777 | |
| 15778 | nla_put_failure: |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15779 | nlmsg_free(msg); |
| 15780 | } |
| 15781 | |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 15782 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, |
| 15783 | struct sta_opmode_info *sta_opmode, |
| 15784 | gfp_t gfp) |
| 15785 | { |
| 15786 | struct sk_buff *msg; |
| 15787 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15788 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 15789 | void *hdr; |
| 15790 | |
| 15791 | if (WARN_ON(!mac)) |
| 15792 | return; |
| 15793 | |
| 15794 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15795 | if (!msg) |
| 15796 | return; |
| 15797 | |
| 15798 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); |
| 15799 | if (!hdr) { |
| 15800 | nlmsg_free(msg); |
| 15801 | return; |
| 15802 | } |
| 15803 | |
| 15804 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 15805 | goto nla_put_failure; |
| 15806 | |
| 15807 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 15808 | goto nla_put_failure; |
| 15809 | |
| 15810 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
| 15811 | goto nla_put_failure; |
| 15812 | |
| 15813 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && |
| 15814 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) |
| 15815 | goto nla_put_failure; |
| 15816 | |
| 15817 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && |
| 15818 | nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) |
| 15819 | goto nla_put_failure; |
| 15820 | |
| 15821 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && |
| 15822 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) |
| 15823 | goto nla_put_failure; |
| 15824 | |
| 15825 | genlmsg_end(msg, hdr); |
| 15826 | |
| 15827 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15828 | NL80211_MCGRP_MLME, gfp); |
| 15829 | |
| 15830 | return; |
| 15831 | |
| 15832 | nla_put_failure: |
| 15833 | nlmsg_free(msg); |
| 15834 | } |
| 15835 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); |
| 15836 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15837 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 15838 | u64 cookie, bool acked, s32 ack_signal, |
| 15839 | bool is_valid_ack_signal, gfp_t gfp) |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15840 | { |
| 15841 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15842 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15843 | struct sk_buff *msg; |
| 15844 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15845 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 15846 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 15847 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15848 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 15849 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15850 | if (!msg) |
| 15851 | return; |
| 15852 | |
| 15853 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 15854 | if (!hdr) { |
| 15855 | nlmsg_free(msg); |
| 15856 | return; |
| 15857 | } |
| 15858 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15859 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15860 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15861 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15862 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 15863 | NL80211_ATTR_PAD) || |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 15864 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
| 15865 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, |
| 15866 | ack_signal))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15867 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15868 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15869 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15870 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15871 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15872 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15873 | return; |
| 15874 | |
| 15875 | nla_put_failure: |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15876 | nlmsg_free(msg); |
| 15877 | } |
| 15878 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 15879 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15880 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 15881 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15882 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15883 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15884 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15885 | struct sk_buff *msg; |
| 15886 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15887 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15888 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 15889 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 15890 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15891 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 15892 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 15893 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 15894 | if (!msg) { |
| 15895 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 15896 | return; |
| 15897 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15898 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15899 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 15900 | if (!hdr) |
| 15901 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15902 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15903 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15904 | (freq && |
| 15905 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 15906 | (sig_dbm && |
| 15907 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 15908 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 15909 | goto nla_put_failure; |
| 15910 | |
| 15911 | genlmsg_end(msg, hdr); |
| 15912 | |
| 15913 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15914 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15915 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15916 | return; |
| 15917 | |
| 15918 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15919 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15920 | nlmsg_free(msg); |
| 15921 | } |
| 15922 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 15923 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15924 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 15925 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 15926 | struct cfg80211_wowlan_wakeup *wakeup) |
| 15927 | { |
| 15928 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 15929 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 15930 | int i, j; |
| 15931 | |
| 15932 | nl_results = nla_nest_start( |
| 15933 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 15934 | if (!nl_results) |
| 15935 | return -EMSGSIZE; |
| 15936 | |
| 15937 | for (i = 0; i < nd->n_matches; i++) { |
| 15938 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 15939 | |
| 15940 | nl_match = nla_nest_start(msg, i); |
| 15941 | if (!nl_match) |
| 15942 | break; |
| 15943 | |
| 15944 | /* The SSID attribute is optional in nl80211, but for |
| 15945 | * simplicity reasons it's always present in the |
| 15946 | * cfg80211 structure. If a driver can't pass the |
| 15947 | * SSID, that needs to be changed. A zero length SSID |
| 15948 | * is still a valid SSID (wildcard), so it cannot be |
| 15949 | * used for this purpose. |
| 15950 | */ |
| 15951 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 15952 | match->ssid.ssid)) { |
| 15953 | nla_nest_cancel(msg, nl_match); |
| 15954 | goto out; |
| 15955 | } |
| 15956 | |
| 15957 | if (match->n_channels) { |
| 15958 | nl_freqs = nla_nest_start( |
| 15959 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 15960 | if (!nl_freqs) { |
| 15961 | nla_nest_cancel(msg, nl_match); |
| 15962 | goto out; |
| 15963 | } |
| 15964 | |
| 15965 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 15966 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 15967 | nla_nest_cancel(msg, nl_freqs); |
| 15968 | nla_nest_cancel(msg, nl_match); |
| 15969 | goto out; |
| 15970 | } |
| 15971 | } |
| 15972 | |
| 15973 | nla_nest_end(msg, nl_freqs); |
| 15974 | } |
| 15975 | |
| 15976 | nla_nest_end(msg, nl_match); |
| 15977 | } |
| 15978 | |
| 15979 | out: |
| 15980 | nla_nest_end(msg, nl_results); |
| 15981 | return 0; |
| 15982 | } |
| 15983 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15984 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 15985 | struct cfg80211_wowlan_wakeup *wakeup, |
| 15986 | gfp_t gfp) |
| 15987 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15988 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15989 | struct sk_buff *msg; |
| 15990 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15991 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15992 | |
| 15993 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 15994 | |
| 15995 | if (wakeup) |
| 15996 | size += wakeup->packet_present_len; |
| 15997 | |
| 15998 | msg = nlmsg_new(size, gfp); |
| 15999 | if (!msg) |
| 16000 | return; |
| 16001 | |
| 16002 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 16003 | if (!hdr) |
| 16004 | goto free_msg; |
| 16005 | |
| 16006 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16007 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16008 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16009 | goto free_msg; |
| 16010 | |
| 16011 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16012 | wdev->netdev->ifindex)) |
| 16013 | goto free_msg; |
| 16014 | |
| 16015 | if (wakeup) { |
| 16016 | struct nlattr *reasons; |
| 16017 | |
| 16018 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 16019 | if (!reasons) |
| 16020 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16021 | |
| 16022 | if (wakeup->disconnect && |
| 16023 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 16024 | goto free_msg; |
| 16025 | if (wakeup->magic_pkt && |
| 16026 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 16027 | goto free_msg; |
| 16028 | if (wakeup->gtk_rekey_failure && |
| 16029 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 16030 | goto free_msg; |
| 16031 | if (wakeup->eap_identity_req && |
| 16032 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 16033 | goto free_msg; |
| 16034 | if (wakeup->four_way_handshake && |
| 16035 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 16036 | goto free_msg; |
| 16037 | if (wakeup->rfkill_release && |
| 16038 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 16039 | goto free_msg; |
| 16040 | |
| 16041 | if (wakeup->pattern_idx >= 0 && |
| 16042 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 16043 | wakeup->pattern_idx)) |
| 16044 | goto free_msg; |
| 16045 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 16046 | if (wakeup->tcp_match && |
| 16047 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 16048 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 16049 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 16050 | if (wakeup->tcp_connlost && |
| 16051 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 16052 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 16053 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 16054 | if (wakeup->tcp_nomoretokens && |
| 16055 | nla_put_flag(msg, |
| 16056 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 16057 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 16058 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16059 | if (wakeup->packet) { |
| 16060 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 16061 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 16062 | |
| 16063 | if (!wakeup->packet_80211) { |
| 16064 | pkt_attr = |
| 16065 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 16066 | len_attr = |
| 16067 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 16068 | } |
| 16069 | |
| 16070 | if (wakeup->packet_len && |
| 16071 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 16072 | goto free_msg; |
| 16073 | |
| 16074 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 16075 | wakeup->packet)) |
| 16076 | goto free_msg; |
| 16077 | } |
| 16078 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 16079 | if (wakeup->net_detect && |
| 16080 | cfg80211_net_detect_results(msg, wakeup)) |
| 16081 | goto free_msg; |
| 16082 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16083 | nla_nest_end(msg, reasons); |
| 16084 | } |
| 16085 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16086 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16087 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16088 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16089 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 16090 | return; |
| 16091 | |
| 16092 | free_msg: |
| 16093 | nlmsg_free(msg); |
| 16094 | } |
| 16095 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 16096 | #endif |
| 16097 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 16098 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 16099 | enum nl80211_tdls_operation oper, |
| 16100 | u16 reason_code, gfp_t gfp) |
| 16101 | { |
| 16102 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16103 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 16104 | struct sk_buff *msg; |
| 16105 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 16106 | |
| 16107 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 16108 | reason_code); |
| 16109 | |
| 16110 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16111 | if (!msg) |
| 16112 | return; |
| 16113 | |
| 16114 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 16115 | if (!hdr) { |
| 16116 | nlmsg_free(msg); |
| 16117 | return; |
| 16118 | } |
| 16119 | |
| 16120 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16121 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16122 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 16123 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 16124 | (reason_code > 0 && |
| 16125 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 16126 | goto nla_put_failure; |
| 16127 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16128 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 16129 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16130 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16131 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 16132 | return; |
| 16133 | |
| 16134 | nla_put_failure: |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 16135 | nlmsg_free(msg); |
| 16136 | } |
| 16137 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 16138 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16139 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 16140 | unsigned long state, |
| 16141 | void *_notify) |
| 16142 | { |
| 16143 | struct netlink_notify *notify = _notify; |
| 16144 | struct cfg80211_registered_device *rdev; |
| 16145 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16146 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16147 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 16148 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16149 | return NOTIFY_DONE; |
| 16150 | |
| 16151 | rcu_read_lock(); |
| 16152 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16153 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 16154 | struct cfg80211_sched_scan_request *sched_scan_req; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 16155 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 16156 | list_for_each_entry_rcu(sched_scan_req, |
| 16157 | &rdev->sched_scan_req_list, |
| 16158 | list) { |
| 16159 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 16160 | sched_scan_req->nl_owner_dead = true; |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 16161 | schedule_work(&rdev->sched_scan_stop_wk); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 16162 | } |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 16163 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 16164 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 16165 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16166 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16167 | |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 16168 | if (wdev->owner_nlportid == notify->portid) { |
| 16169 | wdev->nl_owner_dead = true; |
| 16170 | schedule_work(&rdev->destroy_work); |
| 16171 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 16172 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 16173 | } |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 16174 | |
| 16175 | cfg80211_release_pmsr(wdev, notify->portid); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 16176 | } |
| 16177 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16178 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 16179 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 16180 | list) { |
| 16181 | if (reg->nlportid == notify->portid) { |
| 16182 | list_del(®->list); |
| 16183 | kfree(reg); |
| 16184 | break; |
| 16185 | } |
| 16186 | } |
| 16187 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16188 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16189 | |
| 16190 | rcu_read_unlock(); |
| 16191 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 16192 | /* |
| 16193 | * It is possible that the user space process that is controlling the |
| 16194 | * indoor setting disappeared, so notify the regulatory core. |
| 16195 | */ |
| 16196 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 16197 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16198 | } |
| 16199 | |
| 16200 | static struct notifier_block nl80211_netlink_notifier = { |
| 16201 | .notifier_call = nl80211_netlink_notify, |
| 16202 | }; |
| 16203 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 16204 | void cfg80211_ft_event(struct net_device *netdev, |
| 16205 | struct cfg80211_ft_event_params *ft_event) |
| 16206 | { |
| 16207 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16208 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 16209 | struct sk_buff *msg; |
| 16210 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 16211 | |
| 16212 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 16213 | |
| 16214 | if (!ft_event->target_ap) |
| 16215 | return; |
| 16216 | |
Dedy Lansky | 1039d08 | 2018-05-17 16:25:03 +0300 | [diff] [blame] | 16217 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
| 16218 | GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 16219 | if (!msg) |
| 16220 | return; |
| 16221 | |
| 16222 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 16223 | if (!hdr) |
| 16224 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 16225 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 16226 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16227 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16228 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 16229 | goto out; |
| 16230 | |
| 16231 | if (ft_event->ies && |
| 16232 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 16233 | goto out; |
| 16234 | if (ft_event->ric_ies && |
| 16235 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 16236 | ft_event->ric_ies)) |
| 16237 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 16238 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16239 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 16240 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16241 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16242 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 16243 | return; |
| 16244 | out: |
| 16245 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 16246 | } |
| 16247 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 16248 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 16249 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 16250 | { |
| 16251 | struct cfg80211_registered_device *rdev; |
| 16252 | struct sk_buff *msg; |
| 16253 | void *hdr; |
| 16254 | u32 nlportid; |
| 16255 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16256 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 16257 | if (!rdev->crit_proto_nlportid) |
| 16258 | return; |
| 16259 | |
| 16260 | nlportid = rdev->crit_proto_nlportid; |
| 16261 | rdev->crit_proto_nlportid = 0; |
| 16262 | |
| 16263 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16264 | if (!msg) |
| 16265 | return; |
| 16266 | |
| 16267 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 16268 | if (!hdr) |
| 16269 | goto nla_put_failure; |
| 16270 | |
| 16271 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16272 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16273 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 16274 | goto nla_put_failure; |
| 16275 | |
| 16276 | genlmsg_end(msg, hdr); |
| 16277 | |
| 16278 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 16279 | return; |
| 16280 | |
| 16281 | nla_put_failure: |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 16282 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 16283 | } |
| 16284 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 16285 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 16286 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 16287 | { |
| 16288 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16289 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 16290 | struct sk_buff *msg; |
| 16291 | void *hdr; |
| 16292 | |
| 16293 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 16294 | if (!msg) |
| 16295 | return; |
| 16296 | |
| 16297 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 16298 | if (!hdr) |
| 16299 | goto out; |
| 16300 | |
| 16301 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16302 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16303 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16304 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 16305 | goto out; |
| 16306 | |
| 16307 | genlmsg_end(msg, hdr); |
| 16308 | |
| 16309 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 16310 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 16311 | return; |
| 16312 | out: |
| 16313 | nlmsg_free(msg); |
| 16314 | } |
| 16315 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 16316 | int cfg80211_external_auth_request(struct net_device *dev, |
| 16317 | struct cfg80211_external_auth_params *params, |
| 16318 | gfp_t gfp) |
| 16319 | { |
| 16320 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16321 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16322 | struct sk_buff *msg; |
| 16323 | void *hdr; |
| 16324 | |
| 16325 | if (!wdev->conn_owner_nlportid) |
| 16326 | return -EINVAL; |
| 16327 | |
| 16328 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16329 | if (!msg) |
| 16330 | return -ENOMEM; |
| 16331 | |
| 16332 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 16333 | if (!hdr) |
| 16334 | goto nla_put_failure; |
| 16335 | |
| 16336 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16337 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16338 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || |
| 16339 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, |
| 16340 | params->action) || |
| 16341 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || |
| 16342 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, |
| 16343 | params->ssid.ssid)) |
| 16344 | goto nla_put_failure; |
| 16345 | |
| 16346 | genlmsg_end(msg, hdr); |
| 16347 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 16348 | wdev->conn_owner_nlportid); |
| 16349 | return 0; |
| 16350 | |
| 16351 | nla_put_failure: |
| 16352 | nlmsg_free(msg); |
| 16353 | return -ENOBUFS; |
| 16354 | } |
| 16355 | EXPORT_SYMBOL(cfg80211_external_auth_request); |
| 16356 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16357 | /* initialisation/exit functions */ |
| 16358 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 16359 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16360 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 16361 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16362 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 16363 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16364 | if (err) |
| 16365 | return err; |
| 16366 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16367 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 16368 | if (err) |
| 16369 | goto err_out; |
| 16370 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16371 | return 0; |
| 16372 | err_out: |
| 16373 | genl_unregister_family(&nl80211_fam); |
| 16374 | return err; |
| 16375 | } |
| 16376 | |
| 16377 | void nl80211_exit(void) |
| 16378 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16379 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16380 | genl_unregister_family(&nl80211_fam); |
| 16381 | } |