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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 203 | /* policy for the attributes */ |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 204 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 205 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 206 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 207 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 208 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 209 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 210 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 211 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 212 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 213 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 214 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 215 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 216 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 217 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 218 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 219 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 220 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 221 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 222 | |
| 223 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 224 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 225 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 226 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 227 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 228 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 229 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 230 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 231 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 232 | .len = WLAN_MAX_KEY_LEN }, |
| 233 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 234 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 235 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 236 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 237 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 238 | |
| 239 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 240 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 242 | .len = IEEE80211_MAX_DATA_LEN }, |
| 243 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 244 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 245 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 246 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 247 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 248 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 249 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 250 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 251 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 252 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 253 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 254 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 255 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 256 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 257 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 258 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 259 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 260 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 261 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 262 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 263 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 264 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 265 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 266 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 267 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 268 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 269 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 270 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 271 | |
| 272 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 273 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 274 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 275 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 276 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 277 | |
| 278 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 279 | .len = IEEE80211_MAX_SSID_LEN }, |
| 280 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 281 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 282 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 283 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 284 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 285 | [NL80211_ATTR_STA_FLAGS2] = { |
| 286 | .len = sizeof(struct nl80211_sta_flag_update), |
| 287 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 288 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 289 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 290 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 291 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 293 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 294 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 295 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 296 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Srinivas Dasari | 9361df1 | 2017-07-07 01:43:39 +0300 | [diff] [blame] | 297 | [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 298 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 300 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 301 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 302 | .len = IEEE80211_MAX_DATA_LEN }, |
| 303 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 304 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 305 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 306 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 308 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 309 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 311 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 312 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 313 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 314 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 315 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 317 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 318 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 319 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 320 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 321 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 322 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 323 | .len = IEEE80211_MAX_DATA_LEN }, |
| 324 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 325 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 326 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 327 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 328 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 329 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 330 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 331 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 332 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 333 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 335 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 337 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 338 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 339 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 340 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 341 | .len = NL80211_HT_CAPABILITY_LEN |
| 342 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 344 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 345 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 346 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 347 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 348 | [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 349 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 350 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 352 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Srinivas Dasari | 8feb69c | 2017-07-07 01:43:41 +0300 | [diff] [blame] | 353 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 354 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 355 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 356 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 357 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 358 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 360 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 361 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 362 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 363 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 364 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 365 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 366 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 367 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 368 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 369 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 370 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 371 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 372 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 373 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 374 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 375 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 376 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 377 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 378 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 379 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 380 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 381 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 382 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 383 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 384 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 385 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 386 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 387 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 388 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 389 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 390 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 391 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 392 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 393 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 394 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 395 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 396 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 397 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 398 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 399 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 400 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 401 | }, |
| 402 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 403 | [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 }, |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 404 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 405 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 406 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 407 | .len = FILS_MAX_KEK_LEN }, |
| 408 | [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 409 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 410 | [NL80211_ATTR_BSSID] = { .len = ETH_ALEN }, |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 411 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 412 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 413 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 414 | }, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 415 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 416 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 417 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 418 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 419 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 420 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 421 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 422 | .len = FILS_ERP_MAX_RRK_LEN }, |
| 423 | [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 }, |
| 424 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 425 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 426 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 427 | |
| 428 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, |
| 429 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, |
| 430 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 431 | [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY, |
| 432 | .len = NL80211_HE_MAX_CAPABILITY_LEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 433 | }; |
| 434 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 435 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 436 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 437 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 438 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 439 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 440 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 441 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 442 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 443 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 444 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 445 | }; |
| 446 | |
| 447 | /* policy for the key default flags */ |
| 448 | static const struct nla_policy |
| 449 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 450 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 451 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 452 | }; |
| 453 | |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 454 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 455 | /* policy for WoWLAN attributes */ |
| 456 | static const struct nla_policy |
| 457 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 458 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 459 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 460 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 461 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 462 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 463 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 464 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 465 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 466 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 467 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 468 | }; |
| 469 | |
| 470 | static const struct nla_policy |
| 471 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 472 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 473 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 474 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 475 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 476 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 477 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 478 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 479 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 480 | }, |
| 481 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 482 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 483 | }, |
| 484 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 485 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 486 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 487 | }; |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 488 | #endif /* CONFIG_PM */ |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 489 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 490 | /* policy for coalesce rule attributes */ |
| 491 | static const struct nla_policy |
| 492 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 493 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 494 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 495 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 496 | }; |
| 497 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 498 | /* policy for GTK rekey offload attributes */ |
| 499 | static const struct nla_policy |
| 500 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 501 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 502 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 503 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 504 | }; |
| 505 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 506 | static const struct nla_policy |
| 507 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 508 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 509 | .len = IEEE80211_MAX_SSID_LEN }, |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 510 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 511 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 512 | }; |
| 513 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 514 | static const struct nla_policy |
| 515 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 516 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 517 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 518 | }; |
| 519 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 520 | static const struct nla_policy |
| 521 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 522 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 523 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 524 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 525 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 526 | }, |
| 527 | }; |
| 528 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 529 | /* policy for NAN function attributes */ |
| 530 | static const struct nla_policy |
| 531 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
| 532 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, |
Srinivas Dasari | 0a27844 | 2017-07-07 01:43:40 +0300 | [diff] [blame] | 533 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 534 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 535 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 536 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 537 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 538 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 539 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
| 540 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN }, |
| 541 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 542 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 543 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 544 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 545 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 546 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 547 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 548 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 549 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 550 | }; |
| 551 | |
| 552 | /* policy for Service Response Filter attributes */ |
| 553 | static const struct nla_policy |
| 554 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 555 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 556 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 557 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 558 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 559 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 560 | }; |
| 561 | |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 562 | /* policy for packet pattern attributes */ |
| 563 | static const struct nla_policy |
| 564 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { |
| 565 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, |
| 566 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, |
| 567 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, |
| 568 | }; |
| 569 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 570 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 571 | struct netlink_callback *cb, |
| 572 | struct cfg80211_registered_device **rdev, |
| 573 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 574 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 575 | int err; |
| 576 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 577 | if (!cb->args[0]) { |
| 578 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 579 | genl_family_attrbuf(&nl80211_fam), |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 580 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 581 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 582 | return err; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 583 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 584 | *wdev = __cfg80211_wdev_from_attrs( |
| 585 | sock_net(skb->sk), |
| 586 | genl_family_attrbuf(&nl80211_fam)); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 587 | if (IS_ERR(*wdev)) |
| 588 | return PTR_ERR(*wdev); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 589 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 590 | /* 0 is the first index - add 1 to parse only once */ |
| 591 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 592 | cb->args[1] = (*wdev)->identifier; |
| 593 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 594 | /* subtract the 1 again here */ |
| 595 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 596 | struct wireless_dev *tmp; |
| 597 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 598 | if (!wiphy) |
| 599 | return -ENODEV; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 600 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 601 | *wdev = NULL; |
| 602 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 603 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 604 | if (tmp->identifier == cb->args[1]) { |
| 605 | *wdev = tmp; |
| 606 | break; |
| 607 | } |
| 608 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 609 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 610 | if (!*wdev) |
| 611 | return -ENODEV; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 612 | } |
| 613 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 614 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 615 | } |
| 616 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 617 | /* IE validation */ |
| 618 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 619 | { |
| 620 | const u8 *pos; |
| 621 | int len; |
| 622 | |
| 623 | if (!attr) |
| 624 | return true; |
| 625 | |
| 626 | pos = nla_data(attr); |
| 627 | len = nla_len(attr); |
| 628 | |
| 629 | while (len) { |
| 630 | u8 elemlen; |
| 631 | |
| 632 | if (len < 2) |
| 633 | return false; |
| 634 | len -= 2; |
| 635 | |
| 636 | elemlen = pos[1]; |
| 637 | if (elemlen > len) |
| 638 | return false; |
| 639 | |
| 640 | len -= elemlen; |
| 641 | pos += 2 + elemlen; |
| 642 | } |
| 643 | |
| 644 | return true; |
| 645 | } |
| 646 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 647 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 648 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 649 | int flags, u8 cmd) |
| 650 | { |
| 651 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 652 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 653 | } |
| 654 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 655 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, |
| 656 | const struct ieee80211_reg_rule *rule) |
| 657 | { |
| 658 | int j; |
| 659 | struct nlattr *nl_wmm_rules = |
| 660 | nla_nest_start(msg, NL80211_FREQUENCY_ATTR_WMM); |
| 661 | |
| 662 | if (!nl_wmm_rules) |
| 663 | goto nla_put_failure; |
| 664 | |
| 665 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { |
| 666 | struct nlattr *nl_wmm_rule = nla_nest_start(msg, j); |
| 667 | |
| 668 | if (!nl_wmm_rule) |
| 669 | goto nla_put_failure; |
| 670 | |
| 671 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, |
| 672 | rule->wmm_rule->client[j].cw_min) || |
| 673 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, |
| 674 | rule->wmm_rule->client[j].cw_max) || |
| 675 | nla_put_u8(msg, NL80211_WMMR_AIFSN, |
| 676 | rule->wmm_rule->client[j].aifsn) || |
| 677 | nla_put_u8(msg, NL80211_WMMR_TXOP, |
| 678 | rule->wmm_rule->client[j].cot)) |
| 679 | goto nla_put_failure; |
| 680 | |
| 681 | nla_nest_end(msg, nl_wmm_rule); |
| 682 | } |
| 683 | nla_nest_end(msg, nl_wmm_rules); |
| 684 | |
| 685 | return 0; |
| 686 | |
| 687 | nla_put_failure: |
| 688 | return -ENOBUFS; |
| 689 | } |
| 690 | |
| 691 | 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] | 692 | struct ieee80211_channel *chan, |
| 693 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 694 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 695 | /* Some channels must be completely excluded from the |
| 696 | * list to protect old user-space tools from breaking |
| 697 | */ |
| 698 | if (!large && chan->flags & |
| 699 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 700 | return 0; |
| 701 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 702 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 703 | chan->center_freq)) |
| 704 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 705 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 706 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 707 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 708 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 709 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 710 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 711 | goto nla_put_failure; |
| 712 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 713 | goto nla_put_failure; |
| 714 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 715 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 716 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 717 | goto nla_put_failure; |
| 718 | if (large) { |
| 719 | u32 time; |
| 720 | |
| 721 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 722 | |
| 723 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 724 | chan->dfs_state)) |
| 725 | goto nla_put_failure; |
| 726 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 727 | time)) |
| 728 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 729 | if (nla_put_u32(msg, |
| 730 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 731 | chan->dfs_cac_ms)) |
| 732 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 733 | } |
| 734 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 735 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 736 | if (large) { |
| 737 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 738 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 739 | goto nla_put_failure; |
| 740 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 741 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 742 | goto nla_put_failure; |
| 743 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 744 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 745 | goto nla_put_failure; |
| 746 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 747 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 748 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 749 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 750 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 751 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 752 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 753 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 754 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 755 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 756 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 757 | goto nla_put_failure; |
| 758 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 759 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 760 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 761 | } |
| 762 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 763 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 764 | DBM_TO_MBM(chan->max_power))) |
| 765 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 766 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 767 | if (large) { |
| 768 | const struct ieee80211_reg_rule *rule = |
| 769 | freq_reg_info(wiphy, chan->center_freq); |
| 770 | |
| 771 | if (!IS_ERR(rule) && rule->wmm_rule) { |
| 772 | if (nl80211_msg_put_wmm_rules(msg, rule)) |
| 773 | goto nla_put_failure; |
| 774 | } |
| 775 | } |
| 776 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 777 | return 0; |
| 778 | |
| 779 | nla_put_failure: |
| 780 | return -ENOBUFS; |
| 781 | } |
| 782 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 783 | static bool nl80211_put_txq_stats(struct sk_buff *msg, |
| 784 | struct cfg80211_txq_stats *txqstats, |
| 785 | int attrtype) |
| 786 | { |
| 787 | struct nlattr *txqattr; |
| 788 | |
| 789 | #define PUT_TXQVAL_U32(attr, memb) do { \ |
| 790 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ |
| 791 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ |
| 792 | return false; \ |
| 793 | } while (0) |
| 794 | |
| 795 | txqattr = nla_nest_start(msg, attrtype); |
| 796 | if (!txqattr) |
| 797 | return false; |
| 798 | |
| 799 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); |
| 800 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); |
| 801 | PUT_TXQVAL_U32(FLOWS, flows); |
| 802 | PUT_TXQVAL_U32(DROPS, drops); |
| 803 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); |
| 804 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); |
| 805 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); |
| 806 | PUT_TXQVAL_U32(COLLISIONS, collisions); |
| 807 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); |
| 808 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); |
| 809 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); |
| 810 | nla_nest_end(msg, txqattr); |
| 811 | |
| 812 | #undef PUT_TXQVAL_U32 |
| 813 | return true; |
| 814 | } |
| 815 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 816 | /* netlink command implementations */ |
| 817 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 818 | struct key_parse { |
| 819 | struct key_params p; |
| 820 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 821 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 822 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 823 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 824 | }; |
| 825 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 826 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
| 827 | struct key_parse *k) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 828 | { |
| 829 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 830 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 831 | nl80211_key_policy, info->extack); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 832 | if (err) |
| 833 | return err; |
| 834 | |
| 835 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 836 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 837 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 838 | if (k->def) { |
| 839 | k->def_uni = true; |
| 840 | k->def_multi = true; |
| 841 | } |
| 842 | if (k->defmgmt) |
| 843 | k->def_multi = true; |
| 844 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 845 | if (tb[NL80211_KEY_IDX]) |
| 846 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 847 | |
| 848 | if (tb[NL80211_KEY_DATA]) { |
| 849 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 850 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 851 | } |
| 852 | |
| 853 | if (tb[NL80211_KEY_SEQ]) { |
| 854 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 855 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 856 | } |
| 857 | |
| 858 | if (tb[NL80211_KEY_CIPHER]) |
| 859 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 860 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 861 | if (tb[NL80211_KEY_TYPE]) { |
| 862 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 863 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 864 | return genl_err_attr(info, -EINVAL, |
| 865 | tb[NL80211_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 866 | } |
| 867 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 868 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 869 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 870 | |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 871 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 872 | tb[NL80211_KEY_DEFAULT_TYPES], |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 873 | nl80211_key_default_policy, |
| 874 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 875 | if (err) |
| 876 | return err; |
| 877 | |
| 878 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 879 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 880 | } |
| 881 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 882 | return 0; |
| 883 | } |
| 884 | |
| 885 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 886 | { |
| 887 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 888 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 889 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 890 | } |
| 891 | |
| 892 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 893 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 894 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 895 | } |
| 896 | |
| 897 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 898 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 899 | |
| 900 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 901 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 902 | |
| 903 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 904 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 905 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 906 | if (k->def) { |
| 907 | k->def_uni = true; |
| 908 | k->def_multi = true; |
| 909 | } |
| 910 | if (k->defmgmt) |
| 911 | k->def_multi = true; |
| 912 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 913 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 914 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 915 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) { |
| 916 | GENL_SET_ERR_MSG(info, "key type out of range"); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 917 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 918 | } |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 919 | } |
| 920 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 921 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 922 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 923 | int err = nla_parse_nested(kdt, |
| 924 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 925 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 926 | nl80211_key_default_policy, |
| 927 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 928 | if (err) |
| 929 | return err; |
| 930 | |
| 931 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 932 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 933 | } |
| 934 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 935 | return 0; |
| 936 | } |
| 937 | |
| 938 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 939 | { |
| 940 | int err; |
| 941 | |
| 942 | memset(k, 0, sizeof(*k)); |
| 943 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 944 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 945 | |
| 946 | if (info->attrs[NL80211_ATTR_KEY]) |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 947 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 948 | else |
| 949 | err = nl80211_parse_key_old(info, k); |
| 950 | |
| 951 | if (err) |
| 952 | return err; |
| 953 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 954 | if (k->def && k->defmgmt) { |
| 955 | GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 956 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 957 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 958 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 959 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 960 | if (k->def_uni || !k->def_multi) { |
| 961 | GENL_SET_ERR_MSG(info, "defmgmt key must be mcast"); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 962 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 963 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 964 | } |
| 965 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 966 | if (k->idx != -1) { |
| 967 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 968 | if (k->idx < 4 || k->idx > 5) { |
| 969 | GENL_SET_ERR_MSG(info, |
| 970 | "defmgmt key idx not 4 or 5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 971 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 972 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 973 | } else if (k->def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 974 | if (k->idx < 0 || k->idx > 3) { |
| 975 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 976 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 977 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 978 | } else { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 979 | if (k->idx < 0 || k->idx > 5) { |
| 980 | GENL_SET_ERR_MSG(info, "key idx not 0-5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 981 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 982 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
| 986 | return 0; |
| 987 | } |
| 988 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 989 | static struct cfg80211_cached_keys * |
| 990 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 991 | struct genl_info *info, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 992 | { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 993 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 994 | struct key_parse parse; |
| 995 | struct nlattr *key; |
| 996 | struct cfg80211_cached_keys *result; |
| 997 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 998 | bool have_key = false; |
| 999 | |
| 1000 | nla_for_each_nested(key, keys, rem) { |
| 1001 | have_key = true; |
| 1002 | break; |
| 1003 | } |
| 1004 | |
| 1005 | if (!have_key) |
| 1006 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1007 | |
| 1008 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 1009 | if (!result) |
| 1010 | return ERR_PTR(-ENOMEM); |
| 1011 | |
| 1012 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1013 | |
| 1014 | nla_for_each_nested(key, keys, rem) { |
| 1015 | memset(&parse, 0, sizeof(parse)); |
| 1016 | parse.idx = -1; |
| 1017 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1018 | err = nl80211_parse_key_new(info, key, &parse); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1019 | if (err) |
| 1020 | goto error; |
| 1021 | err = -EINVAL; |
| 1022 | if (!parse.p.key) |
| 1023 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1024 | if (parse.idx < 0 || parse.idx > 3) { |
| 1025 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1026 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1027 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1028 | if (parse.def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1029 | if (def) { |
| 1030 | GENL_SET_ERR_MSG(info, |
| 1031 | "only one key can be default"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1032 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1033 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1034 | def = 1; |
| 1035 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1036 | if (!parse.def_uni || !parse.def_multi) |
| 1037 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1038 | } else if (parse.defmgmt) |
| 1039 | goto error; |
| 1040 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1041 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1042 | if (err) |
| 1043 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1044 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1045 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1046 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1047 | err = -EINVAL; |
| 1048 | goto error; |
| 1049 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1050 | result->params[parse.idx].cipher = parse.p.cipher; |
| 1051 | result->params[parse.idx].key_len = parse.p.key_len; |
| 1052 | result->params[parse.idx].key = result->data[parse.idx]; |
| 1053 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 1054 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1055 | /* must be WEP key if we got here */ |
| 1056 | if (no_ht) |
| 1057 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1058 | } |
| 1059 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1060 | if (result->def < 0) { |
| 1061 | err = -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1062 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1063 | goto error; |
| 1064 | } |
| 1065 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1066 | return result; |
| 1067 | error: |
| 1068 | kfree(result); |
| 1069 | return ERR_PTR(err); |
| 1070 | } |
| 1071 | |
| 1072 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 1073 | { |
| 1074 | ASSERT_WDEV_LOCK(wdev); |
| 1075 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1076 | switch (wdev->iftype) { |
| 1077 | case NL80211_IFTYPE_AP: |
| 1078 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1079 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 1080 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1081 | break; |
| 1082 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1083 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1084 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1085 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1086 | return -ENOLINK; |
| 1087 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1088 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 1089 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1090 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 1091 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1092 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1093 | case NL80211_IFTYPE_WDS: |
| 1094 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1095 | return -EINVAL; |
| 1096 | } |
| 1097 | |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1101 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 1102 | struct nlattr *tb) |
| 1103 | { |
| 1104 | struct ieee80211_channel *chan; |
| 1105 | |
| 1106 | if (tb == NULL) |
| 1107 | return NULL; |
| 1108 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 1109 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1110 | return NULL; |
| 1111 | return chan; |
| 1112 | } |
| 1113 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1114 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1115 | { |
| 1116 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 1117 | int i; |
| 1118 | |
| 1119 | if (!nl_modes) |
| 1120 | goto nla_put_failure; |
| 1121 | |
| 1122 | i = 0; |
| 1123 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1124 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1125 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1126 | ifmodes >>= 1; |
| 1127 | i++; |
| 1128 | } |
| 1129 | |
| 1130 | nla_nest_end(msg, nl_modes); |
| 1131 | return 0; |
| 1132 | |
| 1133 | nla_put_failure: |
| 1134 | return -ENOBUFS; |
| 1135 | } |
| 1136 | |
| 1137 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1138 | struct sk_buff *msg, |
| 1139 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1140 | { |
| 1141 | struct nlattr *nl_combis; |
| 1142 | int i, j; |
| 1143 | |
| 1144 | nl_combis = nla_nest_start(msg, |
| 1145 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 1146 | if (!nl_combis) |
| 1147 | goto nla_put_failure; |
| 1148 | |
| 1149 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1150 | const struct ieee80211_iface_combination *c; |
| 1151 | struct nlattr *nl_combi, *nl_limits; |
| 1152 | |
| 1153 | c = &wiphy->iface_combinations[i]; |
| 1154 | |
| 1155 | nl_combi = nla_nest_start(msg, i + 1); |
| 1156 | if (!nl_combi) |
| 1157 | goto nla_put_failure; |
| 1158 | |
| 1159 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 1160 | if (!nl_limits) |
| 1161 | goto nla_put_failure; |
| 1162 | |
| 1163 | for (j = 0; j < c->n_limits; j++) { |
| 1164 | struct nlattr *nl_limit; |
| 1165 | |
| 1166 | nl_limit = nla_nest_start(msg, j + 1); |
| 1167 | if (!nl_limit) |
| 1168 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1169 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1170 | c->limits[j].max)) |
| 1171 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1172 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1173 | c->limits[j].types)) |
| 1174 | goto nla_put_failure; |
| 1175 | nla_nest_end(msg, nl_limit); |
| 1176 | } |
| 1177 | |
| 1178 | nla_nest_end(msg, nl_limits); |
| 1179 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1180 | if (c->beacon_int_infra_match && |
| 1181 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1182 | goto nla_put_failure; |
| 1183 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1184 | c->num_different_channels) || |
| 1185 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1186 | c->max_interfaces)) |
| 1187 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1188 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1189 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1190 | c->radar_detect_widths) || |
| 1191 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1192 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1193 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1194 | if (c->beacon_int_min_gcd && |
| 1195 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1196 | c->beacon_int_min_gcd)) |
| 1197 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1198 | |
| 1199 | nla_nest_end(msg, nl_combi); |
| 1200 | } |
| 1201 | |
| 1202 | nla_nest_end(msg, nl_combis); |
| 1203 | |
| 1204 | return 0; |
| 1205 | nla_put_failure: |
| 1206 | return -ENOBUFS; |
| 1207 | } |
| 1208 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1209 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1210 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1211 | struct sk_buff *msg) |
| 1212 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1213 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1214 | struct nlattr *nl_tcp; |
| 1215 | |
| 1216 | if (!tcp) |
| 1217 | return 0; |
| 1218 | |
| 1219 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1220 | if (!nl_tcp) |
| 1221 | return -ENOBUFS; |
| 1222 | |
| 1223 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1224 | tcp->data_payload_max)) |
| 1225 | return -ENOBUFS; |
| 1226 | |
| 1227 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1228 | tcp->data_payload_max)) |
| 1229 | return -ENOBUFS; |
| 1230 | |
| 1231 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1232 | return -ENOBUFS; |
| 1233 | |
| 1234 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1235 | sizeof(*tcp->tok), tcp->tok)) |
| 1236 | return -ENOBUFS; |
| 1237 | |
| 1238 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1239 | tcp->data_interval_max)) |
| 1240 | return -ENOBUFS; |
| 1241 | |
| 1242 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1243 | tcp->wake_payload_max)) |
| 1244 | return -ENOBUFS; |
| 1245 | |
| 1246 | nla_nest_end(msg, nl_tcp); |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1250 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1251 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1252 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1253 | { |
| 1254 | struct nlattr *nl_wowlan; |
| 1255 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1256 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1257 | return 0; |
| 1258 | |
| 1259 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1260 | if (!nl_wowlan) |
| 1261 | return -ENOBUFS; |
| 1262 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1263 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1264 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1265 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1266 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1267 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1268 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1269 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1270 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1271 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1272 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1273 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1274 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1275 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1276 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1277 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1278 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1279 | return -ENOBUFS; |
| 1280 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1281 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1282 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1283 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1284 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1285 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1286 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1287 | }; |
| 1288 | |
| 1289 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1290 | sizeof(pat), &pat)) |
| 1291 | return -ENOBUFS; |
| 1292 | } |
| 1293 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1294 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1295 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1296 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1297 | return -ENOBUFS; |
| 1298 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1299 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1300 | return -ENOBUFS; |
| 1301 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1302 | nla_nest_end(msg, nl_wowlan); |
| 1303 | |
| 1304 | return 0; |
| 1305 | } |
| 1306 | #endif |
| 1307 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1308 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1309 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1310 | { |
| 1311 | struct nl80211_coalesce_rule_support rule; |
| 1312 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1313 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1314 | return 0; |
| 1315 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1316 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1317 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1318 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1319 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1320 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1321 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1322 | |
| 1323 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1324 | return -ENOBUFS; |
| 1325 | |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1329 | static int |
| 1330 | nl80211_send_iftype_data(struct sk_buff *msg, |
| 1331 | const struct ieee80211_sband_iftype_data *iftdata) |
| 1332 | { |
| 1333 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; |
| 1334 | |
| 1335 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, |
| 1336 | iftdata->types_mask)) |
| 1337 | return -ENOBUFS; |
| 1338 | |
| 1339 | if (he_cap->has_he) { |
| 1340 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, |
| 1341 | sizeof(he_cap->he_cap_elem.mac_cap_info), |
| 1342 | he_cap->he_cap_elem.mac_cap_info) || |
| 1343 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, |
| 1344 | sizeof(he_cap->he_cap_elem.phy_cap_info), |
| 1345 | he_cap->he_cap_elem.phy_cap_info) || |
| 1346 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, |
| 1347 | sizeof(he_cap->he_mcs_nss_supp), |
| 1348 | &he_cap->he_mcs_nss_supp) || |
| 1349 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, |
| 1350 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) |
| 1351 | return -ENOBUFS; |
| 1352 | } |
| 1353 | |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1358 | struct ieee80211_supported_band *sband) |
| 1359 | { |
| 1360 | struct nlattr *nl_rates, *nl_rate; |
| 1361 | struct ieee80211_rate *rate; |
| 1362 | int i; |
| 1363 | |
| 1364 | /* add HT info */ |
| 1365 | if (sband->ht_cap.ht_supported && |
| 1366 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1367 | sizeof(sband->ht_cap.mcs), |
| 1368 | &sband->ht_cap.mcs) || |
| 1369 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1370 | sband->ht_cap.cap) || |
| 1371 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1372 | sband->ht_cap.ampdu_factor) || |
| 1373 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1374 | sband->ht_cap.ampdu_density))) |
| 1375 | return -ENOBUFS; |
| 1376 | |
| 1377 | /* add VHT info */ |
| 1378 | if (sband->vht_cap.vht_supported && |
| 1379 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1380 | sizeof(sband->vht_cap.vht_mcs), |
| 1381 | &sband->vht_cap.vht_mcs) || |
| 1382 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1383 | sband->vht_cap.cap))) |
| 1384 | return -ENOBUFS; |
| 1385 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1386 | if (sband->n_iftype_data) { |
| 1387 | struct nlattr *nl_iftype_data = |
| 1388 | nla_nest_start(msg, NL80211_BAND_ATTR_IFTYPE_DATA); |
| 1389 | int err; |
| 1390 | |
| 1391 | if (!nl_iftype_data) |
| 1392 | return -ENOBUFS; |
| 1393 | |
| 1394 | for (i = 0; i < sband->n_iftype_data; i++) { |
| 1395 | struct nlattr *iftdata; |
| 1396 | |
| 1397 | iftdata = nla_nest_start(msg, i + 1); |
| 1398 | if (!iftdata) |
| 1399 | return -ENOBUFS; |
| 1400 | |
| 1401 | err = nl80211_send_iftype_data(msg, |
| 1402 | &sband->iftype_data[i]); |
| 1403 | if (err) |
| 1404 | return err; |
| 1405 | |
| 1406 | nla_nest_end(msg, iftdata); |
| 1407 | } |
| 1408 | |
| 1409 | nla_nest_end(msg, nl_iftype_data); |
| 1410 | } |
| 1411 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1412 | /* add bitrates */ |
| 1413 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1414 | if (!nl_rates) |
| 1415 | return -ENOBUFS; |
| 1416 | |
| 1417 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1418 | nl_rate = nla_nest_start(msg, i); |
| 1419 | if (!nl_rate) |
| 1420 | return -ENOBUFS; |
| 1421 | |
| 1422 | rate = &sband->bitrates[i]; |
| 1423 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1424 | rate->bitrate)) |
| 1425 | return -ENOBUFS; |
| 1426 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1427 | nla_put_flag(msg, |
| 1428 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1429 | return -ENOBUFS; |
| 1430 | |
| 1431 | nla_nest_end(msg, nl_rate); |
| 1432 | } |
| 1433 | |
| 1434 | nla_nest_end(msg, nl_rates); |
| 1435 | |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | static int |
| 1440 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1441 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1442 | { |
| 1443 | u16 stypes; |
| 1444 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1445 | enum nl80211_iftype ift; |
| 1446 | int i; |
| 1447 | |
| 1448 | if (!mgmt_stypes) |
| 1449 | return 0; |
| 1450 | |
| 1451 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1452 | if (!nl_ifs) |
| 1453 | return -ENOBUFS; |
| 1454 | |
| 1455 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1456 | nl_ftypes = nla_nest_start(msg, ift); |
| 1457 | if (!nl_ftypes) |
| 1458 | return -ENOBUFS; |
| 1459 | i = 0; |
| 1460 | stypes = mgmt_stypes[ift].tx; |
| 1461 | while (stypes) { |
| 1462 | if ((stypes & 1) && |
| 1463 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1464 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1465 | return -ENOBUFS; |
| 1466 | stypes >>= 1; |
| 1467 | i++; |
| 1468 | } |
| 1469 | nla_nest_end(msg, nl_ftypes); |
| 1470 | } |
| 1471 | |
| 1472 | nla_nest_end(msg, nl_ifs); |
| 1473 | |
| 1474 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1475 | if (!nl_ifs) |
| 1476 | return -ENOBUFS; |
| 1477 | |
| 1478 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1479 | nl_ftypes = nla_nest_start(msg, ift); |
| 1480 | if (!nl_ftypes) |
| 1481 | return -ENOBUFS; |
| 1482 | i = 0; |
| 1483 | stypes = mgmt_stypes[ift].rx; |
| 1484 | while (stypes) { |
| 1485 | if ((stypes & 1) && |
| 1486 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1487 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1488 | return -ENOBUFS; |
| 1489 | stypes >>= 1; |
| 1490 | i++; |
| 1491 | } |
| 1492 | nla_nest_end(msg, nl_ftypes); |
| 1493 | } |
| 1494 | nla_nest_end(msg, nl_ifs); |
| 1495 | |
| 1496 | return 0; |
| 1497 | } |
| 1498 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1499 | #define CMD(op, n) \ |
| 1500 | do { \ |
| 1501 | if (rdev->ops->op) { \ |
| 1502 | i++; \ |
| 1503 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1504 | goto nla_put_failure; \ |
| 1505 | } \ |
| 1506 | } while (0) |
| 1507 | |
| 1508 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1509 | struct sk_buff *msg) |
| 1510 | { |
| 1511 | int i = 0; |
| 1512 | |
| 1513 | /* |
| 1514 | * do *NOT* add anything into this function, new things need to be |
| 1515 | * advertised only to new versions of userspace that can deal with |
| 1516 | * the split (and they can't possibly care about new features... |
| 1517 | */ |
| 1518 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1519 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1520 | CMD(add_key, NEW_KEY); |
| 1521 | CMD(start_ap, START_AP); |
| 1522 | CMD(add_station, NEW_STATION); |
| 1523 | CMD(add_mpath, NEW_MPATH); |
| 1524 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1525 | CMD(change_bss, SET_BSS); |
| 1526 | CMD(auth, AUTHENTICATE); |
| 1527 | CMD(assoc, ASSOCIATE); |
| 1528 | CMD(deauth, DEAUTHENTICATE); |
| 1529 | CMD(disassoc, DISASSOCIATE); |
| 1530 | CMD(join_ibss, JOIN_IBSS); |
| 1531 | CMD(join_mesh, JOIN_MESH); |
| 1532 | CMD(set_pmksa, SET_PMKSA); |
| 1533 | CMD(del_pmksa, DEL_PMKSA); |
| 1534 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1535 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1536 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1537 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1538 | CMD(mgmt_tx, FRAME); |
| 1539 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1540 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1541 | i++; |
| 1542 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1543 | goto nla_put_failure; |
| 1544 | } |
| 1545 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1546 | rdev->ops->join_mesh) { |
| 1547 | i++; |
| 1548 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1549 | goto nla_put_failure; |
| 1550 | } |
| 1551 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1552 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1553 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1554 | CMD(tdls_oper, TDLS_OPER); |
| 1555 | } |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1556 | if (rdev->wiphy.max_sched_scan_reqs) |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1557 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1558 | CMD(probe_client, PROBE_CLIENT); |
| 1559 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1560 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1561 | i++; |
| 1562 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1563 | goto nla_put_failure; |
| 1564 | } |
| 1565 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1566 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1567 | #ifdef CONFIG_NL80211_TESTMODE |
| 1568 | CMD(testmode_cmd, TESTMODE); |
| 1569 | #endif |
| 1570 | |
| 1571 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1572 | i++; |
| 1573 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1574 | goto nla_put_failure; |
| 1575 | } |
| 1576 | |
| 1577 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1578 | i++; |
| 1579 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1580 | goto nla_put_failure; |
| 1581 | } |
| 1582 | |
| 1583 | return i; |
| 1584 | nla_put_failure: |
| 1585 | return -ENOBUFS; |
| 1586 | } |
| 1587 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1588 | struct nl80211_dump_wiphy_state { |
| 1589 | s64 filter_wiphy; |
| 1590 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1591 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1592 | bool split; |
| 1593 | }; |
| 1594 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1595 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1596 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1597 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1598 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1599 | { |
| 1600 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1601 | struct nlattr *nl_bands, *nl_band; |
| 1602 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1603 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1604 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1605 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1606 | int i; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1607 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1608 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1609 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1610 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1611 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1612 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1613 | return -ENOBUFS; |
| 1614 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1615 | if (WARN_ON(!state)) |
| 1616 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1617 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1618 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1619 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1620 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1621 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1622 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1623 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1624 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1625 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1626 | goto finish; |
| 1627 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1628 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | case 0: |
| 1630 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1631 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1632 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1633 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1634 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1635 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1636 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1637 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1638 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1639 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1640 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1641 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1642 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1643 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1644 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1645 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1646 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1647 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1648 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1649 | rdev->wiphy.max_match_sets) || |
| 1650 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1651 | rdev->wiphy.max_sched_scan_plans) || |
| 1652 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1653 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1654 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1655 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1656 | goto nla_put_failure; |
| 1657 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1658 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1659 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1660 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1661 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1662 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1663 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1664 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1665 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1666 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1667 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1668 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1669 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1670 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1671 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1672 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1673 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1674 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1675 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1676 | state->split_start++; |
| 1677 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1678 | break; |
| 1679 | case 1: |
| 1680 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1681 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1682 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1683 | goto nla_put_failure; |
| 1684 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1685 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1686 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1687 | goto nla_put_failure; |
| 1688 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1689 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1690 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1691 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1692 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1693 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1694 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1695 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1696 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1697 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1698 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1699 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1700 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1701 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1702 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1703 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1704 | if ((rdev->wiphy.available_antennas_tx || |
| 1705 | rdev->wiphy.available_antennas_rx) && |
| 1706 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1707 | u32 tx_ant = 0, rx_ant = 0; |
| 1708 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1709 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1710 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1711 | if (!res) { |
| 1712 | if (nla_put_u32(msg, |
| 1713 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1714 | tx_ant) || |
| 1715 | nla_put_u32(msg, |
| 1716 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1717 | rx_ant)) |
| 1718 | goto nla_put_failure; |
| 1719 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1720 | } |
| 1721 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1722 | state->split_start++; |
| 1723 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1724 | break; |
| 1725 | case 2: |
| 1726 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1727 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1728 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1729 | state->split_start++; |
| 1730 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1731 | break; |
| 1732 | case 3: |
| 1733 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1734 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1735 | goto nla_put_failure; |
| 1736 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1737 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1738 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1739 | struct ieee80211_supported_band *sband; |
| 1740 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1741 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1742 | |
| 1743 | if (!sband) |
| 1744 | continue; |
| 1745 | |
| 1746 | nl_band = nla_nest_start(msg, band); |
| 1747 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1748 | goto nla_put_failure; |
| 1749 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1750 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1751 | case 0: |
| 1752 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1753 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1754 | state->chan_start++; |
| 1755 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1756 | break; |
| 1757 | default: |
| 1758 | /* add frequencies */ |
| 1759 | nl_freqs = nla_nest_start( |
| 1760 | msg, NL80211_BAND_ATTR_FREQS); |
| 1761 | if (!nl_freqs) |
| 1762 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1763 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1764 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1765 | i < sband->n_channels; |
| 1766 | i++) { |
| 1767 | nl_freq = nla_nest_start(msg, i); |
| 1768 | if (!nl_freq) |
| 1769 | goto nla_put_failure; |
| 1770 | |
| 1771 | chan = &sband->channels[i]; |
| 1772 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1773 | if (nl80211_msg_put_channel( |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1774 | msg, &rdev->wiphy, chan, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1775 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1776 | goto nla_put_failure; |
| 1777 | |
| 1778 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1779 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1780 | break; |
| 1781 | } |
| 1782 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1783 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1784 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1785 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1786 | nla_nest_end(msg, nl_freqs); |
| 1787 | } |
| 1788 | |
| 1789 | nla_nest_end(msg, nl_band); |
| 1790 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1791 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1792 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1793 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1794 | band--; |
| 1795 | break; |
| 1796 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1797 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1798 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1799 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1800 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1801 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1802 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1803 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1804 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1805 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1806 | if (state->band_start == 0 && state->chan_start == 0) |
| 1807 | state->split_start++; |
| 1808 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1809 | break; |
| 1810 | case 4: |
| 1811 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1812 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1813 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1814 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1815 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 1816 | if (i < 0) |
| 1817 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1818 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1819 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1820 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1821 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1822 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1823 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1824 | if (rdev->wiphy.features & |
| 1825 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1826 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 1827 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 1828 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1829 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1830 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1831 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1832 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1833 | state->split_start++; |
| 1834 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1835 | break; |
| 1836 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1837 | if (rdev->ops->remain_on_channel && |
| 1838 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1839 | nla_put_u32(msg, |
| 1840 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1841 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1842 | goto nla_put_failure; |
| 1843 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1844 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1845 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1846 | goto nla_put_failure; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1847 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1848 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1849 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1850 | state->split_start++; |
| 1851 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1852 | break; |
| 1853 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1854 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1855 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1856 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1857 | state->split_start++; |
| 1858 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1859 | break; |
| 1860 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1861 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1862 | #endif |
| 1863 | case 7: |
| 1864 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1865 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1866 | goto nla_put_failure; |
| 1867 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1868 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1869 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1870 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1871 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1872 | state->split_start++; |
| 1873 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1874 | break; |
| 1875 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1876 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1877 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1878 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1879 | goto nla_put_failure; |
| 1880 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1881 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1882 | /* |
| 1883 | * We can only add the per-channel limit information if the |
| 1884 | * dump is split, otherwise it makes it too big. Therefore |
| 1885 | * only advertise it in that case. |
| 1886 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1887 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1888 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1889 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1890 | goto nla_put_failure; |
| 1891 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1892 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1893 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1894 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1895 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1896 | goto nla_put_failure; |
| 1897 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1898 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1899 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1900 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1901 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1902 | goto nla_put_failure; |
| 1903 | |
| 1904 | /* |
| 1905 | * Any information below this point is only available to |
| 1906 | * applications that can deal with it being split. This |
| 1907 | * helps ensure that newly added capabilities don't break |
| 1908 | * older tools by overrunning their buffers. |
| 1909 | * |
| 1910 | * We still increment split_start so that in the split |
| 1911 | * case we'll continue with more data in the next round, |
| 1912 | * but break unconditionally so unsplit data stops here. |
| 1913 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1914 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1915 | break; |
| 1916 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1917 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1918 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1919 | rdev->wiphy.extended_capabilities_len, |
| 1920 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1921 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1922 | rdev->wiphy.extended_capabilities_len, |
| 1923 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1924 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1925 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1926 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1927 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1928 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1929 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1930 | goto nla_put_failure; |
| 1931 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1932 | state->split_start++; |
| 1933 | break; |
| 1934 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1935 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1936 | goto nla_put_failure; |
| 1937 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1938 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1939 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1940 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1941 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1942 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1943 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1944 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1945 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1946 | goto nla_put_failure; |
| 1947 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1948 | state->split_start++; |
| 1949 | break; |
| 1950 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1951 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1952 | const struct nl80211_vendor_cmd_info *info; |
| 1953 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1954 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1955 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1956 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1957 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1958 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1959 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1960 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1961 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1962 | goto nla_put_failure; |
| 1963 | } |
| 1964 | nla_nest_end(msg, nested); |
| 1965 | } |
| 1966 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1967 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1968 | const struct nl80211_vendor_cmd_info *info; |
| 1969 | struct nlattr *nested; |
| 1970 | |
| 1971 | nested = nla_nest_start(msg, |
| 1972 | NL80211_ATTR_VENDOR_EVENTS); |
| 1973 | if (!nested) |
| 1974 | goto nla_put_failure; |
| 1975 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1976 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1977 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1978 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1979 | goto nla_put_failure; |
| 1980 | } |
| 1981 | nla_nest_end(msg, nested); |
| 1982 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1983 | state->split_start++; |
| 1984 | break; |
| 1985 | case 12: |
| 1986 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1987 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1988 | rdev->wiphy.max_num_csa_counters)) |
| 1989 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1990 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1991 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1992 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1993 | goto nla_put_failure; |
| 1994 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1995 | if (rdev->wiphy.max_sched_scan_reqs && |
| 1996 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, |
| 1997 | rdev->wiphy.max_sched_scan_reqs)) |
| 1998 | goto nla_put_failure; |
| 1999 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 2000 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 2001 | sizeof(rdev->wiphy.ext_features), |
| 2002 | rdev->wiphy.ext_features)) |
| 2003 | goto nla_put_failure; |
| 2004 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2005 | if (rdev->wiphy.bss_select_support) { |
| 2006 | struct nlattr *nested; |
| 2007 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 2008 | |
| 2009 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 2010 | if (!nested) |
| 2011 | goto nla_put_failure; |
| 2012 | |
| 2013 | i = 0; |
| 2014 | while (bss_select_support) { |
| 2015 | if ((bss_select_support & 1) && |
| 2016 | nla_put_flag(msg, i)) |
| 2017 | goto nla_put_failure; |
| 2018 | i++; |
| 2019 | bss_select_support >>= 1; |
| 2020 | } |
| 2021 | nla_nest_end(msg, nested); |
| 2022 | } |
| 2023 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2024 | state->split_start++; |
| 2025 | break; |
| 2026 | case 13: |
| 2027 | if (rdev->wiphy.num_iftype_ext_capab && |
| 2028 | rdev->wiphy.iftype_ext_capab) { |
| 2029 | struct nlattr *nested_ext_capab, *nested; |
| 2030 | |
| 2031 | nested = nla_nest_start(msg, |
| 2032 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 2033 | if (!nested) |
| 2034 | goto nla_put_failure; |
| 2035 | |
| 2036 | for (i = state->capa_start; |
| 2037 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 2038 | const struct wiphy_iftype_ext_capab *capab; |
| 2039 | |
| 2040 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 2041 | |
| 2042 | nested_ext_capab = nla_nest_start(msg, i); |
| 2043 | if (!nested_ext_capab || |
| 2044 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 2045 | capab->iftype) || |
| 2046 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 2047 | capab->extended_capabilities_len, |
| 2048 | capab->extended_capabilities) || |
| 2049 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 2050 | capab->extended_capabilities_len, |
| 2051 | capab->extended_capabilities_mask)) |
| 2052 | goto nla_put_failure; |
| 2053 | |
| 2054 | nla_nest_end(msg, nested_ext_capab); |
| 2055 | if (state->split) |
| 2056 | break; |
| 2057 | } |
| 2058 | nla_nest_end(msg, nested); |
| 2059 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 2060 | state->capa_start = i + 1; |
| 2061 | break; |
| 2062 | } |
| 2063 | } |
| 2064 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 2065 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 2066 | rdev->wiphy.nan_supported_bands)) |
| 2067 | goto nla_put_failure; |
| 2068 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2069 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 2070 | NL80211_EXT_FEATURE_TXQS)) { |
| 2071 | struct cfg80211_txq_stats txqstats = {}; |
| 2072 | int res; |
| 2073 | |
| 2074 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); |
| 2075 | if (!res && |
| 2076 | !nl80211_put_txq_stats(msg, &txqstats, |
| 2077 | NL80211_ATTR_TXQ_STATS)) |
| 2078 | goto nla_put_failure; |
| 2079 | |
| 2080 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, |
| 2081 | rdev->wiphy.txq_limit)) |
| 2082 | goto nla_put_failure; |
| 2083 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, |
| 2084 | rdev->wiphy.txq_memory_limit)) |
| 2085 | goto nla_put_failure; |
| 2086 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, |
| 2087 | rdev->wiphy.txq_quantum)) |
| 2088 | goto nla_put_failure; |
| 2089 | } |
| 2090 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2091 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2092 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2093 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2094 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2095 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2096 | genlmsg_end(msg, hdr); |
| 2097 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2098 | |
| 2099 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2100 | genlmsg_cancel(msg, hdr); |
| 2101 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2102 | } |
| 2103 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2104 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 2105 | struct netlink_callback *cb, |
| 2106 | struct nl80211_dump_wiphy_state *state) |
| 2107 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 2108 | struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 2109 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb, |
| 2110 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2111 | /* ignore parse errors for backward compatibility */ |
| 2112 | if (ret) |
| 2113 | return 0; |
| 2114 | |
| 2115 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 2116 | if (tb[NL80211_ATTR_WIPHY]) |
| 2117 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 2118 | if (tb[NL80211_ATTR_WDEV]) |
| 2119 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 2120 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 2121 | struct net_device *netdev; |
| 2122 | struct cfg80211_registered_device *rdev; |
| 2123 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 2124 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2125 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2126 | if (!netdev) |
| 2127 | return -ENODEV; |
| 2128 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2129 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2130 | netdev->ieee80211_ptr->wiphy); |
| 2131 | state->filter_wiphy = rdev->wiphy_idx; |
| 2132 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | return 0; |
| 2136 | } |
| 2137 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2138 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 2139 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2140 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2141 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2142 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 2143 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2144 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2145 | if (!state) { |
| 2146 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 2147 | if (!state) { |
| 2148 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2149 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2150 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2151 | state->filter_wiphy = -1; |
| 2152 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 2153 | if (ret) { |
| 2154 | kfree(state); |
| 2155 | rtnl_unlock(); |
| 2156 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2157 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2158 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2159 | } |
| 2160 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2161 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2162 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2163 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2164 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2165 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2166 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2167 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2168 | continue; |
| 2169 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 2170 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2171 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 2172 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2173 | NETLINK_CB(cb->skb).portid, |
| 2174 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2175 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2176 | if (ret < 0) { |
| 2177 | /* |
| 2178 | * If sending the wiphy data didn't fit (ENOBUFS |
| 2179 | * or EMSGSIZE returned), this SKB is still |
| 2180 | * empty (so it's not too big because another |
| 2181 | * wiphy dataset is already in the skb) and |
| 2182 | * we've not tried to adjust the dump allocation |
| 2183 | * yet ... then adjust the alloc size to be |
| 2184 | * bigger, and return 1 but with the empty skb. |
| 2185 | * This results in an empty message being RX'ed |
| 2186 | * in userspace, but that is ignored. |
| 2187 | * |
| 2188 | * We can then retry with the larger buffer. |
| 2189 | */ |
| 2190 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2191 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2192 | cb->min_dump_alloc < 4096) { |
| 2193 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2194 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 2195 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2196 | return 1; |
| 2197 | } |
| 2198 | idx--; |
| 2199 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2200 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2201 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2202 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2203 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2204 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2205 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2206 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2207 | |
| 2208 | return skb->len; |
| 2209 | } |
| 2210 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2211 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2212 | { |
| 2213 | kfree((void *)cb->args[0]); |
| 2214 | return 0; |
| 2215 | } |
| 2216 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2217 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2218 | { |
| 2219 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2221 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2222 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2223 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2224 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2225 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2226 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2227 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2228 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2229 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2230 | nlmsg_free(msg); |
| 2231 | return -ENOBUFS; |
| 2232 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2233 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2234 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2235 | } |
| 2236 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2237 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2238 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2239 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2240 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2241 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2242 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2243 | }; |
| 2244 | |
| 2245 | static int parse_txq_params(struct nlattr *tb[], |
| 2246 | struct ieee80211_txq_params *txq_params) |
| 2247 | { |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2248 | u8 ac; |
| 2249 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2250 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2251 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2252 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2253 | return -EINVAL; |
| 2254 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2255 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2256 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2257 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2258 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2259 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2260 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2261 | if (ac >= NL80211_NUM_ACS) |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2262 | return -EINVAL; |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2263 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2264 | return 0; |
| 2265 | } |
| 2266 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2267 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2268 | { |
| 2269 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2270 | * You can only set the channel explicitly for WDS interfaces, |
| 2271 | * all others have their channel managed via their respective |
| 2272 | * "establish a connection" command (connect, join, ...) |
| 2273 | * |
| 2274 | * For AP/GO and mesh mode, the channel can be set with the |
| 2275 | * channel userspace API, but is only stored and passed to the |
| 2276 | * low-level driver when the AP starts or the mesh is joined. |
| 2277 | * This is for backward compatibility, userspace can also give |
| 2278 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2279 | * |
| 2280 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2281 | * whatever else is going on, so they have their own special |
| 2282 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2283 | */ |
| 2284 | return !wdev || |
| 2285 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2286 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2287 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2288 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2289 | } |
| 2290 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2291 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2292 | struct genl_info *info, |
| 2293 | struct cfg80211_chan_def *chandef) |
| 2294 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2295 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2296 | |
| 2297 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 2298 | return -EINVAL; |
| 2299 | |
| 2300 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 2301 | |
| 2302 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2303 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2304 | chandef->center_freq1 = control_freq; |
| 2305 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2306 | |
| 2307 | /* Primary channel not allowed */ |
| 2308 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 2309 | return -EINVAL; |
| 2310 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2311 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2312 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2313 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2314 | chantype = nla_get_u32( |
| 2315 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2316 | |
| 2317 | switch (chantype) { |
| 2318 | case NL80211_CHAN_NO_HT: |
| 2319 | case NL80211_CHAN_HT20: |
| 2320 | case NL80211_CHAN_HT40PLUS: |
| 2321 | case NL80211_CHAN_HT40MINUS: |
| 2322 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2323 | chantype); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2324 | /* user input for center_freq is incorrect */ |
| 2325 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1] && |
| 2326 | chandef->center_freq1 != nla_get_u32( |
| 2327 | info->attrs[NL80211_ATTR_CENTER_FREQ1])) |
| 2328 | return -EINVAL; |
| 2329 | /* center_freq2 must be zero */ |
| 2330 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2] && |
| 2331 | nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2])) |
| 2332 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2333 | break; |
| 2334 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2335 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2336 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2337 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2338 | chandef->width = |
| 2339 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2340 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2341 | chandef->center_freq1 = |
| 2342 | nla_get_u32( |
| 2343 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2344 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2345 | chandef->center_freq2 = |
| 2346 | nla_get_u32( |
| 2347 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2348 | } |
| 2349 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2350 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2351 | return -EINVAL; |
| 2352 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2353 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2354 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2355 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2356 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2357 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2358 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2359 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2360 | return -EINVAL; |
| 2361 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2362 | return 0; |
| 2363 | } |
| 2364 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2365 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2366 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2367 | struct genl_info *info) |
| 2368 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2369 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2370 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2371 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2372 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2373 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2374 | if (dev) |
| 2375 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2376 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2377 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2378 | if (wdev) |
| 2379 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2380 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2381 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2382 | if (result) |
| 2383 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2384 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2385 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2386 | case NL80211_IFTYPE_AP: |
| 2387 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2388 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2389 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2390 | result = -EINVAL; |
| 2391 | break; |
| 2392 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2393 | if (wdev->beacon_interval) { |
| 2394 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2395 | !(rdev->wiphy.features & |
| 2396 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2397 | result = -EBUSY; |
| 2398 | break; |
| 2399 | } |
| 2400 | |
| 2401 | /* Only allow dynamic channel width changes */ |
| 2402 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2403 | result = -EBUSY; |
| 2404 | break; |
| 2405 | } |
| 2406 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2407 | if (result) |
| 2408 | break; |
| 2409 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2410 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2411 | result = 0; |
| 2412 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2413 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2414 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2415 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2416 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2417 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2418 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2419 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2420 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2421 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2422 | |
| 2423 | return result; |
| 2424 | } |
| 2425 | |
| 2426 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2427 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2428 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2429 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2430 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2431 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2432 | } |
| 2433 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2434 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2435 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2437 | struct net_device *dev = info->user_ptr[1]; |
| 2438 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2439 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2440 | |
| 2441 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2442 | return -EINVAL; |
| 2443 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2444 | if (netif_running(dev)) |
| 2445 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2446 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2447 | if (!rdev->ops->set_wds_peer) |
| 2448 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2449 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2450 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2451 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2452 | |
| 2453 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2454 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2455 | } |
| 2456 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2457 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2458 | { |
| 2459 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2460 | struct net_device *netdev = NULL; |
| 2461 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2462 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2463 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2464 | u32 changed; |
| 2465 | u8 retry_short = 0, retry_long = 0; |
| 2466 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2467 | u8 coverage_class = 0; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2468 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2469 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2470 | ASSERT_RTNL(); |
| 2471 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2472 | /* |
| 2473 | * Try to find the wiphy and netdev. Normally this |
| 2474 | * function shouldn't need the netdev, but this is |
| 2475 | * done for backward compatibility -- previously |
| 2476 | * setting the channel was done per wiphy, but now |
| 2477 | * it is per netdev. Previous userland like hostapd |
| 2478 | * also passed a netdev to set_wiphy, so that it is |
| 2479 | * possible to let that go to the right netdev! |
| 2480 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2481 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2482 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2483 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2484 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2485 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2486 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2487 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2488 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2489 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2490 | } |
| 2491 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2492 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2493 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2494 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2495 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2496 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2497 | wdev = NULL; |
| 2498 | netdev = NULL; |
| 2499 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2500 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2501 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2502 | |
| 2503 | /* |
| 2504 | * end workaround code, by now the rdev is available |
| 2505 | * and locked, and wdev may or may not be NULL. |
| 2506 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2507 | |
| 2508 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2509 | result = cfg80211_dev_rename( |
| 2510 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2511 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2512 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2513 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2514 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2515 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2516 | struct ieee80211_txq_params txq_params; |
| 2517 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2518 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2519 | if (!rdev->ops->set_txq_params) |
| 2520 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2521 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2522 | if (!netdev) |
| 2523 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2524 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2525 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2526 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2527 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2528 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2529 | if (!netif_running(netdev)) |
| 2530 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2531 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2532 | nla_for_each_nested(nl_txq_params, |
| 2533 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2534 | rem_txq_params) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 2535 | result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX, |
| 2536 | nl_txq_params, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 2537 | txq_params_policy, |
| 2538 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2539 | if (result) |
| 2540 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2541 | result = parse_txq_params(tb, &txq_params); |
| 2542 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2543 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2544 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2545 | result = rdev_set_txq_params(rdev, netdev, |
| 2546 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2547 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2548 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2549 | } |
| 2550 | } |
| 2551 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2552 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2553 | result = __nl80211_set_channel( |
| 2554 | rdev, |
| 2555 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2556 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2557 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2558 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2559 | } |
| 2560 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2561 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2562 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2563 | enum nl80211_tx_power_setting type; |
| 2564 | int idx, mbm = 0; |
| 2565 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2566 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2567 | txp_wdev = NULL; |
| 2568 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2569 | if (!rdev->ops->set_tx_power) |
| 2570 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2571 | |
| 2572 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2573 | type = nla_get_u32(info->attrs[idx]); |
| 2574 | |
| 2575 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2576 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2577 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2578 | |
| 2579 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2580 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2581 | mbm = nla_get_u32(info->attrs[idx]); |
| 2582 | } |
| 2583 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2584 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2585 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2586 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2587 | } |
| 2588 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2589 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2590 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2591 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2592 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2593 | if ((!rdev->wiphy.available_antennas_tx && |
| 2594 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2595 | !rdev->ops->set_antenna) |
| 2596 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2597 | |
| 2598 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2599 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2600 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2601 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2602 | * available antenna masks, except for the "all" mask */ |
| 2603 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2604 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2605 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2606 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2607 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2608 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2609 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2610 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2611 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2612 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2613 | } |
| 2614 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2615 | changed = 0; |
| 2616 | |
| 2617 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2618 | retry_short = nla_get_u8( |
| 2619 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2620 | if (retry_short == 0) |
| 2621 | return -EINVAL; |
| 2622 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2623 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2624 | } |
| 2625 | |
| 2626 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2627 | retry_long = nla_get_u8( |
| 2628 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2629 | if (retry_long == 0) |
| 2630 | return -EINVAL; |
| 2631 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2632 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2633 | } |
| 2634 | |
| 2635 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2636 | frag_threshold = nla_get_u32( |
| 2637 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2638 | if (frag_threshold < 256) |
| 2639 | return -EINVAL; |
| 2640 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2641 | if (frag_threshold != (u32) -1) { |
| 2642 | /* |
| 2643 | * Fragments (apart from the last one) are required to |
| 2644 | * have even length. Make the fragmentation code |
| 2645 | * simpler by stripping LSB should someone try to use |
| 2646 | * odd threshold value. |
| 2647 | */ |
| 2648 | frag_threshold &= ~0x1; |
| 2649 | } |
| 2650 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2651 | } |
| 2652 | |
| 2653 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2654 | rts_threshold = nla_get_u32( |
| 2655 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2656 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2657 | } |
| 2658 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2659 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2660 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2661 | return -EINVAL; |
| 2662 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2663 | coverage_class = nla_get_u8( |
| 2664 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2665 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2666 | } |
| 2667 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2668 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2669 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2670 | return -EOPNOTSUPP; |
| 2671 | |
| 2672 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2673 | } |
| 2674 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2675 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { |
| 2676 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 2677 | NL80211_EXT_FEATURE_TXQS)) |
| 2678 | return -EOPNOTSUPP; |
| 2679 | txq_limit = nla_get_u32( |
| 2680 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); |
| 2681 | changed |= WIPHY_PARAM_TXQ_LIMIT; |
| 2682 | } |
| 2683 | |
| 2684 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { |
| 2685 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 2686 | NL80211_EXT_FEATURE_TXQS)) |
| 2687 | return -EOPNOTSUPP; |
| 2688 | txq_memory_limit = nla_get_u32( |
| 2689 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); |
| 2690 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; |
| 2691 | } |
| 2692 | |
| 2693 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { |
| 2694 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 2695 | NL80211_EXT_FEATURE_TXQS)) |
| 2696 | return -EOPNOTSUPP; |
| 2697 | txq_quantum = nla_get_u32( |
| 2698 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); |
| 2699 | changed |= WIPHY_PARAM_TXQ_QUANTUM; |
| 2700 | } |
| 2701 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2702 | if (changed) { |
| 2703 | u8 old_retry_short, old_retry_long; |
| 2704 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2705 | u8 old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2706 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2707 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2708 | if (!rdev->ops->set_wiphy_params) |
| 2709 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2710 | |
| 2711 | old_retry_short = rdev->wiphy.retry_short; |
| 2712 | old_retry_long = rdev->wiphy.retry_long; |
| 2713 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2714 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2715 | old_coverage_class = rdev->wiphy.coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2716 | old_txq_limit = rdev->wiphy.txq_limit; |
| 2717 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; |
| 2718 | old_txq_quantum = rdev->wiphy.txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2719 | |
| 2720 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2721 | rdev->wiphy.retry_short = retry_short; |
| 2722 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2723 | rdev->wiphy.retry_long = retry_long; |
| 2724 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2725 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2726 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2727 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2728 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2729 | rdev->wiphy.coverage_class = coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2730 | if (changed & WIPHY_PARAM_TXQ_LIMIT) |
| 2731 | rdev->wiphy.txq_limit = txq_limit; |
| 2732 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) |
| 2733 | rdev->wiphy.txq_memory_limit = txq_memory_limit; |
| 2734 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) |
| 2735 | rdev->wiphy.txq_quantum = txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2736 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2737 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2738 | if (result) { |
| 2739 | rdev->wiphy.retry_short = old_retry_short; |
| 2740 | rdev->wiphy.retry_long = old_retry_long; |
| 2741 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2742 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2743 | rdev->wiphy.coverage_class = old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2744 | rdev->wiphy.txq_limit = old_txq_limit; |
| 2745 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; |
| 2746 | rdev->wiphy.txq_quantum = old_txq_quantum; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2747 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2748 | } |
| 2749 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2750 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2751 | } |
| 2752 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2753 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2754 | { |
| 2755 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2756 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2757 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2758 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2759 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2760 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2761 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2762 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2763 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2764 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2765 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2766 | chandef->chan->center_freq)) |
| 2767 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2768 | switch (chandef->width) { |
| 2769 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2770 | case NL80211_CHAN_WIDTH_20: |
| 2771 | case NL80211_CHAN_WIDTH_40: |
| 2772 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2773 | cfg80211_get_chandef_type(chandef))) |
| 2774 | return -ENOBUFS; |
| 2775 | break; |
| 2776 | default: |
| 2777 | break; |
| 2778 | } |
| 2779 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2780 | return -ENOBUFS; |
| 2781 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2782 | return -ENOBUFS; |
| 2783 | if (chandef->center_freq2 && |
| 2784 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2785 | return -ENOBUFS; |
| 2786 | return 0; |
| 2787 | } |
| 2788 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2789 | 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] | 2790 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2791 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2792 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2793 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2794 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2795 | void *hdr; |
| 2796 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2797 | if (removal) |
| 2798 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2799 | |
| 2800 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2801 | if (!hdr) |
| 2802 | return -1; |
| 2803 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2804 | if (dev && |
| 2805 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2806 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2807 | goto nla_put_failure; |
| 2808 | |
| 2809 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2810 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2811 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2812 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2813 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2814 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2815 | rdev->devlist_generation ^ |
Antonio Quartulli | 446faa1 | 2018-06-14 09:43:06 +0800 | [diff] [blame] | 2816 | (cfg80211_rdev_list_generation << 2)) || |
| 2817 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2818 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2819 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2820 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2821 | int ret; |
| 2822 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2823 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2824 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2825 | if (ret == 0) { |
| 2826 | if (nl80211_send_chandef(msg, &chandef)) |
| 2827 | goto nla_put_failure; |
| 2828 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2829 | } |
| 2830 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2831 | if (rdev->ops->get_tx_power) { |
| 2832 | int dbm, ret; |
| 2833 | |
| 2834 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2835 | if (ret == 0 && |
| 2836 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2837 | DBM_TO_MBM(dbm))) |
| 2838 | goto nla_put_failure; |
| 2839 | } |
| 2840 | |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 2841 | wdev_lock(wdev); |
| 2842 | switch (wdev->iftype) { |
| 2843 | case NL80211_IFTYPE_AP: |
| 2844 | if (wdev->ssid_len && |
| 2845 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 2846 | goto nla_put_failure_locked; |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 2847 | break; |
| 2848 | case NL80211_IFTYPE_STATION: |
| 2849 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2850 | case NL80211_IFTYPE_ADHOC: { |
| 2851 | const u8 *ssid_ie; |
| 2852 | if (!wdev->current_bss) |
| 2853 | break; |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 2854 | rcu_read_lock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 2855 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 2856 | WLAN_EID_SSID); |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 2857 | if (ssid_ie && |
| 2858 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) |
| 2859 | goto nla_put_failure_rcu_locked; |
| 2860 | rcu_read_unlock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 2861 | break; |
| 2862 | } |
| 2863 | default: |
| 2864 | /* nothing */ |
| 2865 | break; |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2866 | } |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 2867 | wdev_unlock(wdev); |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2868 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2869 | if (rdev->ops->get_txq_stats) { |
| 2870 | struct cfg80211_txq_stats txqstats = {}; |
| 2871 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); |
| 2872 | |
| 2873 | if (ret == 0 && |
| 2874 | !nl80211_put_txq_stats(msg, &txqstats, |
| 2875 | NL80211_ATTR_TXQ_STATS)) |
| 2876 | goto nla_put_failure; |
| 2877 | } |
| 2878 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2879 | genlmsg_end(msg, hdr); |
| 2880 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2881 | |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 2882 | nla_put_failure_rcu_locked: |
| 2883 | rcu_read_unlock(); |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 2884 | nla_put_failure_locked: |
| 2885 | wdev_unlock(wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2886 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2887 | genlmsg_cancel(msg, hdr); |
| 2888 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2892 | { |
| 2893 | int wp_idx = 0; |
| 2894 | int if_idx = 0; |
| 2895 | int wp_start = cb->args[0]; |
| 2896 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2897 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2898 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2899 | struct wireless_dev *wdev; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2900 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2901 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2902 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2903 | if (!cb->args[2]) { |
| 2904 | struct nl80211_dump_wiphy_state state = { |
| 2905 | .filter_wiphy = -1, |
| 2906 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2907 | |
| 2908 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 2909 | if (ret) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2910 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2911 | |
| 2912 | filter_wiphy = state.filter_wiphy; |
| 2913 | |
| 2914 | /* |
| 2915 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 2916 | * value needed to determine that parsing is necessary. |
| 2917 | */ |
| 2918 | if (filter_wiphy >= 0) |
| 2919 | cb->args[2] = filter_wiphy + 1; |
| 2920 | else |
| 2921 | cb->args[2] = -1; |
| 2922 | } else if (cb->args[2] > 0) { |
| 2923 | filter_wiphy = cb->args[2] - 1; |
| 2924 | } |
| 2925 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2926 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2927 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2928 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2929 | if (wp_idx < wp_start) { |
| 2930 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2931 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2932 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2933 | |
| 2934 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 2935 | continue; |
| 2936 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2937 | if_idx = 0; |
| 2938 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2939 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2940 | if (if_idx < if_start) { |
| 2941 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2942 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2943 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2944 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2945 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2946 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2947 | goto out; |
| 2948 | } |
| 2949 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2950 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2951 | |
| 2952 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2953 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2954 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2955 | cb->args[0] = wp_idx; |
| 2956 | cb->args[1] = if_idx; |
| 2957 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2958 | ret = skb->len; |
| 2959 | out_unlock: |
| 2960 | rtnl_unlock(); |
| 2961 | |
| 2962 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2966 | { |
| 2967 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2969 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2970 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2971 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2972 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2973 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2974 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2975 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2976 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2977 | nlmsg_free(msg); |
| 2978 | return -ENOBUFS; |
| 2979 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2980 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2981 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2982 | } |
| 2983 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2984 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2985 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2986 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2987 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2988 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2989 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2990 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2991 | }; |
| 2992 | |
| 2993 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2994 | { |
| 2995 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2996 | int flag; |
| 2997 | |
| 2998 | *mntrflags = 0; |
| 2999 | |
| 3000 | if (!nla) |
| 3001 | return -EINVAL; |
| 3002 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 3003 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla, |
| 3004 | mntr_flags_policy, NULL)) |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3005 | return -EINVAL; |
| 3006 | |
| 3007 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 3008 | if (flags[flag]) |
| 3009 | *mntrflags |= (1<<flag); |
| 3010 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3011 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 3012 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3013 | return 0; |
| 3014 | } |
| 3015 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3016 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 3017 | enum nl80211_iftype type, |
| 3018 | struct genl_info *info, |
| 3019 | struct vif_params *params) |
| 3020 | { |
| 3021 | bool change = false; |
| 3022 | int err; |
| 3023 | |
| 3024 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 3025 | if (type != NL80211_IFTYPE_MONITOR) |
| 3026 | return -EINVAL; |
| 3027 | |
| 3028 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 3029 | ¶ms->flags); |
| 3030 | if (err) |
| 3031 | return err; |
| 3032 | |
| 3033 | change = true; |
| 3034 | } |
| 3035 | |
| 3036 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 3037 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 3038 | return -EOPNOTSUPP; |
| 3039 | |
| 3040 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 3041 | const u8 *mumimo_groups; |
| 3042 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3043 | |
| 3044 | if (type != NL80211_IFTYPE_MONITOR) |
| 3045 | return -EINVAL; |
| 3046 | |
| 3047 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3048 | return -EOPNOTSUPP; |
| 3049 | |
| 3050 | mumimo_groups = |
| 3051 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 3052 | |
| 3053 | /* bits 0 and 63 are reserved and must be zero */ |
Johannes Berg | 4954601 | 2017-04-27 09:13:38 +0200 | [diff] [blame] | 3054 | if ((mumimo_groups[0] & BIT(0)) || |
| 3055 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3056 | return -EINVAL; |
| 3057 | |
| 3058 | params->vht_mumimo_groups = mumimo_groups; |
| 3059 | change = true; |
| 3060 | } |
| 3061 | |
| 3062 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 3063 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3064 | |
| 3065 | if (type != NL80211_IFTYPE_MONITOR) |
| 3066 | return -EINVAL; |
| 3067 | |
| 3068 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3069 | return -EOPNOTSUPP; |
| 3070 | |
| 3071 | params->vht_mumimo_follow_addr = |
| 3072 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 3073 | change = true; |
| 3074 | } |
| 3075 | |
| 3076 | return change ? 1 : 0; |
| 3077 | } |
| 3078 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3079 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3080 | struct net_device *netdev, u8 use_4addr, |
| 3081 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3082 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3083 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 3084 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3085 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3086 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3087 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3088 | |
| 3089 | switch (iftype) { |
| 3090 | case NL80211_IFTYPE_AP_VLAN: |
| 3091 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 3092 | return 0; |
| 3093 | break; |
| 3094 | case NL80211_IFTYPE_STATION: |
| 3095 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 3096 | return 0; |
| 3097 | break; |
| 3098 | default: |
| 3099 | break; |
| 3100 | } |
| 3101 | |
| 3102 | return -EOPNOTSUPP; |
| 3103 | } |
| 3104 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3105 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 3106 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3107 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3108 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 3109 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3110 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3111 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3112 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3113 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3114 | memset(¶ms, 0, sizeof(params)); |
| 3115 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3116 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3117 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3118 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3119 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3120 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3121 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3122 | if (ntype > NL80211_IFTYPE_MAX) |
| 3123 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3124 | } |
| 3125 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 3126 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3127 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3128 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3129 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 3130 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3131 | if (netif_running(dev)) |
| 3132 | return -EBUSY; |
| 3133 | |
| 3134 | wdev_lock(wdev); |
| 3135 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3136 | IEEE80211_MAX_MESH_ID_LEN); |
| 3137 | wdev->mesh_id_up_len = |
| 3138 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3139 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3140 | wdev->mesh_id_up_len); |
| 3141 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3142 | } |
| 3143 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3144 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 3145 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 3146 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3147 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3148 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3149 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3150 | } else { |
| 3151 | params.use_4addr = -1; |
| 3152 | } |
| 3153 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3154 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 3155 | if (err < 0) |
| 3156 | return err; |
| 3157 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3158 | change = true; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3159 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3160 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3161 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3162 | else |
| 3163 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 3164 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3165 | if (!err && params.use_4addr != -1) |
| 3166 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 3167 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3168 | return err; |
| 3169 | } |
| 3170 | |
| 3171 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 3172 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3173 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3174 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3175 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 3176 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3177 | int err; |
| 3178 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 3179 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3180 | /* to avoid failing a new interface creation due to pending removal */ |
| 3181 | cfg80211_destroy_ifaces(rdev); |
| 3182 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3183 | memset(¶ms, 0, sizeof(params)); |
| 3184 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3185 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 3186 | return -EINVAL; |
| 3187 | |
| 3188 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 3189 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 3190 | if (type > NL80211_IFTYPE_MAX) |
| 3191 | return -EINVAL; |
| 3192 | } |
| 3193 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3194 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3195 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 3196 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3197 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3198 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 3199 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 3200 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 3201 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 3202 | ETH_ALEN); |
| 3203 | if (!is_valid_ether_addr(params.macaddr)) |
| 3204 | return -EADDRNOTAVAIL; |
| 3205 | } |
| 3206 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3207 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3208 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3209 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3210 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3211 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3212 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3213 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3214 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 3215 | if (err < 0) |
| 3216 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3217 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 3218 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 3219 | if (!msg) |
| 3220 | return -ENOMEM; |
| 3221 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3222 | wdev = rdev_add_virtual_intf(rdev, |
| 3223 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3224 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 3225 | if (WARN_ON(!wdev)) { |
| 3226 | nlmsg_free(msg); |
| 3227 | return -EPROTO; |
| 3228 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3229 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3230 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3231 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3232 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 3233 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3234 | wdev->owner_nlportid = info->snd_portid; |
| 3235 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3236 | switch (type) { |
| 3237 | case NL80211_IFTYPE_MESH_POINT: |
| 3238 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 3239 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3240 | wdev_lock(wdev); |
| 3241 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3242 | IEEE80211_MAX_MESH_ID_LEN); |
| 3243 | wdev->mesh_id_up_len = |
| 3244 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3245 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3246 | wdev->mesh_id_up_len); |
| 3247 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3248 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3249 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3250 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3251 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3252 | * 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] | 3253 | * through the netdev notifier and must be added here |
| 3254 | */ |
| 3255 | mutex_init(&wdev->mtx); |
| 3256 | INIT_LIST_HEAD(&wdev->event_list); |
| 3257 | spin_lock_init(&wdev->event_lock); |
| 3258 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 3259 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 3260 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3261 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3262 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3263 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3264 | break; |
| 3265 | default: |
| 3266 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3267 | } |
| 3268 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3269 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3270 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3271 | nlmsg_free(msg); |
| 3272 | return -ENOBUFS; |
| 3273 | } |
| 3274 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 3275 | /* |
| 3276 | * For wdevs which have no associated netdev object (e.g. of type |
| 3277 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. |
| 3278 | * For all other types, the event will be generated from the |
| 3279 | * netdev notifier |
| 3280 | */ |
| 3281 | if (!wdev->netdev) |
| 3282 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3283 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3284 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3288 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3289 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3290 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3291 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3292 | if (!rdev->ops->del_virtual_intf) |
| 3293 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3294 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3295 | /* |
| 3296 | * If we remove a wireless device without a netdev then clear |
| 3297 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3298 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3299 | * since the wdev has been freed, unlike with a netdev where |
| 3300 | * we need the dev_put() for the netdev to really be freed. |
| 3301 | */ |
| 3302 | if (!wdev->netdev) |
| 3303 | info->user_ptr[1] = NULL; |
| 3304 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 3305 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3306 | } |
| 3307 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3308 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3309 | { |
| 3310 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3311 | struct net_device *dev = info->user_ptr[1]; |
| 3312 | u16 noack_map; |
| 3313 | |
| 3314 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3315 | return -EINVAL; |
| 3316 | |
| 3317 | if (!rdev->ops->set_noack_map) |
| 3318 | return -EOPNOTSUPP; |
| 3319 | |
| 3320 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3321 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3322 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3323 | } |
| 3324 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3325 | struct get_key_cookie { |
| 3326 | struct sk_buff *msg; |
| 3327 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3328 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3329 | }; |
| 3330 | |
| 3331 | static void get_key_callback(void *c, struct key_params *params) |
| 3332 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3333 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3334 | struct get_key_cookie *cookie = c; |
| 3335 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3336 | if ((params->key && |
| 3337 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3338 | params->key_len, params->key)) || |
| 3339 | (params->seq && |
| 3340 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3341 | params->seq_len, params->seq)) || |
| 3342 | (params->cipher && |
| 3343 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3344 | params->cipher))) |
| 3345 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3346 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3347 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 3348 | if (!key) |
| 3349 | goto nla_put_failure; |
| 3350 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3351 | if ((params->key && |
| 3352 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3353 | params->key_len, params->key)) || |
| 3354 | (params->seq && |
| 3355 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3356 | params->seq_len, params->seq)) || |
| 3357 | (params->cipher && |
| 3358 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3359 | params->cipher))) |
| 3360 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3361 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3362 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 3363 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3364 | |
| 3365 | nla_nest_end(cookie->msg, key); |
| 3366 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3367 | return; |
| 3368 | nla_put_failure: |
| 3369 | cookie->error = 1; |
| 3370 | } |
| 3371 | |
| 3372 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3373 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3374 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3375 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3376 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3377 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3378 | const u8 *mac_addr = NULL; |
| 3379 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3380 | struct get_key_cookie cookie = { |
| 3381 | .error = 0, |
| 3382 | }; |
| 3383 | void *hdr; |
| 3384 | struct sk_buff *msg; |
| 3385 | |
| 3386 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 3387 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 3388 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 3389 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3390 | return -EINVAL; |
| 3391 | |
| 3392 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3393 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3394 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3395 | pairwise = !!mac_addr; |
| 3396 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3397 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3398 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3399 | if (kt >= NUM_NL80211_KEYTYPES) |
| 3400 | return -EINVAL; |
| 3401 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3402 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3403 | return -EINVAL; |
| 3404 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3405 | } |
| 3406 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3407 | if (!rdev->ops->get_key) |
| 3408 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3409 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3410 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3411 | return -ENOENT; |
| 3412 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3413 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3414 | if (!msg) |
| 3415 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3416 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3417 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3418 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3419 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3420 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3421 | |
| 3422 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3423 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3424 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3425 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3426 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3427 | goto nla_put_failure; |
| 3428 | if (mac_addr && |
| 3429 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3430 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3431 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3432 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3433 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3434 | |
| 3435 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3436 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3437 | |
| 3438 | if (cookie.error) |
| 3439 | goto nla_put_failure; |
| 3440 | |
| 3441 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3442 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3443 | |
| 3444 | nla_put_failure: |
| 3445 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3446 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3447 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3448 | return err; |
| 3449 | } |
| 3450 | |
| 3451 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3452 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3454 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3455 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3456 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3457 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3458 | err = nl80211_parse_key(info, &key); |
| 3459 | if (err) |
| 3460 | return err; |
| 3461 | |
| 3462 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3463 | return -EINVAL; |
| 3464 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3465 | /* only support setting default key */ |
| 3466 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3467 | return -EINVAL; |
| 3468 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3469 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3470 | |
| 3471 | if (key.def) { |
| 3472 | if (!rdev->ops->set_default_key) { |
| 3473 | err = -EOPNOTSUPP; |
| 3474 | goto out; |
| 3475 | } |
| 3476 | |
| 3477 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3478 | if (err) |
| 3479 | goto out; |
| 3480 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3481 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3482 | key.def_uni, key.def_multi); |
| 3483 | |
| 3484 | if (err) |
| 3485 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3486 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3487 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3488 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3489 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3490 | } else { |
| 3491 | if (key.def_uni || !key.def_multi) { |
| 3492 | err = -EINVAL; |
| 3493 | goto out; |
| 3494 | } |
| 3495 | |
| 3496 | if (!rdev->ops->set_default_mgmt_key) { |
| 3497 | err = -EOPNOTSUPP; |
| 3498 | goto out; |
| 3499 | } |
| 3500 | |
| 3501 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3502 | if (err) |
| 3503 | goto out; |
| 3504 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3505 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3506 | if (err) |
| 3507 | goto out; |
| 3508 | |
| 3509 | #ifdef CONFIG_CFG80211_WEXT |
| 3510 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3511 | #endif |
| 3512 | } |
| 3513 | |
| 3514 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3515 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3516 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3517 | return err; |
| 3518 | } |
| 3519 | |
| 3520 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3521 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3522 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3523 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3524 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3525 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3526 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3527 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3528 | err = nl80211_parse_key(info, &key); |
| 3529 | if (err) |
| 3530 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3531 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3532 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3533 | return -EINVAL; |
| 3534 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3535 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3536 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3537 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3538 | if (key.type == -1) { |
| 3539 | if (mac_addr) |
| 3540 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3541 | else |
| 3542 | key.type = NL80211_KEYTYPE_GROUP; |
| 3543 | } |
| 3544 | |
| 3545 | /* for now */ |
| 3546 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3547 | key.type != NL80211_KEYTYPE_GROUP) |
| 3548 | return -EINVAL; |
| 3549 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3550 | if (!rdev->ops->add_key) |
| 3551 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3552 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3553 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3554 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3555 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3556 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3557 | |
| 3558 | wdev_lock(dev->ieee80211_ptr); |
| 3559 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3560 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3561 | err = rdev_add_key(rdev, dev, key.idx, |
| 3562 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3563 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3564 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3565 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3566 | return err; |
| 3567 | } |
| 3568 | |
| 3569 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3570 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3571 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3572 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3573 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3574 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3575 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3576 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3577 | err = nl80211_parse_key(info, &key); |
| 3578 | if (err) |
| 3579 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3580 | |
| 3581 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3582 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3583 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3584 | if (key.type == -1) { |
| 3585 | if (mac_addr) |
| 3586 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3587 | else |
| 3588 | key.type = NL80211_KEYTYPE_GROUP; |
| 3589 | } |
| 3590 | |
| 3591 | /* for now */ |
| 3592 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3593 | key.type != NL80211_KEYTYPE_GROUP) |
| 3594 | return -EINVAL; |
| 3595 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3596 | if (!rdev->ops->del_key) |
| 3597 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3598 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3599 | wdev_lock(dev->ieee80211_ptr); |
| 3600 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3601 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3602 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3603 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3604 | err = -ENOENT; |
| 3605 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3606 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3607 | err = rdev_del_key(rdev, dev, key.idx, |
| 3608 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3609 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3610 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3611 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3612 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3613 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3614 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3615 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3616 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3617 | } |
| 3618 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3619 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3620 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3621 | return err; |
| 3622 | } |
| 3623 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3624 | /* This function returns an error or the number of nested attributes */ |
| 3625 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3626 | { |
| 3627 | struct nlattr *attr; |
| 3628 | int n_entries = 0, tmp; |
| 3629 | |
| 3630 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3631 | if (nla_len(attr) != ETH_ALEN) |
| 3632 | return -EINVAL; |
| 3633 | |
| 3634 | n_entries++; |
| 3635 | } |
| 3636 | |
| 3637 | return n_entries; |
| 3638 | } |
| 3639 | |
| 3640 | /* |
| 3641 | * This function parses ACL information and allocates memory for ACL data. |
| 3642 | * On successful return, the calling function is responsible to free the |
| 3643 | * ACL buffer returned by this function. |
| 3644 | */ |
| 3645 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3646 | struct genl_info *info) |
| 3647 | { |
| 3648 | enum nl80211_acl_policy acl_policy; |
| 3649 | struct nlattr *attr; |
| 3650 | struct cfg80211_acl_data *acl; |
| 3651 | int i = 0, n_entries, tmp; |
| 3652 | |
| 3653 | if (!wiphy->max_acl_mac_addrs) |
| 3654 | return ERR_PTR(-EOPNOTSUPP); |
| 3655 | |
| 3656 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3657 | return ERR_PTR(-EINVAL); |
| 3658 | |
| 3659 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3660 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3661 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3662 | return ERR_PTR(-EINVAL); |
| 3663 | |
| 3664 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3665 | return ERR_PTR(-EINVAL); |
| 3666 | |
| 3667 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3668 | if (n_entries < 0) |
| 3669 | return ERR_PTR(n_entries); |
| 3670 | |
| 3671 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3672 | return ERR_PTR(-ENOTSUPP); |
| 3673 | |
| 3674 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3675 | GFP_KERNEL); |
| 3676 | if (!acl) |
| 3677 | return ERR_PTR(-ENOMEM); |
| 3678 | |
| 3679 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3680 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3681 | i++; |
| 3682 | } |
| 3683 | |
| 3684 | acl->n_acl_entries = n_entries; |
| 3685 | acl->acl_policy = acl_policy; |
| 3686 | |
| 3687 | return acl; |
| 3688 | } |
| 3689 | |
| 3690 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3691 | { |
| 3692 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3693 | struct net_device *dev = info->user_ptr[1]; |
| 3694 | struct cfg80211_acl_data *acl; |
| 3695 | int err; |
| 3696 | |
| 3697 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3698 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3699 | return -EOPNOTSUPP; |
| 3700 | |
| 3701 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3702 | return -EINVAL; |
| 3703 | |
| 3704 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3705 | if (IS_ERR(acl)) |
| 3706 | return PTR_ERR(acl); |
| 3707 | |
| 3708 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3709 | |
| 3710 | kfree(acl); |
| 3711 | |
| 3712 | return err; |
| 3713 | } |
| 3714 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3715 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3716 | u8 *rates, u8 rates_len) |
| 3717 | { |
| 3718 | u8 i; |
| 3719 | u32 mask = 0; |
| 3720 | |
| 3721 | for (i = 0; i < rates_len; i++) { |
| 3722 | int rate = (rates[i] & 0x7f) * 5; |
| 3723 | int ridx; |
| 3724 | |
| 3725 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 3726 | struct ieee80211_rate *srate = |
| 3727 | &sband->bitrates[ridx]; |
| 3728 | if (rate == srate->bitrate) { |
| 3729 | mask |= 1 << ridx; |
| 3730 | break; |
| 3731 | } |
| 3732 | } |
| 3733 | if (ridx == sband->n_bitrates) |
| 3734 | return 0; /* rate not found */ |
| 3735 | } |
| 3736 | |
| 3737 | return mask; |
| 3738 | } |
| 3739 | |
| 3740 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3741 | u8 *rates, u8 rates_len, |
| 3742 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 3743 | { |
| 3744 | u8 i; |
| 3745 | |
| 3746 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 3747 | |
| 3748 | for (i = 0; i < rates_len; i++) { |
| 3749 | int ridx, rbit; |
| 3750 | |
| 3751 | ridx = rates[i] / 8; |
| 3752 | rbit = BIT(rates[i] % 8); |
| 3753 | |
| 3754 | /* check validity */ |
| 3755 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 3756 | return false; |
| 3757 | |
| 3758 | /* check availability */ |
| 3759 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 3760 | mcs[ridx] |= rbit; |
| 3761 | else |
| 3762 | return false; |
| 3763 | } |
| 3764 | |
| 3765 | return true; |
| 3766 | } |
| 3767 | |
| 3768 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 3769 | { |
| 3770 | u16 mcs_mask = 0; |
| 3771 | |
| 3772 | switch (vht_mcs_map) { |
| 3773 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 3774 | break; |
| 3775 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 3776 | mcs_mask = 0x00FF; |
| 3777 | break; |
| 3778 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 3779 | mcs_mask = 0x01FF; |
| 3780 | break; |
| 3781 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 3782 | mcs_mask = 0x03FF; |
| 3783 | break; |
| 3784 | default: |
| 3785 | break; |
| 3786 | } |
| 3787 | |
| 3788 | return mcs_mask; |
| 3789 | } |
| 3790 | |
| 3791 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 3792 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 3793 | { |
| 3794 | u8 nss; |
| 3795 | |
| 3796 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 3797 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 3798 | vht_mcs_map >>= 2; |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 3803 | struct nl80211_txrate_vht *txrate, |
| 3804 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 3805 | { |
| 3806 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3807 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 3808 | u8 i; |
| 3809 | |
| 3810 | if (!sband->vht_cap.vht_supported) |
| 3811 | return false; |
| 3812 | |
| 3813 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 3814 | |
| 3815 | /* Build vht_mcs_mask from VHT capabilities */ |
| 3816 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 3817 | |
| 3818 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 3819 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 3820 | mcs[i] = txrate->mcs[i]; |
| 3821 | else |
| 3822 | return false; |
| 3823 | } |
| 3824 | |
| 3825 | return true; |
| 3826 | } |
| 3827 | |
| 3828 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 3829 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 3830 | .len = NL80211_MAX_SUPP_RATES }, |
| 3831 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 3832 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 3833 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
| 3834 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 3835 | }; |
| 3836 | |
| 3837 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| 3838 | struct cfg80211_bitrate_mask *mask) |
| 3839 | { |
| 3840 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 3841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3842 | int rem, i; |
| 3843 | struct nlattr *tx_rates; |
| 3844 | struct ieee80211_supported_band *sband; |
| 3845 | u16 vht_tx_mcs_map; |
| 3846 | |
| 3847 | memset(mask, 0, sizeof(*mask)); |
| 3848 | /* Default to all rates enabled */ |
| 3849 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 3850 | sband = rdev->wiphy.bands[i]; |
| 3851 | |
| 3852 | if (!sband) |
| 3853 | continue; |
| 3854 | |
| 3855 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 3856 | memcpy(mask->control[i].ht_mcs, |
| 3857 | sband->ht_cap.mcs.rx_mask, |
| 3858 | sizeof(mask->control[i].ht_mcs)); |
| 3859 | |
| 3860 | if (!sband->vht_cap.vht_supported) |
| 3861 | continue; |
| 3862 | |
| 3863 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3864 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 3865 | } |
| 3866 | |
| 3867 | /* if no rates are given set it back to the defaults */ |
| 3868 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 3869 | goto out; |
| 3870 | |
| 3871 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 3872 | * directly to the enum nl80211_band values used in cfg80211. |
| 3873 | */ |
| 3874 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| 3875 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
| 3876 | enum nl80211_band band = nla_type(tx_rates); |
| 3877 | int err; |
| 3878 | |
| 3879 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 3880 | return -EINVAL; |
| 3881 | sband = rdev->wiphy.bands[band]; |
| 3882 | if (sband == NULL) |
| 3883 | return -EINVAL; |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 3884 | err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 3885 | nl80211_txattr_policy, info->extack); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3886 | if (err) |
| 3887 | return err; |
| 3888 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 3889 | mask->control[band].legacy = rateset_to_mask( |
| 3890 | sband, |
| 3891 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 3892 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 3893 | if ((mask->control[band].legacy == 0) && |
| 3894 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 3895 | return -EINVAL; |
| 3896 | } |
| 3897 | if (tb[NL80211_TXRATE_HT]) { |
| 3898 | if (!ht_rateset_to_mask( |
| 3899 | sband, |
| 3900 | nla_data(tb[NL80211_TXRATE_HT]), |
| 3901 | nla_len(tb[NL80211_TXRATE_HT]), |
| 3902 | mask->control[band].ht_mcs)) |
| 3903 | return -EINVAL; |
| 3904 | } |
| 3905 | if (tb[NL80211_TXRATE_VHT]) { |
| 3906 | if (!vht_set_mcs_mask( |
| 3907 | sband, |
| 3908 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 3909 | mask->control[band].vht_mcs)) |
| 3910 | return -EINVAL; |
| 3911 | } |
| 3912 | if (tb[NL80211_TXRATE_GI]) { |
| 3913 | mask->control[band].gi = |
| 3914 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 3915 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 3916 | return -EINVAL; |
| 3917 | } |
| 3918 | |
| 3919 | if (mask->control[band].legacy == 0) { |
| 3920 | /* don't allow empty legacy rates if HT or VHT |
| 3921 | * are not even supported. |
| 3922 | */ |
| 3923 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 3924 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 3925 | return -EINVAL; |
| 3926 | |
| 3927 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 3928 | if (mask->control[band].ht_mcs[i]) |
| 3929 | goto out; |
| 3930 | |
| 3931 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 3932 | if (mask->control[band].vht_mcs[i]) |
| 3933 | goto out; |
| 3934 | |
| 3935 | /* legacy and mcs rates may not be both empty */ |
| 3936 | return -EINVAL; |
| 3937 | } |
| 3938 | } |
| 3939 | |
| 3940 | out: |
| 3941 | return 0; |
| 3942 | } |
| 3943 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3944 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 3945 | enum nl80211_band band, |
| 3946 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3947 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3948 | u32 count_ht, count_vht, i; |
| 3949 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3950 | |
| 3951 | /* Allow only one rate */ |
| 3952 | if (hweight32(rate) > 1) |
| 3953 | return -EINVAL; |
| 3954 | |
| 3955 | count_ht = 0; |
| 3956 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3957 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3958 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3959 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3960 | count_ht++; |
| 3961 | if (count_ht > 1) |
| 3962 | return -EINVAL; |
| 3963 | } |
| 3964 | if (count_ht && rate) |
| 3965 | return -EINVAL; |
| 3966 | } |
| 3967 | |
| 3968 | count_vht = 0; |
| 3969 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3970 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3971 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3972 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3973 | count_vht++; |
| 3974 | if (count_vht > 1) |
| 3975 | return -EINVAL; |
| 3976 | } |
| 3977 | if (count_vht && rate) |
| 3978 | return -EINVAL; |
| 3979 | } |
| 3980 | |
| 3981 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 3982 | return -EINVAL; |
| 3983 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3984 | if (rate && |
| 3985 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3986 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 3987 | return -EINVAL; |
| 3988 | if (count_ht && |
| 3989 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3990 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 3991 | return -EINVAL; |
| 3992 | if (count_vht && |
| 3993 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3994 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 3995 | return -EINVAL; |
| 3996 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3997 | return 0; |
| 3998 | } |
| 3999 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4000 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4001 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4002 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4003 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4004 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4005 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 4006 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 4007 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 4008 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4009 | return -EINVAL; |
| 4010 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4011 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4012 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4013 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 4014 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 4015 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4016 | if (!bcn->head_len) |
| 4017 | return -EINVAL; |
| 4018 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4019 | } |
| 4020 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4021 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 4022 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 4023 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4024 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4025 | } |
| 4026 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4027 | if (!haveinfo) |
| 4028 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4029 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4030 | if (attrs[NL80211_ATTR_IE]) { |
| 4031 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 4032 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4033 | } |
| 4034 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4035 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4036 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4037 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4038 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4039 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4040 | } |
| 4041 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4042 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4043 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4044 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4045 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4046 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4047 | } |
| 4048 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4049 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 4050 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 4051 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 4052 | } |
| 4053 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4054 | return 0; |
| 4055 | } |
| 4056 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4057 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 4058 | const u8 *rates) |
| 4059 | { |
| 4060 | int i; |
| 4061 | |
| 4062 | if (!rates) |
| 4063 | return; |
| 4064 | |
| 4065 | for (i = 0; i < rates[1]; i++) { |
| 4066 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 4067 | params->ht_required = true; |
| 4068 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 4069 | params->vht_required = true; |
| 4070 | } |
| 4071 | } |
| 4072 | |
| 4073 | /* |
| 4074 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 4075 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 4076 | * benefit of drivers that rebuild IEs in the firmware. |
| 4077 | */ |
| 4078 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 4079 | { |
| 4080 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
Igor Mitsyanko | ba83bfb | 2017-08-30 13:52:25 -0700 | [diff] [blame] | 4081 | size_t ies_len = bcn->tail_len; |
| 4082 | const u8 *ies = bcn->tail; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4083 | const u8 *rates; |
| 4084 | const u8 *cap; |
| 4085 | |
| 4086 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 4087 | nl80211_check_ap_rate_selectors(params, rates); |
| 4088 | |
| 4089 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 4090 | nl80211_check_ap_rate_selectors(params, rates); |
| 4091 | |
| 4092 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 4093 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 4094 | params->ht_cap = (void *)(cap + 2); |
| 4095 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 4096 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 4097 | params->vht_cap = (void *)(cap + 2); |
| 4098 | } |
| 4099 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4100 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 4101 | struct cfg80211_ap_settings *params) |
| 4102 | { |
| 4103 | struct wireless_dev *wdev; |
| 4104 | bool ret = false; |
| 4105 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 4106 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4107 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 4108 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 4109 | continue; |
| 4110 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4111 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4112 | continue; |
| 4113 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4114 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4115 | ret = true; |
| 4116 | break; |
| 4117 | } |
| 4118 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4119 | return ret; |
| 4120 | } |
| 4121 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4122 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 4123 | enum nl80211_auth_type auth_type, |
| 4124 | enum nl80211_commands cmd) |
| 4125 | { |
| 4126 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 4127 | return false; |
| 4128 | |
| 4129 | switch (cmd) { |
| 4130 | case NL80211_CMD_AUTHENTICATE: |
| 4131 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 4132 | auth_type == NL80211_AUTHTYPE_SAE) |
| 4133 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 4134 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 4135 | NL80211_EXT_FEATURE_FILS_STA) && |
| 4136 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 4137 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4138 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 4139 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4140 | return true; |
| 4141 | case NL80211_CMD_CONNECT: |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 4142 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 4143 | auth_type == NL80211_AUTHTYPE_SAE) |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 4144 | return false; |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 4145 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 4146 | /* FILS with SK PFS or PK not supported yet */ |
| 4147 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4148 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 4149 | return false; |
| 4150 | if (!wiphy_ext_feature_isset( |
| 4151 | &rdev->wiphy, |
| 4152 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 4153 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 4154 | return false; |
| 4155 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4156 | case NL80211_CMD_START_AP: |
| 4157 | /* SAE not supported yet */ |
| 4158 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 4159 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 4160 | /* FILS not supported yet */ |
| 4161 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 4162 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4163 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 4164 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4165 | return true; |
| 4166 | default: |
| 4167 | return false; |
| 4168 | } |
| 4169 | } |
| 4170 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4171 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 4172 | { |
| 4173 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4174 | struct net_device *dev = info->user_ptr[1]; |
| 4175 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4176 | struct cfg80211_ap_settings params; |
| 4177 | int err; |
| 4178 | |
| 4179 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4180 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4181 | return -EOPNOTSUPP; |
| 4182 | |
| 4183 | if (!rdev->ops->start_ap) |
| 4184 | return -EOPNOTSUPP; |
| 4185 | |
| 4186 | if (wdev->beacon_interval) |
| 4187 | return -EALREADY; |
| 4188 | |
| 4189 | memset(¶ms, 0, sizeof(params)); |
| 4190 | |
| 4191 | /* these are required for START_AP */ |
| 4192 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 4193 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 4194 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 4195 | return -EINVAL; |
| 4196 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4197 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4198 | if (err) |
| 4199 | return err; |
| 4200 | |
| 4201 | params.beacon_interval = |
| 4202 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4203 | params.dtim_period = |
| 4204 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 4205 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 4206 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 4207 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4208 | if (err) |
| 4209 | return err; |
| 4210 | |
| 4211 | /* |
| 4212 | * In theory, some of these attributes should be required here |
| 4213 | * but since they were not used when the command was originally |
| 4214 | * added, keep them optional for old user space programs to let |
| 4215 | * them continue to work with drivers that do not need the |
| 4216 | * additional information -- drivers must check! |
| 4217 | */ |
| 4218 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 4219 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4220 | params.ssid_len = |
| 4221 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4222 | if (params.ssid_len == 0 || |
| 4223 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 4224 | return -EINVAL; |
| 4225 | } |
| 4226 | |
| 4227 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 4228 | params.hidden_ssid = nla_get_u32( |
| 4229 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 4230 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 4231 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 4232 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 4233 | return -EINVAL; |
| 4234 | } |
| 4235 | |
| 4236 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 4237 | |
| 4238 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4239 | params.auth_type = nla_get_u32( |
| 4240 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4241 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 4242 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4243 | return -EINVAL; |
| 4244 | } else |
| 4245 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4246 | |
| 4247 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 4248 | NL80211_MAX_NR_CIPHER_SUITES); |
| 4249 | if (err) |
| 4250 | return err; |
| 4251 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 4252 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 4253 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 4254 | return -EOPNOTSUPP; |
| 4255 | params.inactivity_timeout = nla_get_u16( |
| 4256 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 4257 | } |
| 4258 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4259 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4260 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4261 | return -EINVAL; |
| 4262 | params.p2p_ctwindow = |
| 4263 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4264 | if (params.p2p_ctwindow > 127) |
| 4265 | return -EINVAL; |
| 4266 | if (params.p2p_ctwindow != 0 && |
| 4267 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4268 | return -EINVAL; |
| 4269 | } |
| 4270 | |
| 4271 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4272 | u8 tmp; |
| 4273 | |
| 4274 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4275 | return -EINVAL; |
| 4276 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4277 | if (tmp > 1) |
| 4278 | return -EINVAL; |
| 4279 | params.p2p_opp_ps = tmp; |
| 4280 | if (params.p2p_opp_ps != 0 && |
| 4281 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4282 | return -EINVAL; |
| 4283 | } |
| 4284 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4285 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4286 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 4287 | if (err) |
| 4288 | return err; |
| 4289 | } else if (wdev->preset_chandef.chan) { |
| 4290 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4291 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4292 | return -EINVAL; |
| 4293 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 4294 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 4295 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4296 | return -EINVAL; |
| 4297 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4298 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 4299 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); |
| 4300 | if (err) |
| 4301 | return err; |
| 4302 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4303 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 4304 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4305 | if (err) |
| 4306 | return err; |
| 4307 | } |
| 4308 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 4309 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 4310 | params.smps_mode = |
| 4311 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 4312 | switch (params.smps_mode) { |
| 4313 | case NL80211_SMPS_OFF: |
| 4314 | break; |
| 4315 | case NL80211_SMPS_STATIC: |
| 4316 | if (!(rdev->wiphy.features & |
| 4317 | NL80211_FEATURE_STATIC_SMPS)) |
| 4318 | return -EINVAL; |
| 4319 | break; |
| 4320 | case NL80211_SMPS_DYNAMIC: |
| 4321 | if (!(rdev->wiphy.features & |
| 4322 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 4323 | return -EINVAL; |
| 4324 | break; |
| 4325 | default: |
| 4326 | return -EINVAL; |
| 4327 | } |
| 4328 | } else { |
| 4329 | params.smps_mode = NL80211_SMPS_OFF; |
| 4330 | } |
| 4331 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 4332 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 4333 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 4334 | return -EOPNOTSUPP; |
| 4335 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 4336 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 4337 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 4338 | if (IS_ERR(params.acl)) |
| 4339 | return PTR_ERR(params.acl); |
| 4340 | } |
| 4341 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4342 | nl80211_calculate_ap_params(¶ms); |
| 4343 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4344 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4345 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4346 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4347 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4348 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 4349 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 4350 | wdev->ssid_len = params.ssid_len; |
| 4351 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Denis Kenzior | 466a306 | 2018-03-26 12:52:47 -0500 | [diff] [blame] | 4352 | |
| 4353 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 4354 | wdev->conn_owner_nlportid = info->snd_portid; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4355 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4356 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4357 | |
| 4358 | kfree(params.acl); |
| 4359 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 4360 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4361 | } |
| 4362 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4363 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 4364 | { |
| 4365 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4366 | struct net_device *dev = info->user_ptr[1]; |
| 4367 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4368 | struct cfg80211_beacon_data params; |
| 4369 | int err; |
| 4370 | |
| 4371 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4372 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4373 | return -EOPNOTSUPP; |
| 4374 | |
| 4375 | if (!rdev->ops->change_beacon) |
| 4376 | return -EOPNOTSUPP; |
| 4377 | |
| 4378 | if (!wdev->beacon_interval) |
| 4379 | return -EINVAL; |
| 4380 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4381 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4382 | if (err) |
| 4383 | return err; |
| 4384 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4385 | wdev_lock(wdev); |
| 4386 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 4387 | wdev_unlock(wdev); |
| 4388 | |
| 4389 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | 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] | 4393 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4395 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4396 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 4397 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4398 | } |
| 4399 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4400 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 4401 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 4402 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 4403 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 4404 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 4405 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 4406 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4407 | }; |
| 4408 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4409 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4410 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4411 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4412 | { |
| 4413 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4414 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4415 | int flag; |
| 4416 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4417 | /* |
| 4418 | * Try parsing the new attribute first so userspace |
| 4419 | * can specify both for older kernels. |
| 4420 | */ |
| 4421 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 4422 | if (nla) { |
| 4423 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4424 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4425 | sta_flags = nla_data(nla); |
| 4426 | params->sta_flags_mask = sta_flags->mask; |
| 4427 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4428 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4429 | if ((params->sta_flags_mask | |
| 4430 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 4431 | return -EINVAL; |
| 4432 | return 0; |
| 4433 | } |
| 4434 | |
| 4435 | /* if present, parse the old attribute */ |
| 4436 | |
| 4437 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4438 | if (!nla) |
| 4439 | return 0; |
| 4440 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 4441 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 4442 | sta_flags_policy, info->extack)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4443 | return -EINVAL; |
| 4444 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4445 | /* |
| 4446 | * Only allow certain flags for interface types so that |
| 4447 | * other attributes are silently ignored. Remember that |
| 4448 | * this is backward compatibility code with old userspace |
| 4449 | * and shouldn't be hit in other cases anyway. |
| 4450 | */ |
| 4451 | switch (iftype) { |
| 4452 | case NL80211_IFTYPE_AP: |
| 4453 | case NL80211_IFTYPE_AP_VLAN: |
| 4454 | case NL80211_IFTYPE_P2P_GO: |
| 4455 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4456 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4457 | BIT(NL80211_STA_FLAG_WME) | |
| 4458 | BIT(NL80211_STA_FLAG_MFP); |
| 4459 | break; |
| 4460 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4461 | case NL80211_IFTYPE_STATION: |
| 4462 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4463 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4464 | break; |
| 4465 | case NL80211_IFTYPE_MESH_POINT: |
| 4466 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4467 | BIT(NL80211_STA_FLAG_MFP) | |
| 4468 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4469 | default: |
| 4470 | return -EINVAL; |
| 4471 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4472 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4473 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 4474 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4475 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4476 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4477 | /* no longer support new API additions in old API */ |
| 4478 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 4479 | return -EINVAL; |
| 4480 | } |
| 4481 | } |
| 4482 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4483 | return 0; |
| 4484 | } |
| 4485 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4486 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 4487 | int attr) |
| 4488 | { |
| 4489 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4490 | u32 bitrate; |
| 4491 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 4492 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4493 | |
| 4494 | rate = nla_nest_start(msg, attr); |
| 4495 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4496 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4497 | |
| 4498 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 4499 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4500 | /* report 16-bit bitrate only if we can */ |
| 4501 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4502 | if (bitrate > 0 && |
| 4503 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 4504 | return false; |
| 4505 | if (bitrate_compat > 0 && |
| 4506 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 4507 | return false; |
| 4508 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4509 | switch (info->bw) { |
| 4510 | case RATE_INFO_BW_5: |
| 4511 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 4512 | break; |
| 4513 | case RATE_INFO_BW_10: |
| 4514 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 4515 | break; |
| 4516 | default: |
| 4517 | WARN_ON(1); |
| 4518 | /* fall through */ |
| 4519 | case RATE_INFO_BW_20: |
| 4520 | rate_flg = 0; |
| 4521 | break; |
| 4522 | case RATE_INFO_BW_40: |
| 4523 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 4524 | break; |
| 4525 | case RATE_INFO_BW_80: |
| 4526 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 4527 | break; |
| 4528 | case RATE_INFO_BW_160: |
| 4529 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 4530 | break; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 4531 | case RATE_INFO_BW_HE_RU: |
| 4532 | rate_flg = 0; |
| 4533 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4534 | } |
| 4535 | |
| 4536 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 4537 | return false; |
| 4538 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4539 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 4540 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 4541 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4542 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4543 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4544 | return false; |
| 4545 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 4546 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 4547 | return false; |
| 4548 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 4549 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4550 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4551 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4552 | return false; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 4553 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { |
| 4554 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) |
| 4555 | return false; |
| 4556 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) |
| 4557 | return false; |
| 4558 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) |
| 4559 | return false; |
| 4560 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) |
| 4561 | return false; |
| 4562 | if (info->bw == RATE_INFO_BW_HE_RU && |
| 4563 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, |
| 4564 | info->he_ru_alloc)) |
| 4565 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4566 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4567 | |
| 4568 | nla_nest_end(msg, rate); |
| 4569 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4570 | } |
| 4571 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4572 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 4573 | int id) |
| 4574 | { |
| 4575 | void *attr; |
| 4576 | int i = 0; |
| 4577 | |
| 4578 | if (!mask) |
| 4579 | return true; |
| 4580 | |
| 4581 | attr = nla_nest_start(msg, id); |
| 4582 | if (!attr) |
| 4583 | return false; |
| 4584 | |
| 4585 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 4586 | if (!(mask & BIT(i))) |
| 4587 | continue; |
| 4588 | |
| 4589 | if (nla_put_u8(msg, i, signal[i])) |
| 4590 | return false; |
| 4591 | } |
| 4592 | |
| 4593 | nla_nest_end(msg, attr); |
| 4594 | |
| 4595 | return true; |
| 4596 | } |
| 4597 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4598 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 4599 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4600 | struct cfg80211_registered_device *rdev, |
| 4601 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 4602 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4603 | { |
| 4604 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4605 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4606 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4607 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4608 | if (!hdr) |
| 4609 | return -1; |
| 4610 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4611 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4612 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 4613 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 4614 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4615 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4616 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 4617 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4618 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4619 | |
| 4620 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4621 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 4622 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4623 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 4624 | sinfo->memb)) \ |
| 4625 | goto nla_put_failure; \ |
| 4626 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4627 | #define PUT_SINFO_U64(attr, memb) do { \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 4628 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4629 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 4630 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 4631 | goto nla_put_failure; \ |
| 4632 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4633 | |
| 4634 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 4635 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 4636 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 4637 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | |
| 4638 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4639 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4640 | (u32)sinfo->rx_bytes)) |
| 4641 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4642 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 4643 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | |
| 4644 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4645 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 4646 | (u32)sinfo->tx_bytes)) |
| 4647 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4648 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4649 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 4650 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4651 | PUT_SINFO(LLID, llid, u16); |
| 4652 | PUT_SINFO(PLID, plid, u16); |
| 4653 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4654 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4655 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4656 | switch (rdev->wiphy.signal_type) { |
| 4657 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4658 | PUT_SINFO(SIGNAL, signal, u8); |
| 4659 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4660 | break; |
| 4661 | default: |
| 4662 | break; |
| 4663 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 4664 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4665 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4666 | sinfo->chain_signal, |
| 4667 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 4668 | goto nla_put_failure; |
| 4669 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 4670 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4671 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4672 | sinfo->chain_signal_avg, |
| 4673 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 4674 | goto nla_put_failure; |
| 4675 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 4676 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4677 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 4678 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4679 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4680 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 4681 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4682 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 4683 | NL80211_STA_INFO_RX_BITRATE)) |
| 4684 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4685 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4686 | |
| 4687 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 4688 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 4689 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 4690 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 4691 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 4692 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 4693 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 4694 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 4695 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 4696 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 4697 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4698 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 4699 | if (!bss_param) |
| 4700 | goto nla_put_failure; |
| 4701 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4702 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 4703 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 4704 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 4705 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 4706 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 4707 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 4708 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 4709 | sinfo->bss_param.dtim_period) || |
| 4710 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 4711 | sinfo->bss_param.beacon_interval)) |
| 4712 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4713 | |
| 4714 | nla_nest_end(msg, bss_param); |
| 4715 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 4716 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4717 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 4718 | sizeof(struct nl80211_sta_flag_update), |
| 4719 | &sinfo->sta_flags)) |
| 4720 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4721 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4722 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 4723 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 4724 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 4725 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 4726 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); |
Balaji Pothunoori | 81d5439 | 2018-04-16 20:18:40 +0530 | [diff] [blame] | 4727 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 4728 | NL80211_EXT_FEATURE_DATA_ACK_SIGNAL_SUPPORT)) |
| 4729 | PUT_SINFO(DATA_ACK_SIGNAL_AVG, avg_ack_signal, s8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4730 | |
| 4731 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4732 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4733 | |
Arend van Spriel | 8689c05 | 2018-05-10 13:50:12 +0200 | [diff] [blame] | 4734 | if (sinfo->pertid) { |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4735 | struct nlattr *tidsattr; |
| 4736 | int tid; |
| 4737 | |
| 4738 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 4739 | if (!tidsattr) |
| 4740 | goto nla_put_failure; |
| 4741 | |
| 4742 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 4743 | struct cfg80211_tid_stats *tidstats; |
| 4744 | struct nlattr *tidattr; |
| 4745 | |
| 4746 | tidstats = &sinfo->pertid[tid]; |
| 4747 | |
| 4748 | if (!tidstats->filled) |
| 4749 | continue; |
| 4750 | |
| 4751 | tidattr = nla_nest_start(msg, tid + 1); |
| 4752 | if (!tidattr) |
| 4753 | goto nla_put_failure; |
| 4754 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4755 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4756 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4757 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 4758 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4759 | goto nla_put_failure; \ |
| 4760 | } while (0) |
| 4761 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4762 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 4763 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 4764 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 4765 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4766 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4767 | #undef PUT_TIDVAL_U64 |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 4768 | if ((tidstats->filled & |
| 4769 | BIT(NL80211_TID_STATS_TXQ_STATS)) && |
| 4770 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, |
| 4771 | NL80211_TID_STATS_TXQ_STATS)) |
| 4772 | goto nla_put_failure; |
| 4773 | |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4774 | nla_nest_end(msg, tidattr); |
| 4775 | } |
| 4776 | |
| 4777 | nla_nest_end(msg, tidsattr); |
| 4778 | } |
| 4779 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4780 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4781 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4782 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4783 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 4784 | sinfo->assoc_req_ies)) |
| 4785 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 4786 | |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 4787 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4788 | genlmsg_end(msg, hdr); |
| 4789 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4790 | |
| 4791 | nla_put_failure: |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 4792 | cfg80211_sinfo_release_content(sinfo); |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4793 | genlmsg_cancel(msg, hdr); |
| 4794 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4795 | } |
| 4796 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4797 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4798 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4799 | { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4800 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4801 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4802 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4803 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4804 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4805 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4806 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4807 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4808 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4809 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4810 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4811 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4812 | if (!wdev->netdev) { |
| 4813 | err = -EINVAL; |
| 4814 | goto out_err; |
| 4815 | } |
| 4816 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4817 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4818 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4819 | goto out_err; |
| 4820 | } |
| 4821 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4822 | while (1) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4823 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4824 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4825 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4826 | if (err == -ENOENT) |
| 4827 | break; |
| 4828 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4829 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4830 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4831 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4832 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4833 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4834 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4835 | &sinfo) < 0) |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4836 | goto out; |
| 4837 | |
| 4838 | sta_idx++; |
| 4839 | } |
| 4840 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4841 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4842 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4843 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4844 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4845 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4846 | |
| 4847 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4848 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4849 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4850 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4851 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4853 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4854 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4855 | struct sk_buff *msg; |
| 4856 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4857 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4858 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4859 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4860 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4861 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4862 | return -EINVAL; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4863 | |
| 4864 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4865 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4866 | if (!rdev->ops->get_station) |
| 4867 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4868 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4869 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4870 | if (err) |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4871 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4872 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4873 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 4874 | if (!msg) { |
Denis Kenzior | ba8f566 | 2018-05-21 19:21:42 -0500 | [diff] [blame] | 4875 | cfg80211_sinfo_release_content(&sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4876 | return -ENOMEM; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 4877 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4878 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4879 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4880 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4881 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4882 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4883 | return -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4884 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4885 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 4886 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4887 | } |
| 4888 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4889 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4890 | struct station_parameters *params, |
| 4891 | enum cfg80211_station_type statype) |
| 4892 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4893 | if (params->listen_interval != -1 && |
| 4894 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4895 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4896 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4897 | if (params->support_p2p_ps != -1 && |
| 4898 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4899 | return -EINVAL; |
| 4900 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4901 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4902 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4903 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4904 | return -EINVAL; |
| 4905 | |
| 4906 | /* When you run into this, adjust the code below for the new flag */ |
| 4907 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4908 | |
| 4909 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4910 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4911 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4912 | /* |
| 4913 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4914 | * code doesn't have the bug of including TDLS in the |
| 4915 | * mask everywhere. |
| 4916 | */ |
| 4917 | if (params->sta_flags_mask & |
| 4918 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4919 | BIT(NL80211_STA_FLAG_MFP) | |
| 4920 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4921 | return -EINVAL; |
| 4922 | break; |
| 4923 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4924 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4925 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4926 | return -EINVAL; |
| 4927 | /* ignore since it can't change */ |
| 4928 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4929 | break; |
| 4930 | default: |
| 4931 | /* disallow mesh-specific things */ |
| 4932 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4933 | return -EINVAL; |
| 4934 | if (params->local_pm) |
| 4935 | return -EINVAL; |
| 4936 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4937 | return -EINVAL; |
| 4938 | } |
| 4939 | |
| 4940 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4941 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4942 | /* TDLS can't be set, ... */ |
| 4943 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4944 | return -EINVAL; |
| 4945 | /* |
| 4946 | * ... but don't bother the driver with it. This works around |
| 4947 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4948 | * TLDS_PEER flag in the mask even for AP mode. |
| 4949 | */ |
| 4950 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4951 | } |
| 4952 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4953 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4954 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4955 | /* reject other things that can't change */ |
| 4956 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4957 | return -EINVAL; |
| 4958 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4959 | return -EINVAL; |
| 4960 | if (params->supported_rates) |
| 4961 | return -EINVAL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 4962 | if (params->ext_capab || params->ht_capa || params->vht_capa || |
| 4963 | params->he_capa) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4964 | return -EINVAL; |
| 4965 | } |
| 4966 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4967 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4968 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4969 | if (params->vlan) |
| 4970 | return -EINVAL; |
| 4971 | } |
| 4972 | |
| 4973 | switch (statype) { |
| 4974 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4975 | /* Use this only for authorizing/unauthorizing a station */ |
| 4976 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4977 | return -EOPNOTSUPP; |
| 4978 | break; |
| 4979 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4980 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4981 | /* accept only the listed bits */ |
| 4982 | if (params->sta_flags_mask & |
| 4983 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4984 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4985 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4986 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4987 | BIT(NL80211_STA_FLAG_WME) | |
| 4988 | BIT(NL80211_STA_FLAG_MFP))) |
| 4989 | return -EINVAL; |
| 4990 | |
| 4991 | /* but authenticated/associated only if driver handles it */ |
| 4992 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4993 | params->sta_flags_mask & |
| 4994 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4995 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4996 | return -EINVAL; |
| 4997 | break; |
| 4998 | case CFG80211_STA_IBSS: |
| 4999 | case CFG80211_STA_AP_STA: |
| 5000 | /* reject any changes other than AUTHORIZED */ |
| 5001 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 5002 | return -EINVAL; |
| 5003 | break; |
| 5004 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5005 | /* reject any changes other than AUTHORIZED or WME */ |
| 5006 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5007 | BIT(NL80211_STA_FLAG_WME))) |
| 5008 | return -EINVAL; |
| 5009 | /* force (at least) rates when authorizing */ |
| 5010 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 5011 | !params->supported_rates) |
| 5012 | return -EINVAL; |
| 5013 | break; |
| 5014 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5015 | /* reject any changes */ |
| 5016 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5017 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5018 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5019 | return -EINVAL; |
| 5020 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5021 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 5022 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 5023 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5024 | return -EINVAL; |
| 5025 | break; |
| 5026 | } |
| 5027 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 5028 | /* |
| 5029 | * Older kernel versions ignored this attribute entirely, so don't |
| 5030 | * reject attempts to update it but mark it as unused instead so the |
| 5031 | * driver won't look at the data. |
| 5032 | */ |
| 5033 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 5034 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 5035 | params->opmode_notif_used = false; |
| 5036 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5037 | return 0; |
| 5038 | } |
| 5039 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 5040 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5041 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 5042 | * 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] | 5043 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5044 | static struct net_device *get_vlan(struct genl_info *info, |
| 5045 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5046 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5047 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5048 | struct net_device *v; |
| 5049 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5050 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5051 | if (!vlanattr) |
| 5052 | return NULL; |
| 5053 | |
| 5054 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 5055 | if (!v) |
| 5056 | return ERR_PTR(-ENODEV); |
| 5057 | |
| 5058 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 5059 | ret = -EINVAL; |
| 5060 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5061 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5062 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5063 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5064 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5065 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 5066 | ret = -EINVAL; |
| 5067 | goto error; |
| 5068 | } |
| 5069 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5070 | if (!netif_running(v)) { |
| 5071 | ret = -ENETDOWN; |
| 5072 | goto error; |
| 5073 | } |
| 5074 | |
| 5075 | return v; |
| 5076 | error: |
| 5077 | dev_put(v); |
| 5078 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5079 | } |
| 5080 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 5081 | static const struct nla_policy |
| 5082 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5083 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 5084 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 5085 | }; |
| 5086 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5087 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 5088 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5089 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5090 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 5091 | struct nlattr *nla; |
| 5092 | int err; |
| 5093 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5094 | /* parse WME attributes if present */ |
| 5095 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 5096 | return 0; |
| 5097 | |
| 5098 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 5099 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 5100 | nl80211_sta_wme_policy, info->extack); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5101 | if (err) |
| 5102 | return err; |
| 5103 | |
| 5104 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 5105 | params->uapsd_queues = nla_get_u8( |
| 5106 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 5107 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 5108 | return -EINVAL; |
| 5109 | |
| 5110 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 5111 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 5112 | |
| 5113 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 5114 | return -EINVAL; |
| 5115 | |
| 5116 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 5117 | |
| 5118 | return 0; |
| 5119 | } |
| 5120 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5121 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 5122 | struct station_parameters *params) |
| 5123 | { |
| 5124 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 5125 | params->supported_channels = |
| 5126 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 5127 | params->supported_channels_len = |
| 5128 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 5129 | /* |
| 5130 | * Need to include at least one (first channel, number of |
| 5131 | * channels) tuple for each subband, and must have proper |
| 5132 | * tuples for the rest of the data as well. |
| 5133 | */ |
| 5134 | if (params->supported_channels_len < 2) |
| 5135 | return -EINVAL; |
| 5136 | if (params->supported_channels_len % 2) |
| 5137 | return -EINVAL; |
| 5138 | } |
| 5139 | |
| 5140 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 5141 | params->supported_oper_classes = |
| 5142 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 5143 | params->supported_oper_classes_len = |
| 5144 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 5145 | /* |
| 5146 | * The value of the Length field of the Supported Operating |
| 5147 | * Classes element is between 2 and 253. |
| 5148 | */ |
| 5149 | if (params->supported_oper_classes_len < 2 || |
| 5150 | params->supported_oper_classes_len > 253) |
| 5151 | return -EINVAL; |
| 5152 | } |
| 5153 | return 0; |
| 5154 | } |
| 5155 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5156 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 5157 | struct station_parameters *params) |
| 5158 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5159 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5160 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5161 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 5162 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5163 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 5164 | params->ht_capa = |
| 5165 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5166 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 5167 | params->vht_capa = |
| 5168 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5169 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 5170 | params->he_capa = |
| 5171 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5172 | params->he_capa_len = |
| 5173 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5174 | |
| 5175 | if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) |
| 5176 | return -EINVAL; |
| 5177 | } |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5178 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5179 | err = nl80211_parse_sta_channel_info(info, params); |
| 5180 | if (err) |
| 5181 | return err; |
| 5182 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5183 | return nl80211_parse_sta_wme(info, params); |
| 5184 | } |
| 5185 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5186 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 5187 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5189 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5190 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5191 | u8 *mac_addr; |
| 5192 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5193 | |
| 5194 | memset(¶ms, 0, sizeof(params)); |
| 5195 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5196 | if (!rdev->ops->change_station) |
| 5197 | return -EOPNOTSUPP; |
| 5198 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5199 | /* |
| 5200 | * AID and listen_interval properties can be set only for unassociated |
| 5201 | * station. Include these parameters here and will check them in |
| 5202 | * cfg80211_check_station_change(). |
| 5203 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 5204 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 5205 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5206 | |
| 5207 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 5208 | params.listen_interval = |
| 5209 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 5210 | else |
| 5211 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5212 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5213 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 5214 | u8 tmp; |
| 5215 | |
| 5216 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 5217 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 5218 | return -EINVAL; |
| 5219 | |
| 5220 | params.support_p2p_ps = tmp; |
| 5221 | } else { |
| 5222 | params.support_p2p_ps = -1; |
| 5223 | } |
| 5224 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5225 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5226 | return -EINVAL; |
| 5227 | |
| 5228 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5229 | |
| 5230 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 5231 | params.supported_rates = |
| 5232 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5233 | params.supported_rates_len = |
| 5234 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5235 | } |
| 5236 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 5237 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 5238 | params.capability = |
| 5239 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 5240 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 5241 | } |
| 5242 | |
| 5243 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 5244 | params.ext_capab = |
| 5245 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5246 | params.ext_capab_len = |
| 5247 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5248 | } |
| 5249 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5250 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5251 | return -EINVAL; |
| 5252 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5253 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5254 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5255 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 5256 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 5257 | return -EINVAL; |
| 5258 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5259 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5260 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 5261 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5262 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 5263 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 5264 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 5265 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 5266 | params.peer_aid = nla_get_u16( |
| 5267 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 5268 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 5269 | return -EINVAL; |
| 5270 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5271 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 5272 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 5273 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5274 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 5275 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 5276 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 5277 | |
| 5278 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 5279 | pm > NL80211_MESH_POWER_MAX) |
| 5280 | return -EINVAL; |
| 5281 | |
| 5282 | params.local_pm = pm; |
| 5283 | } |
| 5284 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 5285 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 5286 | params.opmode_notif_used = true; |
| 5287 | params.opmode_notif = |
| 5288 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 5289 | } |
| 5290 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5291 | /* Include parameters for TDLS peer (will check later) */ |
| 5292 | err = nl80211_set_station_tdls(info, ¶ms); |
| 5293 | if (err) |
| 5294 | return err; |
| 5295 | |
| 5296 | params.vlan = get_vlan(info, rdev); |
| 5297 | if (IS_ERR(params.vlan)) |
| 5298 | return PTR_ERR(params.vlan); |
| 5299 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5300 | switch (dev->ieee80211_ptr->iftype) { |
| 5301 | case NL80211_IFTYPE_AP: |
| 5302 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5303 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5304 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5305 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5306 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5307 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5308 | break; |
| 5309 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5310 | err = -EOPNOTSUPP; |
| 5311 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 5312 | } |
| 5313 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5314 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5315 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5316 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5317 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5318 | if (params.vlan) |
| 5319 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5320 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5321 | return err; |
| 5322 | } |
| 5323 | |
| 5324 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 5325 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5326 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5327 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5328 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5329 | struct station_parameters params; |
| 5330 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5331 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5332 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5333 | |
| 5334 | memset(¶ms, 0, sizeof(params)); |
| 5335 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5336 | if (!rdev->ops->add_station) |
| 5337 | return -EOPNOTSUPP; |
| 5338 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5339 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5340 | return -EINVAL; |
| 5341 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5342 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 5343 | return -EINVAL; |
| 5344 | |
| 5345 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 5346 | return -EINVAL; |
| 5347 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5348 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 5349 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 5350 | return -EINVAL; |
| 5351 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5352 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5353 | params.supported_rates = |
| 5354 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5355 | params.supported_rates_len = |
| 5356 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5357 | params.listen_interval = |
| 5358 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5359 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5360 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 5361 | u8 tmp; |
| 5362 | |
| 5363 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 5364 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 5365 | return -EINVAL; |
| 5366 | |
| 5367 | params.support_p2p_ps = tmp; |
| 5368 | } else { |
| 5369 | /* |
| 5370 | * if not specified, assume it's supported for P2P GO interface, |
| 5371 | * and is NOT supported for AP interface |
| 5372 | */ |
| 5373 | params.support_p2p_ps = |
| 5374 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 5375 | } |
| 5376 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5377 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5378 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5379 | else |
| 5380 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 5381 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 5382 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5383 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 5384 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 5385 | params.capability = |
| 5386 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 5387 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 5388 | } |
| 5389 | |
| 5390 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 5391 | params.ext_capab = |
| 5392 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5393 | params.ext_capab_len = |
| 5394 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5395 | } |
| 5396 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 5397 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 5398 | params.ht_capa = |
| 5399 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5400 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 5401 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 5402 | params.vht_capa = |
| 5403 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 5404 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5405 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 5406 | params.he_capa = |
| 5407 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5408 | params.he_capa_len = |
| 5409 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5410 | |
| 5411 | /* max len is validated in nla policy */ |
| 5412 | if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) |
| 5413 | return -EINVAL; |
| 5414 | } |
| 5415 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 5416 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 5417 | params.opmode_notif_used = true; |
| 5418 | params.opmode_notif = |
| 5419 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 5420 | } |
| 5421 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5422 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5423 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5424 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 5425 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 5426 | return -EINVAL; |
| 5427 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5428 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5429 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 5430 | if (err) |
| 5431 | return err; |
| 5432 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5433 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 5434 | if (err) |
| 5435 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5436 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5437 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5438 | return -EINVAL; |
| 5439 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 5440 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 5441 | * as userspace might just pass through the capabilities from the IEs |
| 5442 | * directly, rather than enforcing this restriction and returning an |
| 5443 | * error in this case. |
| 5444 | */ |
| 5445 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 5446 | params.ht_capa = NULL; |
| 5447 | params.vht_capa = NULL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5448 | |
| 5449 | /* HE requires WME */ |
| 5450 | if (params.he_capa_len) |
| 5451 | return -EINVAL; |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 5452 | } |
| 5453 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5454 | /* When you run into this, adjust the code below for the new flag */ |
| 5455 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5456 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5457 | switch (dev->ieee80211_ptr->iftype) { |
| 5458 | case NL80211_IFTYPE_AP: |
| 5459 | case NL80211_IFTYPE_AP_VLAN: |
| 5460 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5461 | /* ignore WME attributes if iface/sta is not capable */ |
| 5462 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 5463 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 5464 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5465 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5466 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5467 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5468 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5469 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5470 | /* but don't bother the driver with it */ |
| 5471 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5472 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5473 | /* allow authenticated/associated only if driver handles it */ |
| 5474 | if (!(rdev->wiphy.features & |
| 5475 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5476 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5477 | return -EINVAL; |
| 5478 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5479 | /* Older userspace, or userspace wanting to be compatible with |
| 5480 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 5481 | * and assoc flags in the mask, but assumes the station will be |
| 5482 | * added as associated anyway since this was the required driver |
| 5483 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 5484 | * introduced. |
| 5485 | * In order to not bother drivers with this quirk in the API |
| 5486 | * set the flags in both the mask and set for new stations in |
| 5487 | * this case. |
| 5488 | */ |
| 5489 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 5490 | params.sta_flags_mask |= auth_assoc; |
| 5491 | params.sta_flags_set |= auth_assoc; |
| 5492 | } |
| 5493 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5494 | /* must be last in here for error handling */ |
| 5495 | params.vlan = get_vlan(info, rdev); |
| 5496 | if (IS_ERR(params.vlan)) |
| 5497 | return PTR_ERR(params.vlan); |
| 5498 | break; |
| 5499 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5500 | /* ignore uAPSD data */ |
| 5501 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5502 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5503 | /* associated is disallowed */ |
| 5504 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 5505 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5506 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5507 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5508 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5509 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5510 | break; |
| 5511 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 5512 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5513 | /* ignore uAPSD data */ |
| 5514 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5515 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5516 | /* these are disallowed */ |
| 5517 | if (params.sta_flags_mask & |
| 5518 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5519 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5520 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5521 | /* Only TDLS peers can be added */ |
| 5522 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5523 | return -EINVAL; |
| 5524 | /* Can only add if TDLS ... */ |
| 5525 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 5526 | return -EOPNOTSUPP; |
| 5527 | /* ... with external setup is supported */ |
| 5528 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 5529 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5530 | /* |
| 5531 | * Older wpa_supplicant versions always mark the TDLS peer |
| 5532 | * as authorized, but it shouldn't yet be. |
| 5533 | */ |
| 5534 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5535 | break; |
| 5536 | default: |
| 5537 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5538 | } |
| 5539 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5540 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5541 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5542 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5543 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5544 | if (params.vlan) |
| 5545 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5546 | return err; |
| 5547 | } |
| 5548 | |
| 5549 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 5550 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5551 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5552 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5553 | struct station_del_parameters params; |
| 5554 | |
| 5555 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5556 | |
| 5557 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5558 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5559 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5560 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 5561 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5562 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5563 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5564 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5566 | if (!rdev->ops->del_station) |
| 5567 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5568 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 5569 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 5570 | params.subtype = |
| 5571 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 5572 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 5573 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 5574 | return -EINVAL; |
| 5575 | } else { |
| 5576 | /* Default to Deauthentication frame */ |
| 5577 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 5578 | } |
| 5579 | |
| 5580 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 5581 | params.reason_code = |
| 5582 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5583 | if (params.reason_code == 0) |
| 5584 | return -EINVAL; /* 0 is reserved */ |
| 5585 | } else { |
| 5586 | /* Default to reason code 2 */ |
| 5587 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 5588 | } |
| 5589 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5590 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5591 | } |
| 5592 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5593 | 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] | 5594 | int flags, struct net_device *dev, |
| 5595 | u8 *dst, u8 *next_hop, |
| 5596 | struct mpath_info *pinfo) |
| 5597 | { |
| 5598 | void *hdr; |
| 5599 | struct nlattr *pinfoattr; |
| 5600 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 5601 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5602 | if (!hdr) |
| 5603 | return -1; |
| 5604 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5605 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5606 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 5607 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 5608 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 5609 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5610 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5611 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 5612 | if (!pinfoattr) |
| 5613 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5614 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 5615 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 5616 | pinfo->frame_qlen)) |
| 5617 | goto nla_put_failure; |
| 5618 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 5619 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 5620 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 5621 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 5622 | pinfo->metric)) || |
| 5623 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 5624 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 5625 | pinfo->exptime)) || |
| 5626 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 5627 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 5628 | pinfo->flags)) || |
| 5629 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 5630 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 5631 | pinfo->discovery_timeout)) || |
| 5632 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 5633 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 5634 | pinfo->discovery_retries))) |
| 5635 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5636 | |
| 5637 | nla_nest_end(msg, pinfoattr); |
| 5638 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5639 | genlmsg_end(msg, hdr); |
| 5640 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5641 | |
| 5642 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5643 | genlmsg_cancel(msg, hdr); |
| 5644 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5645 | } |
| 5646 | |
| 5647 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5648 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5649 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5650 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5651 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5652 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5653 | u8 dst[ETH_ALEN]; |
| 5654 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5655 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5656 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5657 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5658 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5659 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5660 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5661 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5662 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5663 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5664 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5665 | goto out_err; |
| 5666 | } |
| 5667 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5668 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5669 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 5670 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5671 | } |
| 5672 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5673 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5674 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5675 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5676 | if (err == -ENOENT) |
| 5677 | break; |
| 5678 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5679 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5680 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5681 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5682 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5683 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5684 | &pinfo) < 0) |
| 5685 | goto out; |
| 5686 | |
| 5687 | path_idx++; |
| 5688 | } |
| 5689 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5690 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5691 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5692 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5693 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5694 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5695 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5699 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5701 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5702 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5703 | struct mpath_info pinfo; |
| 5704 | struct sk_buff *msg; |
| 5705 | u8 *dst = NULL; |
| 5706 | u8 next_hop[ETH_ALEN]; |
| 5707 | |
| 5708 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5709 | |
| 5710 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5711 | return -EINVAL; |
| 5712 | |
| 5713 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5714 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5715 | if (!rdev->ops->get_mpath) |
| 5716 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5717 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5718 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5719 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5720 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5721 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5722 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5723 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5724 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5725 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5726 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5727 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5728 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5729 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5730 | dev, dst, next_hop, &pinfo) < 0) { |
| 5731 | nlmsg_free(msg); |
| 5732 | return -ENOBUFS; |
| 5733 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5734 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5735 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5736 | } |
| 5737 | |
| 5738 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5739 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5740 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5741 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5742 | u8 *dst = NULL; |
| 5743 | u8 *next_hop = NULL; |
| 5744 | |
| 5745 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5746 | return -EINVAL; |
| 5747 | |
| 5748 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5749 | return -EINVAL; |
| 5750 | |
| 5751 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5752 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5753 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5754 | if (!rdev->ops->change_mpath) |
| 5755 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5756 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5757 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5758 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5759 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5760 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5761 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5762 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5763 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5764 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5766 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5767 | u8 *dst = NULL; |
| 5768 | u8 *next_hop = NULL; |
| 5769 | |
| 5770 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5771 | return -EINVAL; |
| 5772 | |
| 5773 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5774 | return -EINVAL; |
| 5775 | |
| 5776 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5777 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5778 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5779 | if (!rdev->ops->add_mpath) |
| 5780 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5781 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5782 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5783 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5784 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5785 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5789 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5790 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5791 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5792 | u8 *dst = NULL; |
| 5793 | |
| 5794 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5795 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5796 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5797 | if (!rdev->ops->del_mpath) |
| 5798 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5799 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5800 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5801 | } |
| 5802 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5803 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 5804 | { |
| 5805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5806 | int err; |
| 5807 | struct net_device *dev = info->user_ptr[1]; |
| 5808 | struct mpath_info pinfo; |
| 5809 | struct sk_buff *msg; |
| 5810 | u8 *dst = NULL; |
| 5811 | u8 mpp[ETH_ALEN]; |
| 5812 | |
| 5813 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5814 | |
| 5815 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5816 | return -EINVAL; |
| 5817 | |
| 5818 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5819 | |
| 5820 | if (!rdev->ops->get_mpp) |
| 5821 | return -EOPNOTSUPP; |
| 5822 | |
| 5823 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5824 | return -EOPNOTSUPP; |
| 5825 | |
| 5826 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 5827 | if (err) |
| 5828 | return err; |
| 5829 | |
| 5830 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5831 | if (!msg) |
| 5832 | return -ENOMEM; |
| 5833 | |
| 5834 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 5835 | dev, dst, mpp, &pinfo) < 0) { |
| 5836 | nlmsg_free(msg); |
| 5837 | return -ENOBUFS; |
| 5838 | } |
| 5839 | |
| 5840 | return genlmsg_reply(msg, info); |
| 5841 | } |
| 5842 | |
| 5843 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 5844 | struct netlink_callback *cb) |
| 5845 | { |
| 5846 | struct mpath_info pinfo; |
| 5847 | struct cfg80211_registered_device *rdev; |
| 5848 | struct wireless_dev *wdev; |
| 5849 | u8 dst[ETH_ALEN]; |
| 5850 | u8 mpp[ETH_ALEN]; |
| 5851 | int path_idx = cb->args[2]; |
| 5852 | int err; |
| 5853 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5854 | rtnl_lock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5855 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 5856 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5857 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5858 | |
| 5859 | if (!rdev->ops->dump_mpp) { |
| 5860 | err = -EOPNOTSUPP; |
| 5861 | goto out_err; |
| 5862 | } |
| 5863 | |
| 5864 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5865 | err = -EOPNOTSUPP; |
| 5866 | goto out_err; |
| 5867 | } |
| 5868 | |
| 5869 | while (1) { |
| 5870 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5871 | mpp, &pinfo); |
| 5872 | if (err == -ENOENT) |
| 5873 | break; |
| 5874 | if (err) |
| 5875 | goto out_err; |
| 5876 | |
| 5877 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5878 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5879 | wdev->netdev, dst, mpp, |
| 5880 | &pinfo) < 0) |
| 5881 | goto out; |
| 5882 | |
| 5883 | path_idx++; |
| 5884 | } |
| 5885 | |
| 5886 | out: |
| 5887 | cb->args[2] = path_idx; |
| 5888 | err = skb->len; |
| 5889 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5890 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5891 | return err; |
| 5892 | } |
| 5893 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5894 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5895 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5896 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5897 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5898 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5899 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5900 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5901 | |
| 5902 | memset(¶ms, 0, sizeof(params)); |
| 5903 | /* default to not changing parameters */ |
| 5904 | params.use_cts_prot = -1; |
| 5905 | params.use_short_preamble = -1; |
| 5906 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5907 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5908 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5909 | params.p2p_ctwindow = -1; |
| 5910 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5911 | |
| 5912 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5913 | params.use_cts_prot = |
| 5914 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5915 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5916 | params.use_short_preamble = |
| 5917 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5918 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5919 | params.use_short_slot_time = |
| 5920 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5921 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5922 | params.basic_rates = |
| 5923 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5924 | params.basic_rates_len = |
| 5925 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5926 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5927 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5928 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5929 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5930 | params.ht_opmode = |
| 5931 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5932 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5933 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5934 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5935 | return -EINVAL; |
| 5936 | params.p2p_ctwindow = |
| 5937 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5938 | if (params.p2p_ctwindow < 0) |
| 5939 | return -EINVAL; |
| 5940 | if (params.p2p_ctwindow != 0 && |
| 5941 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5942 | return -EINVAL; |
| 5943 | } |
| 5944 | |
| 5945 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5946 | u8 tmp; |
| 5947 | |
| 5948 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5949 | return -EINVAL; |
| 5950 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5951 | if (tmp > 1) |
| 5952 | return -EINVAL; |
| 5953 | params.p2p_opp_ps = tmp; |
| 5954 | if (params.p2p_opp_ps && |
| 5955 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5956 | return -EINVAL; |
| 5957 | } |
| 5958 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5959 | if (!rdev->ops->change_bss) |
| 5960 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5961 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5962 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5963 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5964 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5965 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5966 | wdev_lock(wdev); |
| 5967 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5968 | wdev_unlock(wdev); |
| 5969 | |
| 5970 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5971 | } |
| 5972 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5973 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5974 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5975 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5976 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5977 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5978 | u32 owner_nlportid; |
| 5979 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5980 | /* |
| 5981 | * You should only get this when cfg80211 hasn't yet initialized |
| 5982 | * completely when built-in to the kernel right between the time |
| 5983 | * window between nl80211_init() and regulatory_init(), if that is |
| 5984 | * even possible. |
| 5985 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5986 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5987 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5988 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5989 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5990 | user_reg_hint_type = |
| 5991 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5992 | else |
| 5993 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5994 | |
| 5995 | switch (user_reg_hint_type) { |
| 5996 | case NL80211_USER_REG_HINT_USER: |
| 5997 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5998 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5999 | return -EINVAL; |
| 6000 | |
| 6001 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6002 | return regulatory_hint_user(data, user_reg_hint_type); |
| 6003 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6004 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 6005 | owner_nlportid = info->snd_portid; |
| 6006 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 6007 | } else { |
| 6008 | owner_nlportid = 0; |
| 6009 | is_indoor = true; |
| 6010 | } |
| 6011 | |
| 6012 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6013 | default: |
| 6014 | return -EINVAL; |
| 6015 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6016 | } |
| 6017 | |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 6018 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
| 6019 | { |
| 6020 | return reg_reload_regdb(); |
| 6021 | } |
| 6022 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6023 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6024 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6025 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6027 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6028 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6029 | struct mesh_config cur_params; |
| 6030 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6031 | void *hdr; |
| 6032 | struct nlattr *pinfoattr; |
| 6033 | struct sk_buff *msg; |
| 6034 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6035 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6036 | return -EOPNOTSUPP; |
| 6037 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6038 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6039 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 6040 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6041 | wdev_lock(wdev); |
| 6042 | /* If not connected, get default parameters */ |
| 6043 | if (!wdev->mesh_id_len) |
| 6044 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 6045 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6046 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6047 | wdev_unlock(wdev); |
| 6048 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6049 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6050 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6051 | |
| 6052 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6053 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6054 | if (!msg) |
| 6055 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6056 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6057 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6058 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6059 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6060 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6061 | if (!pinfoattr) |
| 6062 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6063 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 6064 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 6065 | cur_params.dot11MeshRetryTimeout) || |
| 6066 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 6067 | cur_params.dot11MeshConfirmTimeout) || |
| 6068 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 6069 | cur_params.dot11MeshHoldingTimeout) || |
| 6070 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 6071 | cur_params.dot11MeshMaxPeerLinks) || |
| 6072 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 6073 | cur_params.dot11MeshMaxRetries) || |
| 6074 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 6075 | cur_params.dot11MeshTTL) || |
| 6076 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 6077 | cur_params.element_ttl) || |
| 6078 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 6079 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 6080 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 6081 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6082 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 6083 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 6084 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 6085 | cur_params.path_refresh_time) || |
| 6086 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 6087 | cur_params.min_discovery_timeout) || |
| 6088 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 6089 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 6090 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 6091 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 6092 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 6093 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 6094 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 6095 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 6096 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 6097 | cur_params.dot11MeshHWMPRootMode) || |
| 6098 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 6099 | cur_params.dot11MeshHWMPRannInterval) || |
| 6100 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 6101 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 6102 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 6103 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 6104 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 6105 | cur_params.rssi_threshold) || |
| 6106 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6107 | cur_params.ht_opmode) || |
| 6108 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 6109 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 6110 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6111 | cur_params.dot11MeshHWMProotInterval) || |
| 6112 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6113 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 6114 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 6115 | cur_params.power_mode) || |
| 6116 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6117 | cur_params.dot11MeshAwakeWindowDuration) || |
| 6118 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 6119 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6120 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6121 | nla_nest_end(msg, pinfoattr); |
| 6122 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6123 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6124 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6125 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6126 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6127 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6128 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6129 | } |
| 6130 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6131 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6132 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 6133 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 6134 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 6135 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 6136 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 6137 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 6138 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6139 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6140 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6141 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 6142 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 6143 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 6144 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 6145 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 6146 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6147 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 6148 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 6149 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 6150 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 6151 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6152 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 6153 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6154 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 6155 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6156 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6157 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 6158 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6159 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6160 | }; |
| 6161 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6162 | static const struct nla_policy |
| 6163 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6164 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6165 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 6166 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 6167 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6168 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6169 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6170 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6171 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6172 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6173 | }; |
| 6174 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6175 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
| 6176 | { |
| 6177 | u8 val = nla_get_u8(nla); |
| 6178 | if (val < min || val > max) |
| 6179 | return -EINVAL; |
| 6180 | *out = val; |
| 6181 | return 0; |
| 6182 | } |
| 6183 | |
| 6184 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 6185 | { |
| 6186 | u8 val = nla_get_u8(nla); |
| 6187 | if (val < min || val > max) |
| 6188 | return -EINVAL; |
| 6189 | *out = val; |
| 6190 | return 0; |
| 6191 | } |
| 6192 | |
| 6193 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 6194 | { |
| 6195 | u16 val = nla_get_u16(nla); |
| 6196 | if (val < min || val > max) |
| 6197 | return -EINVAL; |
| 6198 | *out = val; |
| 6199 | return 0; |
| 6200 | } |
| 6201 | |
| 6202 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 6203 | { |
| 6204 | u32 val = nla_get_u32(nla); |
| 6205 | if (val < min || val > max) |
| 6206 | return -EINVAL; |
| 6207 | *out = val; |
| 6208 | return 0; |
| 6209 | } |
| 6210 | |
| 6211 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 6212 | { |
| 6213 | s32 val = nla_get_s32(nla); |
| 6214 | if (val < min || val > max) |
| 6215 | return -EINVAL; |
| 6216 | *out = val; |
| 6217 | return 0; |
| 6218 | } |
| 6219 | |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 6220 | static int nl80211_check_power_mode(const struct nlattr *nla, |
| 6221 | enum nl80211_mesh_power_mode min, |
| 6222 | enum nl80211_mesh_power_mode max, |
| 6223 | enum nl80211_mesh_power_mode *out) |
| 6224 | { |
| 6225 | u32 val = nla_get_u32(nla); |
| 6226 | if (val < min || val > max) |
| 6227 | return -EINVAL; |
| 6228 | *out = val; |
| 6229 | return 0; |
| 6230 | } |
| 6231 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6232 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6233 | struct mesh_config *cfg, |
| 6234 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6235 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6236 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6237 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6238 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6239 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6240 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 6241 | do { \ |
| 6242 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6243 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6244 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6245 | mask |= (1 << (attr - 1)); \ |
| 6246 | } \ |
| 6247 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6248 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6249 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6250 | return -EINVAL; |
| 6251 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6252 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6253 | nl80211_meshconf_params_policy, info->extack)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6254 | return -EINVAL; |
| 6255 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6256 | /* This makes sure that there aren't more than 32 mesh config |
| 6257 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 6258 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 6259 | |
| 6260 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6261 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6262 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6263 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6264 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6265 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6266 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6267 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6268 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6269 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6270 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6271 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6272 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6273 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6274 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6275 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6276 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6277 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6278 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6279 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6280 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6281 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6282 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6283 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6284 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 6285 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6286 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6287 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6288 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6289 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6290 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6291 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6292 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6293 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6294 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6295 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6296 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6297 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 6298 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6299 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6300 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6301 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6302 | 1, 65535, mask, |
| 6303 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6304 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 6305 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6306 | 1, 65535, mask, |
| 6307 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6308 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6309 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6310 | dot11MeshHWMPnetDiameterTraversalTime, |
| 6311 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6312 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6313 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6314 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 6315 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6316 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6317 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 6318 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6319 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 6320 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6321 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 6322 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6323 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6324 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6325 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6326 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 6327 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6328 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6329 | nl80211_check_s32); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6330 | /* |
| 6331 | * Check HT operation mode based on |
| 6332 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. |
| 6333 | */ |
| 6334 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 6335 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 6336 | |
| 6337 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 6338 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 6339 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6340 | return -EINVAL; |
| 6341 | |
| 6342 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && |
| 6343 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6344 | return -EINVAL; |
| 6345 | |
| 6346 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { |
| 6347 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 6348 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 6349 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) |
| 6350 | return -EINVAL; |
| 6351 | break; |
| 6352 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 6353 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 6354 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6355 | return -EINVAL; |
| 6356 | break; |
| 6357 | } |
| 6358 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 6359 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6360 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6361 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6362 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6363 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6364 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6365 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6366 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6367 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6368 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6369 | dot11MeshHWMPconfirmationInterval, |
| 6370 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6371 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6372 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6373 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 6374 | NL80211_MESH_POWER_ACTIVE, |
| 6375 | NL80211_MESH_POWER_MAX, |
| 6376 | mask, NL80211_MESHCONF_POWER_MODE, |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 6377 | nl80211_check_power_mode); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6378 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 6379 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6380 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 6381 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6382 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6383 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6384 | if (mask_out) |
| 6385 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6386 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6387 | return 0; |
| 6388 | |
| 6389 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 6390 | } |
| 6391 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6392 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 6393 | struct mesh_setup *setup) |
| 6394 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6396 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 6397 | |
| 6398 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 6399 | return -EINVAL; |
| 6400 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 6401 | info->attrs[NL80211_ATTR_MESH_SETUP], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6402 | nl80211_mesh_setup_params_policy, info->extack)) |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6403 | return -EINVAL; |
| 6404 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6405 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 6406 | setup->sync_method = |
| 6407 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 6408 | IEEE80211_SYNC_METHOD_VENDOR : |
| 6409 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 6410 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6411 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 6412 | setup->path_sel_proto = |
| 6413 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 6414 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 6415 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 6416 | |
| 6417 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 6418 | setup->path_metric = |
| 6419 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 6420 | IEEE80211_PATH_METRIC_VENDOR : |
| 6421 | IEEE80211_PATH_METRIC_AIRTIME; |
| 6422 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6423 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6424 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6425 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6426 | if (!is_valid_ie_attr(ieattr)) |
| 6427 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6428 | setup->ie = nla_data(ieattr); |
| 6429 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6430 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6431 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 6432 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 6433 | return -EINVAL; |
| 6434 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6435 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 6436 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6437 | if (setup->is_secure) |
| 6438 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6439 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6440 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 6441 | if (!setup->user_mpm) |
| 6442 | return -EINVAL; |
| 6443 | setup->auth_id = |
| 6444 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 6445 | } |
| 6446 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6447 | return 0; |
| 6448 | } |
| 6449 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6450 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6451 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6452 | { |
| 6453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6454 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6455 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6456 | struct mesh_config cfg; |
| 6457 | u32 mask; |
| 6458 | int err; |
| 6459 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6460 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6461 | return -EOPNOTSUPP; |
| 6462 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6463 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6464 | return -EOPNOTSUPP; |
| 6465 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6466 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6467 | if (err) |
| 6468 | return err; |
| 6469 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6470 | wdev_lock(wdev); |
| 6471 | if (!wdev->mesh_id_len) |
| 6472 | err = -ENOLINK; |
| 6473 | |
| 6474 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6475 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6476 | |
| 6477 | wdev_unlock(wdev); |
| 6478 | |
| 6479 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6480 | } |
| 6481 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6482 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 6483 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6484 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6485 | struct nlattr *nl_reg_rules; |
| 6486 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6487 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6488 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 6489 | (regdom->dfs_region && |
| 6490 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6491 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6492 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6493 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 6494 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6495 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6496 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6497 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6498 | struct nlattr *nl_reg_rule; |
| 6499 | const struct ieee80211_reg_rule *reg_rule; |
| 6500 | const struct ieee80211_freq_range *freq_range; |
| 6501 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6502 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6503 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6504 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6505 | freq_range = ®_rule->freq_range; |
| 6506 | power_rule = ®_rule->power_rule; |
| 6507 | |
| 6508 | nl_reg_rule = nla_nest_start(msg, i); |
| 6509 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6510 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6511 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6512 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 6513 | if (!max_bandwidth_khz) |
| 6514 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 6515 | reg_rule); |
| 6516 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6517 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 6518 | reg_rule->flags) || |
| 6519 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 6520 | freq_range->start_freq_khz) || |
| 6521 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 6522 | freq_range->end_freq_khz) || |
| 6523 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6524 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6525 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 6526 | power_rule->max_antenna_gain) || |
| 6527 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 6528 | power_rule->max_eirp) || |
| 6529 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 6530 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6531 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6532 | |
| 6533 | nla_nest_end(msg, nl_reg_rule); |
| 6534 | } |
| 6535 | |
| 6536 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6537 | return 0; |
| 6538 | |
| 6539 | nla_put_failure: |
| 6540 | return -EMSGSIZE; |
| 6541 | } |
| 6542 | |
| 6543 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 6544 | { |
| 6545 | const struct ieee80211_regdomain *regdom = NULL; |
| 6546 | struct cfg80211_registered_device *rdev; |
| 6547 | struct wiphy *wiphy = NULL; |
| 6548 | struct sk_buff *msg; |
| 6549 | void *hdr; |
| 6550 | |
| 6551 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6552 | if (!msg) |
| 6553 | return -ENOBUFS; |
| 6554 | |
| 6555 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 6556 | NL80211_CMD_GET_REG); |
| 6557 | if (!hdr) |
| 6558 | goto put_failure; |
| 6559 | |
| 6560 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6561 | bool self_managed; |
| 6562 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6563 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 6564 | if (IS_ERR(rdev)) { |
| 6565 | nlmsg_free(msg); |
| 6566 | return PTR_ERR(rdev); |
| 6567 | } |
| 6568 | |
| 6569 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6570 | self_managed = wiphy->regulatory_flags & |
| 6571 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6572 | regdom = get_wiphy_regdom(wiphy); |
| 6573 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6574 | /* a self-managed-reg device must have a private regdom */ |
| 6575 | if (WARN_ON(!regdom && self_managed)) { |
| 6576 | nlmsg_free(msg); |
| 6577 | return -EINVAL; |
| 6578 | } |
| 6579 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6580 | if (regdom && |
| 6581 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6582 | goto nla_put_failure; |
| 6583 | } |
| 6584 | |
| 6585 | if (!wiphy && reg_last_request_cell_base() && |
| 6586 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6587 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6588 | goto nla_put_failure; |
| 6589 | |
| 6590 | rcu_read_lock(); |
| 6591 | |
| 6592 | if (!regdom) |
| 6593 | regdom = rcu_dereference(cfg80211_regdomain); |
| 6594 | |
| 6595 | if (nl80211_put_regdom(regdom, msg)) |
| 6596 | goto nla_put_failure_rcu; |
| 6597 | |
| 6598 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6599 | |
| 6600 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6601 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6602 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6603 | nla_put_failure_rcu: |
| 6604 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6605 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6606 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6607 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6608 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6609 | } |
| 6610 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6611 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 6612 | u32 seq, int flags, struct wiphy *wiphy, |
| 6613 | const struct ieee80211_regdomain *regdom) |
| 6614 | { |
| 6615 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 6616 | NL80211_CMD_GET_REG); |
| 6617 | |
| 6618 | if (!hdr) |
| 6619 | return -1; |
| 6620 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 6621 | genl_dump_check_consistent(cb, hdr); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6622 | |
| 6623 | if (nl80211_put_regdom(regdom, msg)) |
| 6624 | goto nla_put_failure; |
| 6625 | |
| 6626 | if (!wiphy && reg_last_request_cell_base() && |
| 6627 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6628 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6629 | goto nla_put_failure; |
| 6630 | |
| 6631 | if (wiphy && |
| 6632 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6633 | goto nla_put_failure; |
| 6634 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6635 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 6636 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 6637 | goto nla_put_failure; |
| 6638 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6639 | genlmsg_end(msg, hdr); |
| 6640 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6641 | |
| 6642 | nla_put_failure: |
| 6643 | genlmsg_cancel(msg, hdr); |
| 6644 | return -EMSGSIZE; |
| 6645 | } |
| 6646 | |
| 6647 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 6648 | struct netlink_callback *cb) |
| 6649 | { |
| 6650 | const struct ieee80211_regdomain *regdom = NULL; |
| 6651 | struct cfg80211_registered_device *rdev; |
| 6652 | int err, reg_idx, start = cb->args[2]; |
| 6653 | |
| 6654 | rtnl_lock(); |
| 6655 | |
| 6656 | if (cfg80211_regdomain && start == 0) { |
| 6657 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6658 | NLM_F_MULTI, NULL, |
| 6659 | rtnl_dereference(cfg80211_regdomain)); |
| 6660 | if (err < 0) |
| 6661 | goto out_err; |
| 6662 | } |
| 6663 | |
| 6664 | /* the global regdom is idx 0 */ |
| 6665 | reg_idx = 1; |
| 6666 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 6667 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 6668 | if (!regdom) |
| 6669 | continue; |
| 6670 | |
| 6671 | if (++reg_idx <= start) |
| 6672 | continue; |
| 6673 | |
| 6674 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6675 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 6676 | if (err < 0) { |
| 6677 | reg_idx--; |
| 6678 | break; |
| 6679 | } |
| 6680 | } |
| 6681 | |
| 6682 | cb->args[2] = reg_idx; |
| 6683 | err = skb->len; |
| 6684 | out_err: |
| 6685 | rtnl_unlock(); |
| 6686 | return err; |
| 6687 | } |
| 6688 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6689 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 6690 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 6691 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6692 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6693 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6694 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6695 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6696 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6697 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 6698 | }; |
| 6699 | |
| 6700 | static int parse_reg_rule(struct nlattr *tb[], |
| 6701 | struct ieee80211_reg_rule *reg_rule) |
| 6702 | { |
| 6703 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 6704 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 6705 | |
| 6706 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6707 | return -EINVAL; |
| 6708 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 6709 | return -EINVAL; |
| 6710 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 6711 | return -EINVAL; |
| 6712 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6713 | return -EINVAL; |
| 6714 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6715 | return -EINVAL; |
| 6716 | |
| 6717 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 6718 | |
| 6719 | freq_range->start_freq_khz = |
| 6720 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 6721 | freq_range->end_freq_khz = |
| 6722 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 6723 | freq_range->max_bandwidth_khz = |
| 6724 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 6725 | |
| 6726 | power_rule->max_eirp = |
| 6727 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 6728 | |
| 6729 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 6730 | power_rule->max_antenna_gain = |
| 6731 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 6732 | |
| 6733 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 6734 | reg_rule->dfs_cac_ms = |
| 6735 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 6736 | |
| 6737 | return 0; |
| 6738 | } |
| 6739 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6740 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6741 | { |
| 6742 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 6743 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6744 | char *alpha2; |
| 6745 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6746 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 6747 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6748 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6749 | |
| 6750 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6751 | return -EINVAL; |
| 6752 | |
| 6753 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 6754 | return -EINVAL; |
| 6755 | |
| 6756 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6757 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6758 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 6759 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 6760 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6761 | 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] | 6762 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6763 | num_rules++; |
| 6764 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 6765 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6766 | } |
| 6767 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 6768 | if (!reg_is_valid_request(alpha2)) |
| 6769 | return -EINVAL; |
| 6770 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6771 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6772 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6773 | |
| 6774 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 6775 | if (!rd) |
| 6776 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6777 | |
| 6778 | rd->n_reg_rules = num_rules; |
| 6779 | rd->alpha2[0] = alpha2[0]; |
| 6780 | rd->alpha2[1] = alpha2[1]; |
| 6781 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6782 | /* |
| 6783 | * Disable DFS master mode if the DFS region was |
| 6784 | * not supported or known on this kernel. |
| 6785 | */ |
| 6786 | if (reg_supported_dfs_region(dfs_region)) |
| 6787 | rd->dfs_region = dfs_region; |
| 6788 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6789 | 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] | 6790 | rem_reg_rules) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6791 | r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6792 | nl_reg_rule, reg_rule_policy, |
| 6793 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6794 | if (r) |
| 6795 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6796 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 6797 | if (r) |
| 6798 | goto bad_reg; |
| 6799 | |
| 6800 | rule_idx++; |
| 6801 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6802 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 6803 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6804 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6805 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6806 | } |
| 6807 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 6808 | /* set_regdom takes ownership of rd */ |
| 6809 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 6810 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6811 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6812 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6813 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6814 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6815 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6816 | static int validate_scan_freqs(struct nlattr *freqs) |
| 6817 | { |
| 6818 | struct nlattr *attr1, *attr2; |
| 6819 | int n_channels = 0, tmp1, tmp2; |
| 6820 | |
Srinivas Dasari | d7f13f7 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 6821 | nla_for_each_nested(attr1, freqs, tmp1) |
| 6822 | if (nla_len(attr1) != sizeof(u32)) |
| 6823 | return 0; |
| 6824 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6825 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 6826 | n_channels++; |
| 6827 | /* |
| 6828 | * Some hardware has a limited channel list for |
| 6829 | * scanning, and it is pretty much nonsensical |
| 6830 | * to scan for a channel twice, so disallow that |
| 6831 | * and don't require drivers to check that the |
| 6832 | * channel list they get isn't longer than what |
| 6833 | * they can scan, as long as they can scan all |
| 6834 | * the channels they registered at once. |
| 6835 | */ |
| 6836 | nla_for_each_nested(attr2, freqs, tmp2) |
| 6837 | if (attr1 != attr2 && |
| 6838 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 6839 | return 0; |
| 6840 | } |
| 6841 | |
| 6842 | return n_channels; |
| 6843 | } |
| 6844 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6845 | 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] | 6846 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6847 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6848 | } |
| 6849 | |
| 6850 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 6851 | struct cfg80211_bss_selection *bss_select) |
| 6852 | { |
| 6853 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 6854 | struct nlattr *nest; |
| 6855 | int err; |
| 6856 | bool found = false; |
| 6857 | int i; |
| 6858 | |
| 6859 | /* only process one nested attribute */ |
| 6860 | nest = nla_data(nla); |
| 6861 | if (!nla_ok(nest, nla_len(nest))) |
| 6862 | return -EINVAL; |
| 6863 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6864 | err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 6865 | nl80211_bss_select_policy, NULL); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6866 | if (err) |
| 6867 | return err; |
| 6868 | |
| 6869 | /* only one attribute may be given */ |
| 6870 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 6871 | if (attr[i]) { |
| 6872 | if (found) |
| 6873 | return -EINVAL; |
| 6874 | found = true; |
| 6875 | } |
| 6876 | } |
| 6877 | |
| 6878 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 6879 | |
| 6880 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 6881 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 6882 | |
| 6883 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 6884 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 6885 | bss_select->param.band_pref = |
| 6886 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6887 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6888 | return -EINVAL; |
| 6889 | } |
| 6890 | |
| 6891 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6892 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6893 | |
| 6894 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6895 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6896 | bss_select->param.adjust.band = adj_param->band; |
| 6897 | bss_select->param.adjust.delta = adj_param->delta; |
| 6898 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6899 | return -EINVAL; |
| 6900 | } |
| 6901 | |
| 6902 | /* user-space did not provide behaviour attribute */ |
| 6903 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6904 | return -EINVAL; |
| 6905 | |
| 6906 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6907 | return -EINVAL; |
| 6908 | |
| 6909 | return 0; |
| 6910 | } |
| 6911 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6912 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6913 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6914 | { |
| 6915 | int i; |
| 6916 | |
| 6917 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6918 | eth_zero_addr(mac_addr); |
| 6919 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6920 | mac_addr[0] = 0x2; |
| 6921 | mac_addr_mask[0] = 0x3; |
| 6922 | |
| 6923 | return 0; |
| 6924 | } |
| 6925 | |
| 6926 | /* need both or none */ |
| 6927 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6928 | return -EINVAL; |
| 6929 | |
| 6930 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6931 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6932 | |
| 6933 | /* don't allow or configure an mcast address */ |
| 6934 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6935 | is_multicast_ether_addr(mac_addr)) |
| 6936 | return -EINVAL; |
| 6937 | |
| 6938 | /* |
| 6939 | * allow users to pass a MAC address that has bits set outside |
| 6940 | * of the mask, but don't bother drivers with having to deal |
| 6941 | * with such bits |
| 6942 | */ |
| 6943 | for (i = 0; i < ETH_ALEN; i++) |
| 6944 | mac_addr[i] &= mac_addr_mask[i]; |
| 6945 | |
| 6946 | return 0; |
| 6947 | } |
| 6948 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 6949 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 6950 | { |
| 6951 | ASSERT_WDEV_LOCK(wdev); |
| 6952 | |
| 6953 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 6954 | return true; |
| 6955 | |
| 6956 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 6957 | return true; |
| 6958 | |
| 6959 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 6960 | } |
| 6961 | |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 6962 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, |
| 6963 | enum nl80211_ext_feature_index feat) |
| 6964 | { |
| 6965 | if (!(flags & flag)) |
| 6966 | return true; |
| 6967 | if (wiphy_ext_feature_isset(wiphy, feat)) |
| 6968 | return true; |
| 6969 | return false; |
| 6970 | } |
| 6971 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 6972 | static int |
| 6973 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 6974 | void *request, struct nlattr **attrs, |
| 6975 | bool is_sched_scan) |
| 6976 | { |
| 6977 | u8 *mac_addr, *mac_addr_mask; |
| 6978 | u32 *flags; |
| 6979 | enum nl80211_feature_flags randomness_flag; |
| 6980 | |
| 6981 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) |
| 6982 | return 0; |
| 6983 | |
| 6984 | if (is_sched_scan) { |
| 6985 | struct cfg80211_sched_scan_request *req = request; |
| 6986 | |
| 6987 | randomness_flag = wdev ? |
| 6988 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : |
| 6989 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6990 | flags = &req->flags; |
| 6991 | mac_addr = req->mac_addr; |
| 6992 | mac_addr_mask = req->mac_addr_mask; |
| 6993 | } else { |
| 6994 | struct cfg80211_scan_request *req = request; |
| 6995 | |
| 6996 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 6997 | flags = &req->flags; |
| 6998 | mac_addr = req->mac_addr; |
| 6999 | mac_addr_mask = req->mac_addr_mask; |
| 7000 | } |
| 7001 | |
| 7002 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); |
| 7003 | |
Sunil Dutt | 5037a00 | 2018-01-25 17:13:37 +0200 | [diff] [blame] | 7004 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 7005 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 7006 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7007 | NL80211_SCAN_FLAG_LOW_SPAN, |
| 7008 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || |
| 7009 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7010 | NL80211_SCAN_FLAG_LOW_POWER, |
| 7011 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || |
| 7012 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7013 | NL80211_SCAN_FLAG_HIGH_ACCURACY, |
| 7014 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || |
| 7015 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7016 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, |
| 7017 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || |
| 7018 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7019 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, |
| 7020 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || |
| 7021 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7022 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, |
| 7023 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || |
| 7024 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7025 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, |
Johannes Berg | 2e076f1 | 2018-05-28 15:47:40 +0200 | [diff] [blame] | 7026 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || |
| 7027 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7028 | NL80211_SCAN_FLAG_RANDOM_SN, |
| 7029 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || |
| 7030 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7031 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, |
| 7032 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7033 | return -EOPNOTSUPP; |
| 7034 | |
| 7035 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 7036 | int err; |
| 7037 | |
| 7038 | if (!(wiphy->features & randomness_flag) || |
| 7039 | (wdev && wdev->current_bss)) |
| 7040 | return -EOPNOTSUPP; |
| 7041 | |
| 7042 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); |
| 7043 | if (err) |
| 7044 | return err; |
| 7045 | } |
| 7046 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7047 | return 0; |
| 7048 | } |
| 7049 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7050 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 7051 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7052 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7053 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7054 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7055 | struct nlattr *attr; |
| 7056 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7057 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7058 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7059 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7060 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7061 | return -EINVAL; |
| 7062 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7063 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7064 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 7065 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 7066 | return -EOPNOTSUPP; |
| 7067 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7068 | if (!rdev->ops->scan) |
| 7069 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7070 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 7071 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7072 | err = -EBUSY; |
| 7073 | goto unlock; |
| 7074 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7075 | |
| 7076 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7077 | n_channels = validate_scan_freqs( |
| 7078 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7079 | if (!n_channels) { |
| 7080 | err = -EINVAL; |
| 7081 | goto unlock; |
| 7082 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7083 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7084 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7085 | } |
| 7086 | |
| 7087 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7088 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 7089 | n_ssids++; |
| 7090 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7091 | if (n_ssids > wiphy->max_scan_ssids) { |
| 7092 | err = -EINVAL; |
| 7093 | goto unlock; |
| 7094 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7095 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7096 | if (info->attrs[NL80211_ATTR_IE]) |
| 7097 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7098 | else |
| 7099 | ie_len = 0; |
| 7100 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7101 | if (ie_len > wiphy->max_scan_ie_len) { |
| 7102 | err = -EINVAL; |
| 7103 | goto unlock; |
| 7104 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 7105 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7106 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7107 | + sizeof(*request->ssids) * n_ssids |
| 7108 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7109 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7110 | if (!request) { |
| 7111 | err = -ENOMEM; |
| 7112 | goto unlock; |
| 7113 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7114 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7115 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 7116 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7117 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7118 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7119 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7120 | request->ie = (void *)(request->ssids + n_ssids); |
| 7121 | else |
| 7122 | request->ie = (void *)(request->channels + n_channels); |
| 7123 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7124 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7125 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7126 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 7127 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7128 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7129 | struct ieee80211_channel *chan; |
| 7130 | |
| 7131 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7132 | |
| 7133 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7134 | err = -EINVAL; |
| 7135 | goto out_free; |
| 7136 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7137 | |
| 7138 | /* ignore disabled channels */ |
| 7139 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7140 | continue; |
| 7141 | |
| 7142 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7143 | i++; |
| 7144 | } |
| 7145 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7146 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7147 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7148 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7149 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7150 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7151 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7152 | if (!wiphy->bands[band]) |
| 7153 | continue; |
| 7154 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7155 | struct ieee80211_channel *chan; |
| 7156 | |
| 7157 | chan = &wiphy->bands[band]->channels[j]; |
| 7158 | |
| 7159 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7160 | continue; |
| 7161 | |
| 7162 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7163 | i++; |
| 7164 | } |
| 7165 | } |
| 7166 | } |
| 7167 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7168 | if (!i) { |
| 7169 | err = -EINVAL; |
| 7170 | goto out_free; |
| 7171 | } |
| 7172 | |
| 7173 | request->n_channels = i; |
| 7174 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 7175 | wdev_lock(wdev); |
| 7176 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 7177 | struct ieee80211_channel *chan; |
| 7178 | |
| 7179 | if (request->n_channels != 1) { |
| 7180 | wdev_unlock(wdev); |
| 7181 | err = -EBUSY; |
| 7182 | goto out_free; |
| 7183 | } |
| 7184 | |
| 7185 | chan = request->channels[0]; |
| 7186 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 7187 | wdev_unlock(wdev); |
| 7188 | err = -EBUSY; |
| 7189 | goto out_free; |
| 7190 | } |
| 7191 | } |
| 7192 | wdev_unlock(wdev); |
| 7193 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7194 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7195 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7196 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7197 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7198 | err = -EINVAL; |
| 7199 | goto out_free; |
| 7200 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7201 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7202 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7203 | i++; |
| 7204 | } |
| 7205 | } |
| 7206 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7207 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7208 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54b | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 7209 | memcpy((void *)request->ie, |
| 7210 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7211 | request->ie_len); |
| 7212 | } |
| 7213 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7214 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 7215 | if (wiphy->bands[i]) |
| 7216 | request->rates[i] = |
| 7217 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7218 | |
| 7219 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 7220 | nla_for_each_nested(attr, |
| 7221 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 7222 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7223 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7224 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7225 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7226 | err = -EINVAL; |
| 7227 | goto out_free; |
| 7228 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 7229 | |
| 7230 | if (!wiphy->bands[band]) |
| 7231 | continue; |
| 7232 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7233 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 7234 | nla_data(attr), |
| 7235 | nla_len(attr), |
| 7236 | &request->rates[band]); |
| 7237 | if (err) |
| 7238 | goto out_free; |
| 7239 | } |
| 7240 | } |
| 7241 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7242 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 7243 | if (!wiphy_ext_feature_isset(wiphy, |
| 7244 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 7245 | err = -EOPNOTSUPP; |
| 7246 | goto out_free; |
| 7247 | } |
| 7248 | |
| 7249 | request->duration = |
| 7250 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 7251 | request->duration_mandatory = |
| 7252 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 7253 | } |
| 7254 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7255 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
| 7256 | false); |
| 7257 | if (err) |
| 7258 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7259 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7260 | request->no_cck = |
| 7261 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7262 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 7263 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 7264 | * BSSID to scan for. This was problematic because that same attribute |
| 7265 | * was already used for another purpose (local random MAC address). The |
| 7266 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 7267 | * compatibility with older userspace components, also use the |
| 7268 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 7269 | * the specific BSSID use case instead of the random MAC address |
| 7270 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 7271 | */ |
| 7272 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 7273 | memcpy(request->bssid, |
| 7274 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 7275 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 7276 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 7277 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 7278 | ETH_ALEN); |
| 7279 | else |
| 7280 | eth_broadcast_addr(request->bssid); |
| 7281 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7282 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7283 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7284 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7285 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7286 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7287 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7288 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7289 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7290 | nl80211_send_scan_start(rdev, wdev); |
| 7291 | if (wdev->netdev) |
| 7292 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7293 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7294 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7295 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7296 | kfree(request); |
| 7297 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7298 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7299 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7300 | return err; |
| 7301 | } |
| 7302 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 7303 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 7304 | { |
| 7305 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7306 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7307 | |
| 7308 | if (!rdev->ops->abort_scan) |
| 7309 | return -EOPNOTSUPP; |
| 7310 | |
| 7311 | if (rdev->scan_msg) |
| 7312 | return 0; |
| 7313 | |
| 7314 | if (!rdev->scan_req) |
| 7315 | return -ENOENT; |
| 7316 | |
| 7317 | rdev_abort_scan(rdev, wdev); |
| 7318 | return 0; |
| 7319 | } |
| 7320 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7321 | static int |
| 7322 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 7323 | struct cfg80211_sched_scan_request *request, |
| 7324 | struct nlattr **attrs) |
| 7325 | { |
| 7326 | int tmp, err, i = 0; |
| 7327 | struct nlattr *attr; |
| 7328 | |
| 7329 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 7330 | u32 interval; |
| 7331 | |
| 7332 | /* |
| 7333 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 7334 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7335 | * case one scan plan will be set with the specified scan |
| 7336 | * interval and infinite number of iterations. |
| 7337 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7338 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 7339 | if (!interval) |
| 7340 | return -EINVAL; |
| 7341 | |
| 7342 | request->scan_plans[0].interval = |
| 7343 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 7344 | if (!request->scan_plans[0].interval) |
| 7345 | return -EINVAL; |
| 7346 | |
| 7347 | if (request->scan_plans[0].interval > |
| 7348 | wiphy->max_sched_scan_plan_interval) |
| 7349 | request->scan_plans[0].interval = |
| 7350 | wiphy->max_sched_scan_plan_interval; |
| 7351 | |
| 7352 | return 0; |
| 7353 | } |
| 7354 | |
| 7355 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 7356 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 7357 | |
| 7358 | if (WARN_ON(i >= n_plans)) |
| 7359 | return -EINVAL; |
| 7360 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7361 | err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7362 | attr, nl80211_plan_policy, NULL); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7363 | if (err) |
| 7364 | return err; |
| 7365 | |
| 7366 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 7367 | return -EINVAL; |
| 7368 | |
| 7369 | request->scan_plans[i].interval = |
| 7370 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 7371 | if (!request->scan_plans[i].interval || |
| 7372 | request->scan_plans[i].interval > |
| 7373 | wiphy->max_sched_scan_plan_interval) |
| 7374 | return -EINVAL; |
| 7375 | |
| 7376 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 7377 | request->scan_plans[i].iterations = |
| 7378 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 7379 | if (!request->scan_plans[i].iterations || |
| 7380 | (request->scan_plans[i].iterations > |
| 7381 | wiphy->max_sched_scan_plan_iterations)) |
| 7382 | return -EINVAL; |
| 7383 | } else if (i < n_plans - 1) { |
| 7384 | /* |
| 7385 | * All scan plans but the last one must specify |
| 7386 | * a finite number of iterations |
| 7387 | */ |
| 7388 | return -EINVAL; |
| 7389 | } |
| 7390 | |
| 7391 | i++; |
| 7392 | } |
| 7393 | |
| 7394 | /* |
| 7395 | * The last scan plan must not specify the number of |
| 7396 | * iterations, it is supposed to run infinitely |
| 7397 | */ |
| 7398 | if (request->scan_plans[n_plans - 1].iterations) |
| 7399 | return -EINVAL; |
| 7400 | |
| 7401 | return 0; |
| 7402 | } |
| 7403 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7404 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7405 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7406 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7407 | { |
| 7408 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7409 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7410 | 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] | 7411 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7412 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7413 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7414 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7415 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7416 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 7417 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7418 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7419 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7420 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7421 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7422 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7423 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7424 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7425 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7426 | } |
| 7427 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7428 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7429 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7430 | tmp) |
| 7431 | n_ssids++; |
| 7432 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 7433 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7434 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7435 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7436 | /* |
| 7437 | * First, count the number of 'real' matchsets. Due to an issue with |
| 7438 | * the old implementation, matchsets containing only the RSSI attribute |
| 7439 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 7440 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 7441 | * all APs with a strong RSSI. This is needed to be compatible with |
| 7442 | * older userspace that treated a matchset with only the RSSI as the |
| 7443 | * global RSSI for all other matchsets - if there are other matchsets. |
| 7444 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7445 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7446 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7447 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7448 | tmp) { |
| 7449 | struct nlattr *rssi; |
| 7450 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7451 | err = nla_parse_nested(tb, |
| 7452 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7453 | attr, nl80211_match_policy, |
| 7454 | NULL); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7455 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7456 | return ERR_PTR(err); |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7457 | |
| 7458 | /* SSID and BSSID are mutually exclusive */ |
| 7459 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 7460 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 7461 | return ERR_PTR(-EINVAL); |
| 7462 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7463 | /* add other standalone attributes here */ |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7464 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 7465 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7466 | n_match_sets++; |
| 7467 | continue; |
| 7468 | } |
| 7469 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7470 | if (rssi) |
| 7471 | default_match_rssi = nla_get_s32(rssi); |
| 7472 | } |
| 7473 | } |
| 7474 | |
| 7475 | /* However, if there's no other matchset, add the RSSI one */ |
| 7476 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 7477 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7478 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7479 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7480 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7481 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7482 | if (attrs[NL80211_ATTR_IE]) |
| 7483 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7484 | else |
| 7485 | ie_len = 0; |
| 7486 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 7487 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7488 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 7489 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7490 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 7491 | /* |
| 7492 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 7493 | * each scan plan already specifies its own interval |
| 7494 | */ |
| 7495 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7496 | return ERR_PTR(-EINVAL); |
| 7497 | |
| 7498 | nla_for_each_nested(attr, |
| 7499 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 7500 | n_plans++; |
| 7501 | } else { |
| 7502 | /* |
| 7503 | * The scan interval attribute is kept for backward |
| 7504 | * compatibility. If no scan plans are specified and sched scan |
| 7505 | * interval is specified, one scan plan will be set with this |
| 7506 | * scan interval and infinite number of iterations. |
| 7507 | */ |
| 7508 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7509 | return ERR_PTR(-EINVAL); |
| 7510 | |
| 7511 | n_plans = 1; |
| 7512 | } |
| 7513 | |
| 7514 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 7515 | return ERR_PTR(-EINVAL); |
| 7516 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7517 | if (!wiphy_ext_feature_isset( |
| 7518 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 7519 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 7520 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 7521 | return ERR_PTR(-EINVAL); |
| 7522 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7523 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7524 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7525 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7526 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7527 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7528 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7529 | if (!request) |
| 7530 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7531 | |
| 7532 | if (n_ssids) |
| 7533 | request->ssids = (void *)&request->channels[n_channels]; |
| 7534 | request->n_ssids = n_ssids; |
| 7535 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7536 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7537 | request->ie = (void *)(request->ssids + n_ssids); |
| 7538 | else |
| 7539 | request->ie = (void *)(request->channels + n_channels); |
| 7540 | } |
| 7541 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7542 | if (n_match_sets) { |
| 7543 | if (request->ie) |
| 7544 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7545 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7546 | request->match_sets = |
| 7547 | (void *)(request->ssids + n_ssids); |
| 7548 | else |
| 7549 | request->match_sets = |
| 7550 | (void *)(request->channels + n_channels); |
| 7551 | } |
| 7552 | request->n_match_sets = n_match_sets; |
| 7553 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7554 | if (n_match_sets) |
| 7555 | request->scan_plans = (void *)(request->match_sets + |
| 7556 | n_match_sets); |
| 7557 | else if (request->ie) |
| 7558 | request->scan_plans = (void *)(request->ie + ie_len); |
| 7559 | else if (n_ssids) |
| 7560 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 7561 | else |
| 7562 | request->scan_plans = (void *)(request->channels + n_channels); |
| 7563 | |
| 7564 | request->n_scan_plans = n_plans; |
| 7565 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7566 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7567 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7568 | /* user specified, bail out if channel not found */ |
| 7569 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7570 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7571 | tmp) { |
| 7572 | struct ieee80211_channel *chan; |
| 7573 | |
| 7574 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7575 | |
| 7576 | if (!chan) { |
| 7577 | err = -EINVAL; |
| 7578 | goto out_free; |
| 7579 | } |
| 7580 | |
| 7581 | /* ignore disabled channels */ |
| 7582 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7583 | continue; |
| 7584 | |
| 7585 | request->channels[i] = chan; |
| 7586 | i++; |
| 7587 | } |
| 7588 | } else { |
| 7589 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7590 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7591 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7592 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7593 | if (!wiphy->bands[band]) |
| 7594 | continue; |
| 7595 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 7596 | struct ieee80211_channel *chan; |
| 7597 | |
| 7598 | chan = &wiphy->bands[band]->channels[j]; |
| 7599 | |
| 7600 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7601 | continue; |
| 7602 | |
| 7603 | request->channels[i] = chan; |
| 7604 | i++; |
| 7605 | } |
| 7606 | } |
| 7607 | } |
| 7608 | |
| 7609 | if (!i) { |
| 7610 | err = -EINVAL; |
| 7611 | goto out_free; |
| 7612 | } |
| 7613 | |
| 7614 | request->n_channels = i; |
| 7615 | |
| 7616 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7617 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7618 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7619 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7620 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7621 | err = -EINVAL; |
| 7622 | goto out_free; |
| 7623 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7624 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7625 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 7626 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7627 | i++; |
| 7628 | } |
| 7629 | } |
| 7630 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7631 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7632 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7633 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7634 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7635 | tmp) { |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7636 | struct nlattr *ssid, *bssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7637 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7638 | err = nla_parse_nested(tb, |
| 7639 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7640 | attr, nl80211_match_policy, |
| 7641 | NULL); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7642 | if (err) |
| 7643 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 7644 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7645 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
| 7646 | if (ssid || bssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7647 | if (WARN_ON(i >= n_match_sets)) { |
| 7648 | /* this indicates a programming error, |
| 7649 | * the loop above should have verified |
| 7650 | * things properly |
| 7651 | */ |
| 7652 | err = -EINVAL; |
| 7653 | goto out_free; |
| 7654 | } |
| 7655 | |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7656 | if (ssid) { |
| 7657 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 7658 | err = -EINVAL; |
| 7659 | goto out_free; |
| 7660 | } |
| 7661 | memcpy(request->match_sets[i].ssid.ssid, |
| 7662 | nla_data(ssid), nla_len(ssid)); |
| 7663 | request->match_sets[i].ssid.ssid_len = |
| 7664 | nla_len(ssid); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7665 | } |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7666 | if (bssid) { |
| 7667 | if (nla_len(bssid) != ETH_ALEN) { |
| 7668 | err = -EINVAL; |
| 7669 | goto out_free; |
| 7670 | } |
| 7671 | memcpy(request->match_sets[i].bssid, |
| 7672 | nla_data(bssid), ETH_ALEN); |
| 7673 | } |
| 7674 | |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 7675 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7676 | request->match_sets[i].rssi_thold = |
| 7677 | default_match_rssi; |
| 7678 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7679 | if (rssi) |
| 7680 | request->match_sets[i].rssi_thold = |
| 7681 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7682 | } |
| 7683 | i++; |
| 7684 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7685 | |
| 7686 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 7687 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7688 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 7689 | |
| 7690 | request->min_rssi_thold = INT_MAX; |
| 7691 | for (i = 0; i < n_match_sets; i++) |
| 7692 | request->min_rssi_thold = |
| 7693 | min(request->match_sets[i].rssi_thold, |
| 7694 | request->min_rssi_thold); |
| 7695 | } else { |
| 7696 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7697 | } |
| 7698 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 7699 | if (ie_len) { |
| 7700 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7701 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7702 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7703 | request->ie_len); |
| 7704 | } |
| 7705 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7706 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
| 7707 | if (err) |
| 7708 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7709 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 7710 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 7711 | request->delay = |
| 7712 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 7713 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7714 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 7715 | request->relative_rssi = nla_get_s8( |
| 7716 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 7717 | request->relative_rssi_set = true; |
| 7718 | } |
| 7719 | |
| 7720 | if (request->relative_rssi_set && |
| 7721 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 7722 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 7723 | |
| 7724 | rssi_adjust = nla_data( |
| 7725 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 7726 | request->rssi_adjust.band = rssi_adjust->band; |
| 7727 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 7728 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 7729 | err = -EINVAL; |
| 7730 | goto out_free; |
| 7731 | } |
| 7732 | } |
| 7733 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7734 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 7735 | if (err) |
| 7736 | goto out_free; |
| 7737 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7738 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7739 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7740 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7741 | |
| 7742 | out_free: |
| 7743 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7744 | return ERR_PTR(err); |
| 7745 | } |
| 7746 | |
| 7747 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 7748 | struct genl_info *info) |
| 7749 | { |
| 7750 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7751 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7752 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7753 | struct cfg80211_sched_scan_request *sched_scan_req; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7754 | bool want_multi; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7755 | int err; |
| 7756 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7757 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7758 | return -EOPNOTSUPP; |
| 7759 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7760 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 7761 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 7762 | if (err) |
| 7763 | return err; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7764 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7765 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7766 | info->attrs, |
| 7767 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7768 | |
| 7769 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7770 | if (err) |
| 7771 | goto out_err; |
| 7772 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7773 | /* leave request id zero for legacy request |
| 7774 | * or if driver does not support multi-scheduled scan |
| 7775 | */ |
| 7776 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) { |
| 7777 | while (!sched_scan_req->reqid) |
| 7778 | sched_scan_req->reqid = rdev->wiphy.cookie_counter++; |
| 7779 | } |
| 7780 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7781 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7782 | if (err) |
| 7783 | goto out_free; |
| 7784 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7785 | sched_scan_req->dev = dev; |
| 7786 | sched_scan_req->wiphy = &rdev->wiphy; |
| 7787 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 7788 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 7789 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 7790 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7791 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7792 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 7793 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7794 | return 0; |
| 7795 | |
| 7796 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7797 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7798 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7799 | return err; |
| 7800 | } |
| 7801 | |
| 7802 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 7803 | struct genl_info *info) |
| 7804 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7805 | struct cfg80211_sched_scan_request *req; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7806 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7807 | u64 cookie; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7808 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7809 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7810 | return -EOPNOTSUPP; |
| 7811 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7812 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 7813 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7814 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 7815 | } |
| 7816 | |
| 7817 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 7818 | struct cfg80211_sched_scan_request, |
| 7819 | list); |
| 7820 | if (!req || req->reqid || |
| 7821 | (req->owner_nlportid && |
| 7822 | req->owner_nlportid != info->snd_portid)) |
| 7823 | return -ENOENT; |
| 7824 | |
| 7825 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7826 | } |
| 7827 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7828 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 7829 | struct genl_info *info) |
| 7830 | { |
| 7831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7832 | struct net_device *dev = info->user_ptr[1]; |
| 7833 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 7834 | struct wiphy *wiphy = wdev->wiphy; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7835 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7836 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7837 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7838 | int err; |
| 7839 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 7840 | dfs_region = reg_get_dfs_region(wiphy); |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7841 | if (dfs_region == NL80211_DFS_UNSET) |
| 7842 | return -EINVAL; |
| 7843 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7844 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7845 | if (err) |
| 7846 | return err; |
| 7847 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 7848 | if (netif_carrier_ok(dev)) |
| 7849 | return -EBUSY; |
| 7850 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7851 | if (wdev->cac_started) |
| 7852 | return -EBUSY; |
| 7853 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 7854 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7855 | if (err < 0) |
| 7856 | return err; |
| 7857 | |
| 7858 | if (err == 0) |
| 7859 | return -EINVAL; |
| 7860 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 7861 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7862 | return -EINVAL; |
| 7863 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 7864 | /* CAC start is offloaded to HW and can't be started manually */ |
| 7865 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) |
| 7866 | return -EOPNOTSUPP; |
| 7867 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7868 | if (!rdev->ops->start_radar_detection) |
| 7869 | return -EOPNOTSUPP; |
| 7870 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7871 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 7872 | if (WARN_ON(!cac_time_ms)) |
| 7873 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 7874 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7875 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7876 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 7877 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7878 | wdev->cac_started = true; |
| 7879 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7880 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7881 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7882 | return err; |
| 7883 | } |
| 7884 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7885 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 7886 | { |
| 7887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7888 | struct net_device *dev = info->user_ptr[1]; |
| 7889 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7890 | struct cfg80211_csa_settings params; |
| 7891 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 7892 | * function is called under RTNL lock, so this should not be a problem. |
| 7893 | */ |
| 7894 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7895 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7896 | bool need_new_beacon = false; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7897 | bool need_handle_dfs_flag = true; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7898 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7899 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7900 | |
| 7901 | if (!rdev->ops->channel_switch || |
| 7902 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 7903 | return -EOPNOTSUPP; |
| 7904 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7905 | switch (dev->ieee80211_ptr->iftype) { |
| 7906 | case NL80211_IFTYPE_AP: |
| 7907 | case NL80211_IFTYPE_P2P_GO: |
| 7908 | need_new_beacon = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7909 | /* For all modes except AP the handle_dfs flag needs to be |
| 7910 | * supplied to tell the kernel that userspace will handle radar |
| 7911 | * events when they happen. Otherwise a switch to a channel |
| 7912 | * requiring DFS will be rejected. |
| 7913 | */ |
| 7914 | need_handle_dfs_flag = false; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7915 | |
| 7916 | /* useless if AP is not running */ |
| 7917 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7918 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7919 | break; |
| 7920 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7921 | if (!wdev->ssid_len) |
| 7922 | return -ENOTCONN; |
| 7923 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 7924 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7925 | if (!wdev->mesh_id_len) |
| 7926 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7927 | break; |
| 7928 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7929 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7930 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7931 | |
| 7932 | memset(¶ms, 0, sizeof(params)); |
| 7933 | |
| 7934 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7935 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 7936 | return -EINVAL; |
| 7937 | |
| 7938 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 7939 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7940 | return -EINVAL; |
| 7941 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7942 | /* Even though the attribute is u32, the specification says |
| 7943 | * u8, so let's make sure we don't overflow. |
| 7944 | */ |
| 7945 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 7946 | if (cs_count > 255) |
| 7947 | return -EINVAL; |
| 7948 | |
| 7949 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7950 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7951 | if (!need_new_beacon) |
| 7952 | goto skip_beacons; |
| 7953 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7954 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 7955 | if (err) |
| 7956 | return err; |
| 7957 | |
| 7958 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 7959 | info->attrs[NL80211_ATTR_CSA_IES], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 7960 | nl80211_policy, info->extack); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7961 | if (err) |
| 7962 | return err; |
| 7963 | |
| 7964 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 7965 | if (err) |
| 7966 | return err; |
| 7967 | |
| 7968 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 7969 | return -EINVAL; |
| 7970 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7971 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7972 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7973 | return -EINVAL; |
| 7974 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7975 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 7976 | if (rdev->wiphy.max_num_csa_counters && |
| 7977 | (params.n_counter_offsets_beacon > |
| 7978 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7979 | return -EINVAL; |
| 7980 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7981 | params.counter_offsets_beacon = |
| 7982 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7983 | |
| 7984 | /* sanity checks - counters should fit and be the same */ |
| 7985 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 7986 | u16 offset = params.counter_offsets_beacon[i]; |
| 7987 | |
| 7988 | if (offset >= params.beacon_csa.tail_len) |
| 7989 | return -EINVAL; |
| 7990 | |
| 7991 | if (params.beacon_csa.tail[offset] != params.count) |
| 7992 | return -EINVAL; |
| 7993 | } |
| 7994 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7995 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7996 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7997 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7998 | return -EINVAL; |
| 7999 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8000 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 8001 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 8002 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8003 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8004 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8005 | |
| 8006 | params.counter_offsets_presp = |
| 8007 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 8008 | |
| 8009 | /* sanity checks - counters should fit and be the same */ |
| 8010 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 8011 | u16 offset = params.counter_offsets_presp[i]; |
| 8012 | |
| 8013 | if (offset >= params.beacon_csa.probe_resp_len) |
| 8014 | return -EINVAL; |
| 8015 | |
| 8016 | if (params.beacon_csa.probe_resp[offset] != |
| 8017 | params.count) |
| 8018 | return -EINVAL; |
| 8019 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8020 | } |
| 8021 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8022 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8023 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 8024 | if (err) |
| 8025 | return err; |
| 8026 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 8027 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 8028 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8029 | return -EINVAL; |
| 8030 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 8031 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 8032 | ¶ms.chandef, |
| 8033 | wdev->iftype); |
| 8034 | if (err < 0) |
| 8035 | return err; |
| 8036 | |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8037 | if (err > 0) { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 8038 | params.radar_required = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8039 | if (need_handle_dfs_flag && |
| 8040 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
| 8041 | return -EINVAL; |
| 8042 | } |
| 8043 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8044 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8045 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 8046 | params.block_tx = true; |
| 8047 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 8048 | wdev_lock(wdev); |
| 8049 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 8050 | wdev_unlock(wdev); |
| 8051 | |
| 8052 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8053 | } |
| 8054 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8055 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 8056 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8057 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8058 | struct wireless_dev *wdev, |
| 8059 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8060 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8061 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8062 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8063 | void *hdr; |
| 8064 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8065 | |
| 8066 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8067 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8068 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8069 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 8070 | if (!hdr) |
| 8071 | return -1; |
| 8072 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 8073 | genl_dump_check_consistent(cb, hdr); |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8074 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8075 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 8076 | goto nla_put_failure; |
| 8077 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8078 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 8079 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8080 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 8081 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8082 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8083 | |
| 8084 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 8085 | if (!bss) |
| 8086 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8087 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8088 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8089 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8090 | |
| 8091 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8092 | /* indicate whether we have probe response data or not */ |
| 8093 | if (rcu_access_pointer(res->proberesp_ies) && |
| 8094 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 8095 | goto fail_unlock_rcu; |
| 8096 | |
| 8097 | /* this pointer prefers to be pointed to probe response data |
| 8098 | * but is always valid |
| 8099 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8100 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8101 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8102 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 8103 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8104 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8105 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 8106 | ies->len, ies->data)) |
| 8107 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8108 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8109 | |
| 8110 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8111 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8112 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8113 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 8114 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8115 | goto fail_unlock_rcu; |
| 8116 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 8117 | ies->len, ies->data)) |
| 8118 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8119 | } |
| 8120 | rcu_read_unlock(); |
| 8121 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8122 | if (res->beacon_interval && |
| 8123 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 8124 | goto nla_put_failure; |
| 8125 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 8126 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 8127 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8128 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 8129 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 8130 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8131 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 8132 | if (intbss->parent_tsf && |
| 8133 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 8134 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 8135 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 8136 | intbss->parent_bssid))) |
| 8137 | goto nla_put_failure; |
| 8138 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 8139 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8140 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 8141 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 8142 | goto nla_put_failure; |
| 8143 | |
Sunil Dutt | 983dafa | 2017-12-13 19:51:36 +0200 | [diff] [blame] | 8144 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
| 8145 | intbss->pub.chain_signal, |
| 8146 | NL80211_BSS_CHAIN_SIGNAL)) |
| 8147 | goto nla_put_failure; |
| 8148 | |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 8149 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8150 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8151 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 8152 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8153 | break; |
| 8154 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8155 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 8156 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8157 | break; |
| 8158 | default: |
| 8159 | break; |
| 8160 | } |
| 8161 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8162 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8163 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8164 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8165 | if (intbss == wdev->current_bss && |
| 8166 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 8167 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 8168 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8169 | break; |
| 8170 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8171 | if (intbss == wdev->current_bss && |
| 8172 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 8173 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 8174 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8175 | break; |
| 8176 | default: |
| 8177 | break; |
| 8178 | } |
| 8179 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8180 | nla_nest_end(msg, bss); |
| 8181 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 8182 | genlmsg_end(msg, hdr); |
| 8183 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8184 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8185 | fail_unlock_rcu: |
| 8186 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8187 | nla_put_failure: |
| 8188 | genlmsg_cancel(msg, hdr); |
| 8189 | return -EMSGSIZE; |
| 8190 | } |
| 8191 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8192 | 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] | 8193 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8194 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8195 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8196 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8197 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8198 | int err; |
| 8199 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8200 | rtnl_lock(); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8201 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8202 | if (err) { |
| 8203 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8204 | return err; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8205 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8206 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8207 | wdev_lock(wdev); |
| 8208 | spin_lock_bh(&rdev->bss_lock); |
Denis Kenzior | d1e23c9 | 2018-05-21 10:31:13 -0500 | [diff] [blame] | 8209 | |
| 8210 | /* |
| 8211 | * dump_scan will be called multiple times to break up the scan results |
| 8212 | * into multiple messages. It is unlikely that any more bss-es will be |
| 8213 | * expired after the first call, so only call only call this on the |
| 8214 | * first dump_scan invocation. |
| 8215 | */ |
| 8216 | if (start == 0) |
| 8217 | cfg80211_bss_expire(rdev); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8218 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8219 | cb->seq = rdev->bss_generation; |
| 8220 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8221 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8222 | if (++idx <= start) |
| 8223 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8224 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8225 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8226 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8227 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8228 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8229 | } |
| 8230 | } |
| 8231 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8232 | spin_unlock_bh(&rdev->bss_lock); |
| 8233 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8234 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8235 | cb->args[2] = idx; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8236 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8237 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8238 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8239 | } |
| 8240 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8241 | 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] | 8242 | int flags, struct net_device *dev, |
| 8243 | bool allow_radio_stats, |
| 8244 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8245 | { |
| 8246 | void *hdr; |
| 8247 | struct nlattr *infoattr; |
| 8248 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8249 | /* skip radio stats if userspace didn't request them */ |
| 8250 | if (!survey->channel && !allow_radio_stats) |
| 8251 | return 0; |
| 8252 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8253 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8254 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 8255 | if (!hdr) |
| 8256 | return -ENOMEM; |
| 8257 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8258 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 8259 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8260 | |
| 8261 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 8262 | if (!infoattr) |
| 8263 | goto nla_put_failure; |
| 8264 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8265 | if (survey->channel && |
| 8266 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8267 | survey->channel->center_freq)) |
| 8268 | goto nla_put_failure; |
| 8269 | |
| 8270 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 8271 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 8272 | goto nla_put_failure; |
| 8273 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 8274 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 8275 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8276 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8277 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 8278 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8279 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8280 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8281 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 8282 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8283 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8284 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8285 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 8286 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8287 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8288 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8289 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 8290 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8291 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8292 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8293 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 8294 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8295 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 8296 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8297 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 8298 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 8299 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8300 | |
| 8301 | nla_nest_end(msg, infoattr); |
| 8302 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 8303 | genlmsg_end(msg, hdr); |
| 8304 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8305 | |
| 8306 | nla_put_failure: |
| 8307 | genlmsg_cancel(msg, hdr); |
| 8308 | return -EMSGSIZE; |
| 8309 | } |
| 8310 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8311 | 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] | 8312 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8313 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8314 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8315 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8316 | struct wireless_dev *wdev; |
| 8317 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8318 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8319 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8320 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8321 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8322 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8323 | if (res) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8324 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8325 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8326 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8327 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8328 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8329 | if (!wdev->netdev) { |
| 8330 | res = -EINVAL; |
| 8331 | goto out_err; |
| 8332 | } |
| 8333 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8334 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8335 | res = -EOPNOTSUPP; |
| 8336 | goto out_err; |
| 8337 | } |
| 8338 | |
| 8339 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8340 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8341 | if (res == -ENOENT) |
| 8342 | break; |
| 8343 | if (res) |
| 8344 | goto out_err; |
| 8345 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8346 | /* don't send disabled channels, but do send non-channel data */ |
| 8347 | if (survey.channel && |
| 8348 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 8349 | survey_idx++; |
| 8350 | continue; |
| 8351 | } |
| 8352 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8353 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8354 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8355 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8356 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8357 | goto out; |
| 8358 | survey_idx++; |
| 8359 | } |
| 8360 | |
| 8361 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8362 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8363 | res = skb->len; |
| 8364 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8365 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8366 | return res; |
| 8367 | } |
| 8368 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8369 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 8370 | { |
| 8371 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 8372 | NL80211_WPA_VERSION_2)); |
| 8373 | } |
| 8374 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8375 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 8376 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8377 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8378 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8379 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8380 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 8381 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8382 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8383 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8384 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8385 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8386 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8387 | return -EINVAL; |
| 8388 | |
| 8389 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8390 | return -EINVAL; |
| 8391 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 8392 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 8393 | return -EINVAL; |
| 8394 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8395 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 8396 | return -EINVAL; |
| 8397 | |
| 8398 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8399 | return -EINVAL; |
| 8400 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8401 | err = nl80211_parse_key(info, &key); |
| 8402 | if (err) |
| 8403 | return err; |
| 8404 | |
| 8405 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 8406 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 8407 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8408 | if (!key.p.key || !key.p.key_len) |
| 8409 | return -EINVAL; |
| 8410 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 8411 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 8412 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 8413 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 8414 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 8415 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8416 | return -EINVAL; |
| 8417 | } else { |
| 8418 | key.p.key_len = 0; |
| 8419 | key.p.key = NULL; |
| 8420 | } |
| 8421 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8422 | if (key.idx >= 0) { |
| 8423 | int i; |
| 8424 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8425 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8426 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 8427 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 8428 | ok = true; |
| 8429 | break; |
| 8430 | } |
| 8431 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8432 | if (!ok) |
| 8433 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8434 | } |
| 8435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8436 | if (!rdev->ops->auth) |
| 8437 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8438 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8439 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8440 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8441 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8442 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8443 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8444 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8445 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8446 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8447 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8448 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8449 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8450 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8451 | |
| 8452 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8453 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8454 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8455 | } |
| 8456 | |
| 8457 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8458 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8459 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8460 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8461 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 8462 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 8463 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 8464 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8465 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8466 | return -EINVAL; |
| 8467 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8468 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8469 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 8470 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 8471 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 8472 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8473 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8474 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 8475 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8476 | /* need to include at least Auth Transaction and Status Code */ |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8477 | if (auth_data_len < 4) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8478 | return -EINVAL; |
| 8479 | } |
| 8480 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8481 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8482 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 8483 | /* |
| 8484 | * Since we no longer track auth state, ignore |
| 8485 | * requests to only change local state. |
| 8486 | */ |
| 8487 | if (local_state_change) |
| 8488 | return 0; |
| 8489 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8490 | wdev_lock(dev->ieee80211_ptr); |
| 8491 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 8492 | ssid, ssid_len, ie, ie_len, |
| 8493 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8494 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8495 | wdev_unlock(dev->ieee80211_ptr); |
| 8496 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8497 | } |
| 8498 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 8499 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, |
| 8500 | struct genl_info *info) |
| 8501 | { |
| 8502 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8503 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); |
| 8504 | return -EINVAL; |
| 8505 | } |
| 8506 | |
| 8507 | if (!rdev->ops->tx_control_port || |
| 8508 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8509 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 8510 | return -EOPNOTSUPP; |
| 8511 | |
| 8512 | return 0; |
| 8513 | } |
| 8514 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8515 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 8516 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8517 | struct cfg80211_crypto_settings *settings, |
| 8518 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8519 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 8520 | memset(settings, 0, sizeof(*settings)); |
| 8521 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8522 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 8523 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8524 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 8525 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8526 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8527 | proto = nla_get_u16( |
| 8528 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 8529 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 8530 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 8531 | proto != ETH_P_PAE) |
| 8532 | return -EINVAL; |
| 8533 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 8534 | settings->control_port_no_encrypt = true; |
| 8535 | } else |
| 8536 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 8537 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 8538 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 8539 | int r = validate_pae_over_nl80211(rdev, info); |
| 8540 | |
| 8541 | if (r < 0) |
| 8542 | return r; |
| 8543 | |
| 8544 | settings->control_port_over_nl80211 = true; |
| 8545 | } |
| 8546 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8547 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 8548 | void *data; |
| 8549 | int len, i; |
| 8550 | |
| 8551 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8552 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8553 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 8554 | |
| 8555 | if (len % sizeof(u32)) |
| 8556 | return -EINVAL; |
| 8557 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8558 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8559 | return -EINVAL; |
| 8560 | |
| 8561 | memcpy(settings->ciphers_pairwise, data, len); |
| 8562 | |
| 8563 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8564 | if (!cfg80211_supported_cipher_suite( |
| 8565 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8566 | settings->ciphers_pairwise[i])) |
| 8567 | return -EINVAL; |
| 8568 | } |
| 8569 | |
| 8570 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 8571 | settings->cipher_group = |
| 8572 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8573 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 8574 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8575 | return -EINVAL; |
| 8576 | } |
| 8577 | |
| 8578 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 8579 | settings->wpa_versions = |
| 8580 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 8581 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 8582 | return -EINVAL; |
| 8583 | } |
| 8584 | |
| 8585 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 8586 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 8587 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8588 | |
| 8589 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8590 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8591 | settings->n_akm_suites = len / sizeof(u32); |
| 8592 | |
| 8593 | if (len % sizeof(u32)) |
| 8594 | return -EINVAL; |
| 8595 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 8596 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 8597 | return -EINVAL; |
| 8598 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8599 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8600 | } |
| 8601 | |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 8602 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 8603 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 8604 | return -EINVAL; |
| 8605 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8606 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) |
| 8607 | return -EINVAL; |
| 8608 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 8609 | } |
| 8610 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8611 | return 0; |
| 8612 | } |
| 8613 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8614 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 8615 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8617 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8618 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8619 | struct cfg80211_assoc_request req = {}; |
| 8620 | const u8 *bssid, *ssid; |
| 8621 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8622 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 8623 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 8624 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 8625 | return -EPERM; |
| 8626 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8627 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8628 | return -EINVAL; |
| 8629 | |
| 8630 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8631 | !info->attrs[NL80211_ATTR_SSID] || |
| 8632 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8633 | return -EINVAL; |
| 8634 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8635 | if (!rdev->ops->assoc) |
| 8636 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8637 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8638 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8639 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8640 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8641 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8642 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8643 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8644 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8645 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8646 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8647 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8648 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8649 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8650 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8651 | |
| 8652 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8653 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8654 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8655 | } |
| 8656 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8657 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8658 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8659 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8660 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8661 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8662 | else if (mfp != NL80211_MFP_NO) |
| 8663 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8664 | } |
| 8665 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8666 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8667 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8668 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8669 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8670 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8671 | |
| 8672 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8673 | memcpy(&req.ht_capa_mask, |
| 8674 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8675 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8676 | |
| 8677 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8678 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8679 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8680 | memcpy(&req.ht_capa, |
| 8681 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8682 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8683 | } |
| 8684 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8685 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8686 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8687 | |
| 8688 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8689 | memcpy(&req.vht_capa_mask, |
| 8690 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8691 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8692 | |
| 8693 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8694 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8695 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8696 | memcpy(&req.vht_capa, |
| 8697 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8698 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8699 | } |
| 8700 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8701 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8702 | if (!((rdev->wiphy.features & |
| 8703 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8704 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8705 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8706 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8707 | return -EINVAL; |
| 8708 | req.flags |= ASSOC_REQ_USE_RRM; |
| 8709 | } |
| 8710 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 8711 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 8712 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8713 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8714 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 8715 | return -EINVAL; |
| 8716 | req.fils_nonces = |
| 8717 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 8718 | } |
| 8719 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8720 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8721 | if (!err) { |
| 8722 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8723 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8724 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 8725 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8726 | |
| 8727 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8728 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 8729 | info->snd_portid; |
| 8730 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 8731 | bssid, ETH_ALEN); |
| 8732 | } |
| 8733 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8734 | wdev_unlock(dev->ieee80211_ptr); |
| 8735 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8736 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8737 | return err; |
| 8738 | } |
| 8739 | |
| 8740 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 8741 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8743 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8744 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8745 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8746 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8747 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8748 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 8749 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 8750 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 8751 | return -EPERM; |
| 8752 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8753 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8754 | return -EINVAL; |
| 8755 | |
| 8756 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8757 | return -EINVAL; |
| 8758 | |
| 8759 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8760 | return -EINVAL; |
| 8761 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8762 | if (!rdev->ops->deauth) |
| 8763 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8764 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8765 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8766 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8767 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8768 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8769 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8770 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8771 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8772 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8773 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8774 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8775 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8776 | |
| 8777 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8778 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8779 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8780 | } |
| 8781 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8782 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8783 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8784 | wdev_lock(dev->ieee80211_ptr); |
| 8785 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8786 | local_state_change); |
| 8787 | wdev_unlock(dev->ieee80211_ptr); |
| 8788 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8789 | } |
| 8790 | |
| 8791 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 8792 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8793 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8794 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8795 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8796 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8797 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8798 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8799 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 8800 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 8801 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 8802 | return -EPERM; |
| 8803 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8804 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8805 | return -EINVAL; |
| 8806 | |
| 8807 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8808 | return -EINVAL; |
| 8809 | |
| 8810 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8811 | return -EINVAL; |
| 8812 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8813 | if (!rdev->ops->disassoc) |
| 8814 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8815 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8816 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8817 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8818 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8819 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8820 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8821 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8822 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8823 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8824 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8825 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8826 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8827 | |
| 8828 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8829 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8830 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8831 | } |
| 8832 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8833 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8834 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8835 | wdev_lock(dev->ieee80211_ptr); |
| 8836 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8837 | local_state_change); |
| 8838 | wdev_unlock(dev->ieee80211_ptr); |
| 8839 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8840 | } |
| 8841 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8842 | static bool |
| 8843 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8844 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8845 | int rateval) |
| 8846 | { |
| 8847 | struct wiphy *wiphy = &rdev->wiphy; |
| 8848 | bool found = false; |
| 8849 | int band, i; |
| 8850 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8851 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8852 | struct ieee80211_supported_band *sband; |
| 8853 | |
| 8854 | sband = wiphy->bands[band]; |
| 8855 | if (!sband) |
| 8856 | continue; |
| 8857 | |
| 8858 | for (i = 0; i < sband->n_bitrates; i++) { |
| 8859 | if (sband->bitrates[i].bitrate == rateval) { |
| 8860 | mcast_rate[band] = i + 1; |
| 8861 | found = true; |
| 8862 | break; |
| 8863 | } |
| 8864 | } |
| 8865 | } |
| 8866 | |
| 8867 | return found; |
| 8868 | } |
| 8869 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8870 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8871 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8873 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8874 | struct cfg80211_ibss_params ibss; |
| 8875 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8876 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8877 | int err; |
| 8878 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8879 | memset(&ibss, 0, sizeof(ibss)); |
| 8880 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8881 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8882 | return -EINVAL; |
| 8883 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8884 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8885 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8886 | return -EINVAL; |
| 8887 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8888 | ibss.beacon_interval = 100; |
| 8889 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8890 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8891 | ibss.beacon_interval = |
| 8892 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8893 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 8894 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 8895 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8896 | if (err) |
| 8897 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8898 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8899 | if (!rdev->ops->join_ibss) |
| 8900 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8901 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8902 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8903 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8904 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8905 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8906 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8907 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8908 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8909 | |
| 8910 | if (!is_valid_ether_addr(ibss.bssid)) |
| 8911 | return -EINVAL; |
| 8912 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8913 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8914 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8915 | |
| 8916 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8917 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8918 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8919 | } |
| 8920 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8921 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 8922 | if (err) |
| 8923 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8924 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 8925 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 8926 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8927 | return -EINVAL; |
| 8928 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8929 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 8930 | case NL80211_CHAN_WIDTH_5: |
| 8931 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8932 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 8933 | break; |
| 8934 | case NL80211_CHAN_WIDTH_20: |
| 8935 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 8936 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8937 | return -EINVAL; |
| 8938 | break; |
| 8939 | case NL80211_CHAN_WIDTH_80: |
| 8940 | case NL80211_CHAN_WIDTH_80P80: |
| 8941 | case NL80211_CHAN_WIDTH_160: |
| 8942 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8943 | return -EINVAL; |
| 8944 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8945 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 8946 | return -EINVAL; |
| 8947 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8948 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8949 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8950 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8951 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8952 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8953 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8954 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8955 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8956 | u8 *rates = |
| 8957 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8958 | int n_rates = |
| 8959 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8960 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8961 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8962 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8963 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8964 | &ibss.basic_rates); |
| 8965 | if (err) |
| 8966 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8967 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8968 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 8969 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8970 | memcpy(&ibss.ht_capa_mask, |
| 8971 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8972 | sizeof(ibss.ht_capa_mask)); |
| 8973 | |
| 8974 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 8975 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8976 | return -EINVAL; |
| 8977 | memcpy(&ibss.ht_capa, |
| 8978 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8979 | sizeof(ibss.ht_capa)); |
| 8980 | } |
| 8981 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8982 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8983 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 8984 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8985 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8986 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8987 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8988 | bool no_ht = false; |
| 8989 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 8990 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8991 | if (IS_ERR(connkeys)) |
| 8992 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8993 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 8994 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 8995 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 8996 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8997 | return -EINVAL; |
| 8998 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8999 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9000 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 9001 | ibss.control_port = |
| 9002 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 9003 | |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 9004 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 9005 | int r = validate_pae_over_nl80211(rdev, info); |
| 9006 | |
| 9007 | if (r < 0) |
| 9008 | return r; |
| 9009 | |
| 9010 | ibss.control_port_over_nl80211 = true; |
| 9011 | } |
| 9012 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 9013 | ibss.userspace_handles_dfs = |
| 9014 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 9015 | |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 9016 | wdev_lock(dev->ieee80211_ptr); |
| 9017 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9018 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9019 | kzfree(connkeys); |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 9020 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 9021 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 9022 | wdev_unlock(dev->ieee80211_ptr); |
| 9023 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9024 | return err; |
| 9025 | } |
| 9026 | |
| 9027 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 9028 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9030 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9031 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9032 | if (!rdev->ops->leave_ibss) |
| 9033 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9034 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9035 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 9036 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9037 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9038 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9039 | } |
| 9040 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9041 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 9042 | { |
| 9043 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9044 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9045 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9046 | u32 nla_rate; |
| 9047 | int err; |
| 9048 | |
| 9049 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 9050 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 9051 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9052 | return -EOPNOTSUPP; |
| 9053 | |
| 9054 | if (!rdev->ops->set_mcast_rate) |
| 9055 | return -EOPNOTSUPP; |
| 9056 | |
| 9057 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 9058 | |
| 9059 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 9060 | return -EINVAL; |
| 9061 | |
| 9062 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 9063 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 9064 | return -EINVAL; |
| 9065 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 9066 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9067 | |
| 9068 | return err; |
| 9069 | } |
| 9070 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9071 | static struct sk_buff * |
| 9072 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9073 | struct wireless_dev *wdev, int approxlen, |
| 9074 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9075 | enum nl80211_attrs attr, |
| 9076 | const struct nl80211_vendor_cmd_info *info, |
| 9077 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9078 | { |
| 9079 | struct sk_buff *skb; |
| 9080 | void *hdr; |
| 9081 | struct nlattr *data; |
| 9082 | |
| 9083 | skb = nlmsg_new(approxlen + 100, gfp); |
| 9084 | if (!skb) |
| 9085 | return NULL; |
| 9086 | |
| 9087 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 9088 | if (!hdr) { |
| 9089 | kfree_skb(skb); |
| 9090 | return NULL; |
| 9091 | } |
| 9092 | |
| 9093 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 9094 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9095 | |
| 9096 | if (info) { |
| 9097 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 9098 | info->vendor_id)) |
| 9099 | goto nla_put_failure; |
| 9100 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 9101 | info->subcmd)) |
| 9102 | goto nla_put_failure; |
| 9103 | } |
| 9104 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9105 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9106 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 9107 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9108 | goto nla_put_failure; |
| 9109 | if (wdev->netdev && |
| 9110 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 9111 | wdev->netdev->ifindex)) |
| 9112 | goto nla_put_failure; |
| 9113 | } |
| 9114 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9115 | data = nla_nest_start(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9116 | if (!data) |
| 9117 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9118 | |
| 9119 | ((void **)skb->cb)[0] = rdev; |
| 9120 | ((void **)skb->cb)[1] = hdr; |
| 9121 | ((void **)skb->cb)[2] = data; |
| 9122 | |
| 9123 | return skb; |
| 9124 | |
| 9125 | nla_put_failure: |
| 9126 | kfree_skb(skb); |
| 9127 | return NULL; |
| 9128 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9129 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9130 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9131 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9132 | enum nl80211_commands cmd, |
| 9133 | enum nl80211_attrs attr, |
| 9134 | int vendor_event_idx, |
| 9135 | int approxlen, gfp_t gfp) |
| 9136 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9137 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9138 | const struct nl80211_vendor_cmd_info *info; |
| 9139 | |
| 9140 | switch (cmd) { |
| 9141 | case NL80211_CMD_TESTMODE: |
| 9142 | if (WARN_ON(vendor_event_idx != -1)) |
| 9143 | return NULL; |
| 9144 | info = NULL; |
| 9145 | break; |
| 9146 | case NL80211_CMD_VENDOR: |
| 9147 | if (WARN_ON(vendor_event_idx < 0 || |
| 9148 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 9149 | return NULL; |
| 9150 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 9151 | break; |
| 9152 | default: |
| 9153 | WARN_ON(1); |
| 9154 | return NULL; |
| 9155 | } |
| 9156 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9157 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9158 | cmd, attr, info, gfp); |
| 9159 | } |
| 9160 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 9161 | |
| 9162 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 9163 | { |
| 9164 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9165 | void *hdr = ((void **)skb->cb)[1]; |
| 9166 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9167 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 9168 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9169 | /* clear CB data for netlink core to own from now on */ |
| 9170 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 9171 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9172 | nla_nest_end(skb, data); |
| 9173 | genlmsg_end(skb, hdr); |
| 9174 | |
| 9175 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 9176 | mcgrp = NL80211_MCGRP_VENDOR; |
| 9177 | |
| 9178 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 9179 | mcgrp, gfp); |
| 9180 | } |
| 9181 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 9182 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9183 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9184 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 9185 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9186 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 9187 | struct wireless_dev *wdev = |
| 9188 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9189 | int err; |
| 9190 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 9191 | if (!rdev->ops->testmode_cmd) |
| 9192 | return -EOPNOTSUPP; |
| 9193 | |
| 9194 | if (IS_ERR(wdev)) { |
| 9195 | err = PTR_ERR(wdev); |
| 9196 | if (err != -EINVAL) |
| 9197 | return err; |
| 9198 | wdev = NULL; |
| 9199 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9200 | return -EINVAL; |
| 9201 | } |
| 9202 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9203 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 9204 | return -EINVAL; |
| 9205 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9206 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 9207 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9208 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 9209 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9210 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9211 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9212 | return err; |
| 9213 | } |
| 9214 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9215 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 9216 | struct netlink_callback *cb) |
| 9217 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 9218 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9219 | int err; |
| 9220 | long phy_idx; |
| 9221 | void *data = NULL; |
| 9222 | int data_len = 0; |
| 9223 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9224 | rtnl_lock(); |
| 9225 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9226 | if (cb->args[0]) { |
| 9227 | /* |
| 9228 | * 0 is a valid index, but not valid for args[0], |
| 9229 | * so we need to offset by 1. |
| 9230 | */ |
| 9231 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 9232 | |
| 9233 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 9234 | if (!rdev) { |
| 9235 | err = -ENOENT; |
| 9236 | goto out_err; |
| 9237 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9238 | } else { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9239 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
| 9240 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9241 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 9242 | attrbuf, nl80211_fam.maxattr, |
| 9243 | nl80211_policy, NULL); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9244 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9245 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 9246 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9247 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 9248 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9249 | err = PTR_ERR(rdev); |
| 9250 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 9251 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 9252 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 9253 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9254 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 9255 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9256 | } |
| 9257 | |
| 9258 | if (cb->args[1]) { |
| 9259 | data = nla_data((void *)cb->args[1]); |
| 9260 | data_len = nla_len((void *)cb->args[1]); |
| 9261 | } |
| 9262 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 9263 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9264 | err = -EOPNOTSUPP; |
| 9265 | goto out_err; |
| 9266 | } |
| 9267 | |
| 9268 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9269 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9270 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 9271 | NL80211_CMD_TESTMODE); |
| 9272 | struct nlattr *tmdata; |
| 9273 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9274 | if (!hdr) |
| 9275 | break; |
| 9276 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9277 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9278 | genlmsg_cancel(skb, hdr); |
| 9279 | break; |
| 9280 | } |
| 9281 | |
| 9282 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 9283 | if (!tmdata) { |
| 9284 | genlmsg_cancel(skb, hdr); |
| 9285 | break; |
| 9286 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9287 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9288 | nla_nest_end(skb, tmdata); |
| 9289 | |
| 9290 | if (err == -ENOBUFS || err == -ENOENT) { |
| 9291 | genlmsg_cancel(skb, hdr); |
| 9292 | break; |
| 9293 | } else if (err) { |
| 9294 | genlmsg_cancel(skb, hdr); |
| 9295 | goto out_err; |
| 9296 | } |
| 9297 | |
| 9298 | genlmsg_end(skb, hdr); |
| 9299 | } |
| 9300 | |
| 9301 | err = skb->len; |
| 9302 | /* see above */ |
| 9303 | cb->args[0] = phy_idx + 1; |
| 9304 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9305 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9306 | return err; |
| 9307 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9308 | #endif |
| 9309 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9310 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 9311 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9312 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9313 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9314 | struct cfg80211_connect_params connect; |
| 9315 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9316 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9317 | int err; |
| 9318 | |
| 9319 | memset(&connect, 0, sizeof(connect)); |
| 9320 | |
| 9321 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9322 | return -EINVAL; |
| 9323 | |
| 9324 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 9325 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 9326 | return -EINVAL; |
| 9327 | |
| 9328 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 9329 | connect.auth_type = |
| 9330 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9331 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 9332 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9333 | return -EINVAL; |
| 9334 | } else |
| 9335 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 9336 | |
| 9337 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 9338 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 9339 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 9340 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9341 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 9342 | return -EINVAL; |
| 9343 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 9344 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9345 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 9346 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9347 | if (err) |
| 9348 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9349 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9350 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9351 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9352 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9353 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 9354 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9355 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 9356 | connect.bg_scan_period = -1; |
| 9357 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 9358 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 9359 | connect.bg_scan_period = |
| 9360 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 9361 | } |
| 9362 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9363 | if (info->attrs[NL80211_ATTR_MAC]) |
| 9364 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 9365 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 9366 | connect.bssid_hint = |
| 9367 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9368 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9369 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9370 | |
| 9371 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9372 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9373 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9374 | } |
| 9375 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 9376 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 9377 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 9378 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
| 9379 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9380 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) |
| 9381 | return -EOPNOTSUPP; |
| 9382 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 9383 | if (connect.mfp != NL80211_MFP_REQUIRED && |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 9384 | connect.mfp != NL80211_MFP_NO && |
| 9385 | connect.mfp != NL80211_MFP_OPTIONAL) |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 9386 | return -EINVAL; |
| 9387 | } else { |
| 9388 | connect.mfp = NL80211_MFP_NO; |
| 9389 | } |
| 9390 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 9391 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 9392 | connect.prev_bssid = |
| 9393 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 9394 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9395 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9396 | connect.channel = nl80211_get_valid_chan( |
| 9397 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 9398 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9399 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 9400 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9401 | connect.channel_hint = nl80211_get_valid_chan( |
| 9402 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 9403 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 9404 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9405 | } |
| 9406 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9407 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 9408 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9409 | if (IS_ERR(connkeys)) |
| 9410 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9411 | } |
| 9412 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9413 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 9414 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 9415 | |
| 9416 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9417 | memcpy(&connect.ht_capa_mask, |
| 9418 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9419 | sizeof(connect.ht_capa_mask)); |
| 9420 | |
| 9421 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 9422 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9423 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9424 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 9425 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9426 | memcpy(&connect.ht_capa, |
| 9427 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9428 | sizeof(connect.ht_capa)); |
| 9429 | } |
| 9430 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9431 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 9432 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 9433 | |
| 9434 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 9435 | memcpy(&connect.vht_capa_mask, |
| 9436 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 9437 | sizeof(connect.vht_capa_mask)); |
| 9438 | |
| 9439 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 9440 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9441 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9442 | return -EINVAL; |
| 9443 | } |
| 9444 | memcpy(&connect.vht_capa, |
| 9445 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 9446 | sizeof(connect.vht_capa)); |
| 9447 | } |
| 9448 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9449 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 9450 | if (!((rdev->wiphy.features & |
| 9451 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 9452 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 9453 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9454 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 9455 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9456 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 9457 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9458 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 9459 | } |
| 9460 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 9461 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9462 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 9463 | kzfree(connkeys); |
| 9464 | return -EOPNOTSUPP; |
| 9465 | } |
| 9466 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 9467 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 9468 | /* bss selection makes no sense if bssid is set */ |
| 9469 | if (connect.bssid) { |
| 9470 | kzfree(connkeys); |
| 9471 | return -EINVAL; |
| 9472 | } |
| 9473 | |
| 9474 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 9475 | wiphy, &connect.bss_select); |
| 9476 | if (err) { |
| 9477 | kzfree(connkeys); |
| 9478 | return err; |
| 9479 | } |
| 9480 | } |
| 9481 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9482 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 9483 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 9484 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 9485 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 9486 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 9487 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9488 | connect.fils_erp_username = |
| 9489 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9490 | connect.fils_erp_username_len = |
| 9491 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9492 | connect.fils_erp_realm = |
| 9493 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9494 | connect.fils_erp_realm_len = |
| 9495 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9496 | connect.fils_erp_next_seq_num = |
| 9497 | nla_get_u16( |
| 9498 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 9499 | connect.fils_erp_rrk = |
| 9500 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9501 | connect.fils_erp_rrk_len = |
| 9502 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9503 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 9504 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 9505 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 9506 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9507 | kzfree(connkeys); |
| 9508 | return -EINVAL; |
| 9509 | } |
| 9510 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 9511 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
| 9512 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
Srinivas Dasari | 2f0605a | 2018-04-20 11:41:14 +0530 | [diff] [blame] | 9513 | kzfree(connkeys); |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 9514 | GENL_SET_ERR_MSG(info, |
| 9515 | "external auth requires connection ownership"); |
| 9516 | return -EINVAL; |
| 9517 | } |
| 9518 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; |
| 9519 | } |
| 9520 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9521 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9522 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 9523 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 9524 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9525 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9526 | kzfree(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9527 | |
| 9528 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9529 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 9530 | if (connect.bssid) |
| 9531 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 9532 | connect.bssid, ETH_ALEN); |
| 9533 | else |
| 9534 | memset(dev->ieee80211_ptr->disconnect_bssid, |
| 9535 | 0, ETH_ALEN); |
| 9536 | } |
| 9537 | |
| 9538 | wdev_unlock(dev->ieee80211_ptr); |
| 9539 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9540 | return err; |
| 9541 | } |
| 9542 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 9543 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 9544 | struct genl_info *info) |
| 9545 | { |
| 9546 | struct cfg80211_connect_params connect = {}; |
| 9547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9548 | struct net_device *dev = info->user_ptr[1]; |
| 9549 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 9550 | bool fils_sk_offload; |
| 9551 | u32 auth_type; |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 9552 | u32 changed = 0; |
| 9553 | int ret; |
| 9554 | |
| 9555 | if (!rdev->ops->update_connect_params) |
| 9556 | return -EOPNOTSUPP; |
| 9557 | |
| 9558 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9559 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9560 | return -EINVAL; |
| 9561 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9562 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9563 | changed |= UPDATE_ASSOC_IES; |
| 9564 | } |
| 9565 | |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 9566 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, |
| 9567 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); |
| 9568 | |
| 9569 | /* |
| 9570 | * when driver supports fils-sk offload all attributes must be |
| 9571 | * provided. So the else covers "fils-sk-not-all" and |
| 9572 | * "no-fils-sk-any". |
| 9573 | */ |
| 9574 | if (fils_sk_offload && |
| 9575 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 9576 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 9577 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 9578 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9579 | connect.fils_erp_username = |
| 9580 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9581 | connect.fils_erp_username_len = |
| 9582 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9583 | connect.fils_erp_realm = |
| 9584 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9585 | connect.fils_erp_realm_len = |
| 9586 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9587 | connect.fils_erp_next_seq_num = |
| 9588 | nla_get_u16( |
| 9589 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 9590 | connect.fils_erp_rrk = |
| 9591 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9592 | connect.fils_erp_rrk_len = |
| 9593 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9594 | changed |= UPDATE_FILS_ERP_INFO; |
| 9595 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 9596 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 9597 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 9598 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9599 | return -EINVAL; |
| 9600 | } |
| 9601 | |
| 9602 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 9603 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 9604 | if (!nl80211_valid_auth_type(rdev, auth_type, |
| 9605 | NL80211_CMD_CONNECT)) |
| 9606 | return -EINVAL; |
| 9607 | |
| 9608 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && |
| 9609 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) |
| 9610 | return -EINVAL; |
| 9611 | |
| 9612 | connect.auth_type = auth_type; |
| 9613 | changed |= UPDATE_AUTH_TYPE; |
| 9614 | } |
| 9615 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 9616 | wdev_lock(dev->ieee80211_ptr); |
| 9617 | if (!wdev->current_bss) |
| 9618 | ret = -ENOLINK; |
| 9619 | else |
| 9620 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 9621 | wdev_unlock(dev->ieee80211_ptr); |
| 9622 | |
| 9623 | return ret; |
| 9624 | } |
| 9625 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9626 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 9627 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9628 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9629 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9630 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9631 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9632 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9633 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9634 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9635 | return -EPERM; |
| 9636 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9637 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9638 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 9639 | else |
| 9640 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9641 | |
| 9642 | if (reason == 0) |
| 9643 | return -EINVAL; |
| 9644 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9645 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9646 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9647 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9648 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9649 | wdev_lock(dev->ieee80211_ptr); |
| 9650 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 9651 | wdev_unlock(dev->ieee80211_ptr); |
| 9652 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9653 | } |
| 9654 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9655 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 9656 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9657 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9658 | struct net *net; |
| 9659 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9660 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9661 | if (info->attrs[NL80211_ATTR_PID]) { |
| 9662 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 9663 | |
| 9664 | net = get_net_ns_by_pid(pid); |
| 9665 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 9666 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 9667 | |
| 9668 | net = get_net_ns_by_fd(fd); |
| 9669 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9670 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9671 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9672 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9673 | if (IS_ERR(net)) |
| 9674 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9675 | |
| 9676 | err = 0; |
| 9677 | |
| 9678 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9679 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 9680 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9681 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9682 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9683 | return err; |
| 9684 | } |
| 9685 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9686 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9687 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9689 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 9690 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9691 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9692 | struct cfg80211_pmksa pmksa; |
| 9693 | |
| 9694 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 9695 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9696 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 9697 | return -EINVAL; |
| 9698 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9699 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9700 | |
| 9701 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 9702 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9703 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 9704 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 9705 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 9706 | info->attrs[NL80211_ATTR_PMK])) { |
| 9707 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9708 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9709 | pmksa.cache_id = |
| 9710 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 9711 | } else { |
| 9712 | return -EINVAL; |
| 9713 | } |
| 9714 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9715 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9716 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 9717 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9718 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9719 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9720 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9721 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9722 | |
| 9723 | switch (info->genlhdr->cmd) { |
| 9724 | case NL80211_CMD_SET_PMKSA: |
| 9725 | rdev_ops = rdev->ops->set_pmksa; |
| 9726 | break; |
| 9727 | case NL80211_CMD_DEL_PMKSA: |
| 9728 | rdev_ops = rdev->ops->del_pmksa; |
| 9729 | break; |
| 9730 | default: |
| 9731 | WARN_ON(1); |
| 9732 | break; |
| 9733 | } |
| 9734 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9735 | if (!rdev_ops) |
| 9736 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9737 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9738 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9739 | } |
| 9740 | |
| 9741 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9742 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9743 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9744 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9745 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9746 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9747 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9748 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9749 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9750 | if (!rdev->ops->flush_pmksa) |
| 9751 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9752 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9753 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9754 | } |
| 9755 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9756 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 9757 | { |
| 9758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9759 | struct net_device *dev = info->user_ptr[1]; |
| 9760 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9761 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9762 | u16 status_code; |
| 9763 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9764 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9765 | |
| 9766 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9767 | !rdev->ops->tdls_mgmt) |
| 9768 | return -EOPNOTSUPP; |
| 9769 | |
| 9770 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 9771 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 9772 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 9773 | !info->attrs[NL80211_ATTR_IE] || |
| 9774 | !info->attrs[NL80211_ATTR_MAC]) |
| 9775 | return -EINVAL; |
| 9776 | |
| 9777 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9778 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 9779 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 9780 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9781 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9782 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 9783 | peer_capability = |
| 9784 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9785 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9786 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9787 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9788 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9789 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 9790 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9791 | } |
| 9792 | |
| 9793 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 9794 | { |
| 9795 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9796 | struct net_device *dev = info->user_ptr[1]; |
| 9797 | enum nl80211_tdls_operation operation; |
| 9798 | u8 *peer; |
| 9799 | |
| 9800 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9801 | !rdev->ops->tdls_oper) |
| 9802 | return -EOPNOTSUPP; |
| 9803 | |
| 9804 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 9805 | !info->attrs[NL80211_ATTR_MAC]) |
| 9806 | return -EINVAL; |
| 9807 | |
| 9808 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 9809 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9810 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9811 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9812 | } |
| 9813 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9814 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 9815 | struct genl_info *info) |
| 9816 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9818 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9819 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9820 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9821 | struct sk_buff *msg; |
| 9822 | void *hdr; |
| 9823 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9824 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9825 | int err; |
| 9826 | |
| 9827 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 9828 | !info->attrs[NL80211_ATTR_DURATION]) |
| 9829 | return -EINVAL; |
| 9830 | |
| 9831 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 9832 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9833 | if (!rdev->ops->remain_on_channel || |
| 9834 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9835 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9836 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9837 | /* |
| 9838 | * We should be on that channel for at least a minimum amount of |
| 9839 | * time (10ms) but no longer than the driver supports. |
| 9840 | */ |
| 9841 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9842 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 9843 | return -EINVAL; |
| 9844 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9845 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9846 | if (err) |
| 9847 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9848 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9849 | wdev_lock(wdev); |
| 9850 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 9851 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 9852 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 9853 | &chandef); |
| 9854 | if (compat_chandef != &chandef) { |
| 9855 | wdev_unlock(wdev); |
| 9856 | return -EBUSY; |
| 9857 | } |
| 9858 | } |
| 9859 | wdev_unlock(wdev); |
| 9860 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9861 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9862 | if (!msg) |
| 9863 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9864 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9865 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9866 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9867 | if (!hdr) { |
| 9868 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9869 | goto free_msg; |
| 9870 | } |
| 9871 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9872 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 9873 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9874 | |
| 9875 | if (err) |
| 9876 | goto free_msg; |
| 9877 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9878 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9879 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9880 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9881 | |
| 9882 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9883 | |
| 9884 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9885 | |
| 9886 | nla_put_failure: |
| 9887 | err = -ENOBUFS; |
| 9888 | free_msg: |
| 9889 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9890 | return err; |
| 9891 | } |
| 9892 | |
| 9893 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 9894 | struct genl_info *info) |
| 9895 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9896 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9897 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9898 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9899 | |
| 9900 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9901 | return -EINVAL; |
| 9902 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9903 | if (!rdev->ops->cancel_remain_on_channel) |
| 9904 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9905 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9906 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9907 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9908 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9909 | } |
| 9910 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9911 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 9912 | struct genl_info *info) |
| 9913 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9914 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9916 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9917 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9918 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9919 | if (!rdev->ops->set_bitrate_mask) |
| 9920 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9921 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9922 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
| 9923 | if (err) |
| 9924 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 9925 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9926 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9927 | } |
| 9928 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9929 | 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] | 9930 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9932 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9933 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9934 | |
| 9935 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 9936 | return -EINVAL; |
| 9937 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9938 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 9939 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9940 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9941 | switch (wdev->iftype) { |
| 9942 | case NL80211_IFTYPE_STATION: |
| 9943 | case NL80211_IFTYPE_ADHOC: |
| 9944 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9945 | case NL80211_IFTYPE_AP: |
| 9946 | case NL80211_IFTYPE_AP_VLAN: |
| 9947 | case NL80211_IFTYPE_MESH_POINT: |
| 9948 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9949 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9950 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9951 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9952 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9953 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9954 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9955 | |
| 9956 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9957 | if (!rdev->ops->mgmt_tx) |
| 9958 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9959 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9960 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9961 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 9962 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9963 | } |
| 9964 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9965 | 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] | 9966 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9967 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9968 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9969 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9970 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 9971 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9972 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9973 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9974 | struct cfg80211_mgmt_tx_params params = { |
| 9975 | .dont_wait_for_ack = |
| 9976 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 9977 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9978 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9979 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9980 | return -EINVAL; |
| 9981 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9982 | if (!rdev->ops->mgmt_tx) |
| 9983 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9984 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9985 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9986 | case NL80211_IFTYPE_P2P_DEVICE: |
| 9987 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9988 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9989 | case NL80211_IFTYPE_STATION: |
| 9990 | case NL80211_IFTYPE_ADHOC: |
| 9991 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9992 | case NL80211_IFTYPE_AP: |
| 9993 | case NL80211_IFTYPE_AP_VLAN: |
| 9994 | case NL80211_IFTYPE_MESH_POINT: |
| 9995 | case NL80211_IFTYPE_P2P_GO: |
| 9996 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9997 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9998 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9999 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10000 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10001 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10002 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10003 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10004 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10005 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10006 | |
| 10007 | /* |
| 10008 | * We should wait on the channel for at least a minimum amount |
| 10009 | * of time (10ms) but no longer than the driver supports. |
| 10010 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10011 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 10012 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10013 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10014 | } |
| 10015 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10016 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10017 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10018 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10019 | return -EINVAL; |
| 10020 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10021 | 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] | 10022 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10023 | /* get the channel if any has been specified, otherwise pass NULL to |
| 10024 | * the driver. The latter will use the current one |
| 10025 | */ |
| 10026 | chandef.chan = NULL; |
| 10027 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 10028 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10029 | if (err) |
| 10030 | return err; |
| 10031 | } |
| 10032 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10033 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10034 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10035 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10036 | wdev_lock(wdev); |
| 10037 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 10038 | wdev_unlock(wdev); |
| 10039 | return -EBUSY; |
| 10040 | } |
| 10041 | wdev_unlock(wdev); |
| 10042 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 10043 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 10044 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 10045 | |
| 10046 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 10047 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 10048 | int i; |
| 10049 | |
| 10050 | if (len % sizeof(u16)) |
| 10051 | return -EINVAL; |
| 10052 | |
| 10053 | params.n_csa_offsets = len / sizeof(u16); |
| 10054 | params.csa_offsets = |
| 10055 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 10056 | |
| 10057 | /* check that all the offsets fit the frame */ |
| 10058 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 10059 | if (params.csa_offsets[i] >= params.len) |
| 10060 | return -EINVAL; |
| 10061 | } |
| 10062 | } |
| 10063 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10064 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10065 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10066 | if (!msg) |
| 10067 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10068 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10069 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10070 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10071 | if (!hdr) { |
| 10072 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10073 | goto free_msg; |
| 10074 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10075 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10076 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10077 | params.chan = chandef.chan; |
| 10078 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10079 | if (err) |
| 10080 | goto free_msg; |
| 10081 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10082 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10083 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10084 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10085 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10086 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10087 | genlmsg_end(msg, hdr); |
| 10088 | return genlmsg_reply(msg, info); |
| 10089 | } |
| 10090 | |
| 10091 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10092 | |
| 10093 | nla_put_failure: |
| 10094 | err = -ENOBUFS; |
| 10095 | free_msg: |
| 10096 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10097 | return err; |
| 10098 | } |
| 10099 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10100 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 10101 | { |
| 10102 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10103 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10104 | u64 cookie; |
| 10105 | |
| 10106 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 10107 | return -EINVAL; |
| 10108 | |
| 10109 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 10110 | return -EOPNOTSUPP; |
| 10111 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10112 | switch (wdev->iftype) { |
| 10113 | case NL80211_IFTYPE_STATION: |
| 10114 | case NL80211_IFTYPE_ADHOC: |
| 10115 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10116 | case NL80211_IFTYPE_AP: |
| 10117 | case NL80211_IFTYPE_AP_VLAN: |
| 10118 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10119 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10120 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10121 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10122 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10123 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10124 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10125 | |
| 10126 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 10127 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10128 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10129 | } |
| 10130 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10131 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 10132 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10133 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10134 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10135 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10136 | u8 ps_state; |
| 10137 | bool state; |
| 10138 | int err; |
| 10139 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10140 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 10141 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10142 | |
| 10143 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 10144 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10145 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 10146 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10147 | |
| 10148 | wdev = dev->ieee80211_ptr; |
| 10149 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10150 | if (!rdev->ops->set_power_mgmt) |
| 10151 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10152 | |
| 10153 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 10154 | |
| 10155 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10156 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10157 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10158 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10159 | if (!err) |
| 10160 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10161 | return err; |
| 10162 | } |
| 10163 | |
| 10164 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 10165 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10167 | enum nl80211_ps_state ps_state; |
| 10168 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10169 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10170 | struct sk_buff *msg; |
| 10171 | void *hdr; |
| 10172 | int err; |
| 10173 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10174 | wdev = dev->ieee80211_ptr; |
| 10175 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10176 | if (!rdev->ops->set_power_mgmt) |
| 10177 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10178 | |
| 10179 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10180 | if (!msg) |
| 10181 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10182 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10183 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10184 | NL80211_CMD_GET_POWER_SAVE); |
| 10185 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10186 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10187 | goto free_msg; |
| 10188 | } |
| 10189 | |
| 10190 | if (wdev->ps) |
| 10191 | ps_state = NL80211_PS_ENABLED; |
| 10192 | else |
| 10193 | ps_state = NL80211_PS_DISABLED; |
| 10194 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10195 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 10196 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10197 | |
| 10198 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10199 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10200 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10201 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10202 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10203 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10204 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10205 | return err; |
| 10206 | } |
| 10207 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 10208 | static const struct nla_policy |
| 10209 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10210 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10211 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 10212 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10213 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 10214 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 10215 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 10216 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10217 | }; |
| 10218 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10219 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 10220 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10221 | { |
| 10222 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10223 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10224 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10225 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 10226 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10227 | return -EINVAL; |
| 10228 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10229 | if (!rdev->ops->set_cqm_txe_config) |
| 10230 | return -EOPNOTSUPP; |
| 10231 | |
| 10232 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 10233 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10234 | return -EOPNOTSUPP; |
| 10235 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10236 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10237 | } |
| 10238 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10239 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 10240 | struct net_device *dev) |
| 10241 | { |
| 10242 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10243 | s32 last, low, high; |
| 10244 | u32 hyst; |
| 10245 | int i, n; |
| 10246 | int err; |
| 10247 | |
| 10248 | /* RSSI reporting disabled? */ |
| 10249 | if (!wdev->cqm_config) |
| 10250 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 10251 | |
| 10252 | /* |
| 10253 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 10254 | * event has been received yet, we should receive an event after a |
| 10255 | * connection is established and enough beacons received to calculate |
| 10256 | * the average. |
| 10257 | */ |
| 10258 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 10259 | rdev->ops->get_station) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 10260 | struct station_info sinfo = {}; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10261 | u8 *mac_addr; |
| 10262 | |
| 10263 | mac_addr = wdev->current_bss->pub.bssid; |
| 10264 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 10265 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 10266 | if (err) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10267 | return err; |
| 10268 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame^] | 10269 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10270 | wdev->cqm_config->last_rssi_event_value = |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 10271 | (s8) sinfo.rx_beacon_signal_avg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10272 | } |
| 10273 | |
| 10274 | last = wdev->cqm_config->last_rssi_event_value; |
| 10275 | hyst = wdev->cqm_config->rssi_hyst; |
| 10276 | n = wdev->cqm_config->n_rssi_thresholds; |
| 10277 | |
| 10278 | for (i = 0; i < n; i++) |
| 10279 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 10280 | break; |
| 10281 | |
| 10282 | low = i > 0 ? |
| 10283 | (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN; |
| 10284 | high = i < n ? |
| 10285 | (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX; |
| 10286 | |
| 10287 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 10288 | } |
| 10289 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10290 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10291 | const s32 *thresholds, int n_thresholds, |
| 10292 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10293 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10294 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10295 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10296 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10297 | int i, err; |
| 10298 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10299 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10300 | /* Check all values negative and sorted */ |
| 10301 | for (i = 0; i < n_thresholds; i++) { |
| 10302 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 10303 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10304 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10305 | prev = thresholds[i]; |
| 10306 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10307 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10308 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10309 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10310 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10311 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10312 | wdev_lock(wdev); |
| 10313 | cfg80211_cqm_config_free(wdev); |
| 10314 | wdev_unlock(wdev); |
| 10315 | |
| 10316 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 10317 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 10318 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 10319 | |
| 10320 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 10321 | thresholds[0], hysteresis); |
| 10322 | } |
| 10323 | |
| 10324 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 10325 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 10326 | return -EOPNOTSUPP; |
| 10327 | |
| 10328 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 10329 | n_thresholds = 0; |
| 10330 | |
| 10331 | wdev_lock(wdev); |
| 10332 | if (n_thresholds) { |
| 10333 | struct cfg80211_cqm_config *cqm_config; |
| 10334 | |
| 10335 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 10336 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 10337 | if (!cqm_config) { |
| 10338 | err = -ENOMEM; |
| 10339 | goto unlock; |
| 10340 | } |
| 10341 | |
| 10342 | cqm_config->rssi_hyst = hysteresis; |
| 10343 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 10344 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 10345 | n_thresholds * sizeof(s32)); |
| 10346 | |
| 10347 | wdev->cqm_config = cqm_config; |
| 10348 | } |
| 10349 | |
| 10350 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 10351 | |
| 10352 | unlock: |
| 10353 | wdev_unlock(wdev); |
| 10354 | |
| 10355 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10356 | } |
| 10357 | |
| 10358 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 10359 | { |
| 10360 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 10361 | struct nlattr *cqm; |
| 10362 | int err; |
| 10363 | |
| 10364 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10365 | if (!cqm) |
| 10366 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10367 | |
| 10368 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10369 | nl80211_attr_cqm_policy, info->extack); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10370 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10371 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10372 | |
| 10373 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 10374 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10375 | const s32 *thresholds = |
| 10376 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 10377 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10378 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10379 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 10380 | if (len % 4) |
| 10381 | return -EINVAL; |
| 10382 | |
| 10383 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 10384 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 10385 | } |
| 10386 | |
| 10387 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 10388 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 10389 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 10390 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 10391 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 10392 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 10393 | |
| 10394 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 10395 | } |
| 10396 | |
| 10397 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10398 | } |
| 10399 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 10400 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 10401 | { |
| 10402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10403 | struct net_device *dev = info->user_ptr[1]; |
| 10404 | struct ocb_setup setup = {}; |
| 10405 | int err; |
| 10406 | |
| 10407 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 10408 | if (err) |
| 10409 | return err; |
| 10410 | |
| 10411 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 10412 | } |
| 10413 | |
| 10414 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 10415 | { |
| 10416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10417 | struct net_device *dev = info->user_ptr[1]; |
| 10418 | |
| 10419 | return cfg80211_leave_ocb(rdev, dev); |
| 10420 | } |
| 10421 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10422 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 10423 | { |
| 10424 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10425 | struct net_device *dev = info->user_ptr[1]; |
| 10426 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10427 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10428 | int err; |
| 10429 | |
| 10430 | /* start with default */ |
| 10431 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10432 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10433 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10434 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10435 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10436 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10437 | if (err) |
| 10438 | return err; |
| 10439 | } |
| 10440 | |
| 10441 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 10442 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 10443 | return -EINVAL; |
| 10444 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10445 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 10446 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 10447 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 10448 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 10449 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 10450 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 10451 | return -EINVAL; |
| 10452 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 10453 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 10454 | setup.beacon_interval = |
| 10455 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10456 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 10457 | err = cfg80211_validate_beacon_int(rdev, |
| 10458 | NL80211_IFTYPE_MESH_POINT, |
| 10459 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10460 | if (err) |
| 10461 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 10462 | } |
| 10463 | |
| 10464 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 10465 | setup.dtim_period = |
| 10466 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 10467 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 10468 | return -EINVAL; |
| 10469 | } |
| 10470 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10471 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 10472 | /* parse additional setup parameters if given */ |
| 10473 | err = nl80211_parse_mesh_setup(info, &setup); |
| 10474 | if (err) |
| 10475 | return err; |
| 10476 | } |
| 10477 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 10478 | if (setup.user_mpm) |
| 10479 | cfg.auto_open_plinks = false; |
| 10480 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 10481 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10482 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 10483 | if (err) |
| 10484 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 10485 | } else { |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 10486 | /* __cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10487 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 10488 | } |
| 10489 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 10490 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 10491 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10492 | int n_rates = |
| 10493 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10494 | struct ieee80211_supported_band *sband; |
| 10495 | |
| 10496 | if (!setup.chandef.chan) |
| 10497 | return -EINVAL; |
| 10498 | |
| 10499 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 10500 | |
| 10501 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 10502 | &setup.basic_rates); |
| 10503 | if (err) |
| 10504 | return err; |
| 10505 | } |
| 10506 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 10507 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 10508 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); |
| 10509 | if (err) |
| 10510 | return err; |
| 10511 | |
Johannes Berg | 265698d | 2017-09-18 22:46:36 +0200 | [diff] [blame] | 10512 | if (!setup.chandef.chan) |
| 10513 | return -EINVAL; |
| 10514 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 10515 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 10516 | &setup.beacon_rate); |
| 10517 | if (err) |
| 10518 | return err; |
| 10519 | } |
| 10520 | |
Benjamin Berg | d37d49c | 2017-05-16 11:23:11 +0200 | [diff] [blame] | 10521 | setup.userspace_handles_dfs = |
| 10522 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 10523 | |
Denis Kenzior | 1224f58 | 2018-03-26 12:52:49 -0500 | [diff] [blame] | 10524 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 10525 | int r = validate_pae_over_nl80211(rdev, info); |
| 10526 | |
| 10527 | if (r < 0) |
| 10528 | return r; |
| 10529 | |
| 10530 | setup.control_port_over_nl80211 = true; |
| 10531 | } |
| 10532 | |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 10533 | wdev_lock(dev->ieee80211_ptr); |
| 10534 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
| 10535 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 10536 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10537 | wdev_unlock(dev->ieee80211_ptr); |
| 10538 | |
| 10539 | return err; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10540 | } |
| 10541 | |
| 10542 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 10543 | { |
| 10544 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10545 | struct net_device *dev = info->user_ptr[1]; |
| 10546 | |
| 10547 | return cfg80211_leave_mesh(rdev, dev); |
| 10548 | } |
| 10549 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10550 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10551 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 10552 | struct cfg80211_registered_device *rdev) |
| 10553 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10554 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10555 | struct nlattr *nl_pats, *nl_pat; |
| 10556 | int i, pat_len; |
| 10557 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10558 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10559 | return 0; |
| 10560 | |
| 10561 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 10562 | if (!nl_pats) |
| 10563 | return -ENOBUFS; |
| 10564 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10565 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10566 | nl_pat = nla_nest_start(msg, i + 1); |
| 10567 | if (!nl_pat) |
| 10568 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10569 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10570 | 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] | 10571 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10572 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10573 | wowlan->patterns[i].pattern) || |
| 10574 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10575 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10576 | return -ENOBUFS; |
| 10577 | nla_nest_end(msg, nl_pat); |
| 10578 | } |
| 10579 | nla_nest_end(msg, nl_pats); |
| 10580 | |
| 10581 | return 0; |
| 10582 | } |
| 10583 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10584 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 10585 | struct cfg80211_wowlan_tcp *tcp) |
| 10586 | { |
| 10587 | struct nlattr *nl_tcp; |
| 10588 | |
| 10589 | if (!tcp) |
| 10590 | return 0; |
| 10591 | |
| 10592 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 10593 | if (!nl_tcp) |
| 10594 | return -ENOBUFS; |
| 10595 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 10596 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 10597 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10598 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 10599 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 10600 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 10601 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 10602 | tcp->payload_len, tcp->payload) || |
| 10603 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 10604 | tcp->data_interval) || |
| 10605 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 10606 | tcp->wake_len, tcp->wake_data) || |
| 10607 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 10608 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 10609 | return -ENOBUFS; |
| 10610 | |
| 10611 | if (tcp->payload_seq.len && |
| 10612 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 10613 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 10614 | return -ENOBUFS; |
| 10615 | |
| 10616 | if (tcp->payload_tok.len && |
| 10617 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 10618 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 10619 | &tcp->payload_tok)) |
| 10620 | return -ENOBUFS; |
| 10621 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 10622 | nla_nest_end(msg, nl_tcp); |
| 10623 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10624 | return 0; |
| 10625 | } |
| 10626 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10627 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 10628 | struct cfg80211_sched_scan_request *req) |
| 10629 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10630 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10631 | int i; |
| 10632 | |
| 10633 | if (!req) |
| 10634 | return 0; |
| 10635 | |
| 10636 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 10637 | if (!nd) |
| 10638 | return -ENOBUFS; |
| 10639 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10640 | if (req->n_scan_plans == 1 && |
| 10641 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 10642 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10643 | return -ENOBUFS; |
| 10644 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 10645 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 10646 | return -ENOBUFS; |
| 10647 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 10648 | if (req->relative_rssi_set) { |
| 10649 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 10650 | |
| 10651 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 10652 | req->relative_rssi)) |
| 10653 | return -ENOBUFS; |
| 10654 | |
| 10655 | rssi_adjust.band = req->rssi_adjust.band; |
| 10656 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 10657 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 10658 | sizeof(rssi_adjust), &rssi_adjust)) |
| 10659 | return -ENOBUFS; |
| 10660 | } |
| 10661 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10662 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10663 | if (!freqs) |
| 10664 | return -ENOBUFS; |
| 10665 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10666 | for (i = 0; i < req->n_channels; i++) { |
| 10667 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10668 | return -ENOBUFS; |
| 10669 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10670 | |
| 10671 | nla_nest_end(msg, freqs); |
| 10672 | |
| 10673 | if (req->n_match_sets) { |
| 10674 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10675 | if (!matches) |
| 10676 | return -ENOBUFS; |
| 10677 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10678 | for (i = 0; i < req->n_match_sets; i++) { |
| 10679 | match = nla_nest_start(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10680 | if (!match) |
| 10681 | return -ENOBUFS; |
| 10682 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10683 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 10684 | req->match_sets[i].ssid.ssid_len, |
| 10685 | req->match_sets[i].ssid.ssid)) |
| 10686 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10687 | nla_nest_end(msg, match); |
| 10688 | } |
| 10689 | nla_nest_end(msg, matches); |
| 10690 | } |
| 10691 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10692 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 10693 | if (!scan_plans) |
| 10694 | return -ENOBUFS; |
| 10695 | |
| 10696 | for (i = 0; i < req->n_scan_plans; i++) { |
| 10697 | scan_plan = nla_nest_start(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10698 | if (!scan_plan) |
| 10699 | return -ENOBUFS; |
| 10700 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10701 | if (!scan_plan || |
| 10702 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 10703 | req->scan_plans[i].interval) || |
| 10704 | (req->scan_plans[i].iterations && |
| 10705 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 10706 | req->scan_plans[i].iterations))) |
| 10707 | return -ENOBUFS; |
| 10708 | nla_nest_end(msg, scan_plan); |
| 10709 | } |
| 10710 | nla_nest_end(msg, scan_plans); |
| 10711 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10712 | nla_nest_end(msg, nd); |
| 10713 | |
| 10714 | return 0; |
| 10715 | } |
| 10716 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10717 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10718 | { |
| 10719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10720 | struct sk_buff *msg; |
| 10721 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10722 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10723 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10724 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10725 | return -EOPNOTSUPP; |
| 10726 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10727 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10728 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10729 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 10730 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 10731 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 10732 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10733 | } |
| 10734 | |
| 10735 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10736 | if (!msg) |
| 10737 | return -ENOMEM; |
| 10738 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10739 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10740 | NL80211_CMD_GET_WOWLAN); |
| 10741 | if (!hdr) |
| 10742 | goto nla_put_failure; |
| 10743 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10744 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10745 | struct nlattr *nl_wowlan; |
| 10746 | |
| 10747 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10748 | if (!nl_wowlan) |
| 10749 | goto nla_put_failure; |
| 10750 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10751 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10752 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10753 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10754 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10755 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10756 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10757 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10758 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10759 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10760 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10761 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10762 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10763 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10764 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 10765 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10766 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10767 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 10768 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10769 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10770 | if (nl80211_send_wowlan_tcp(msg, |
| 10771 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10772 | goto nla_put_failure; |
| 10773 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10774 | if (nl80211_send_wowlan_nd( |
| 10775 | msg, |
| 10776 | rdev->wiphy.wowlan_config->nd_config)) |
| 10777 | goto nla_put_failure; |
| 10778 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10779 | nla_nest_end(msg, nl_wowlan); |
| 10780 | } |
| 10781 | |
| 10782 | genlmsg_end(msg, hdr); |
| 10783 | return genlmsg_reply(msg, info); |
| 10784 | |
| 10785 | nla_put_failure: |
| 10786 | nlmsg_free(msg); |
| 10787 | return -ENOBUFS; |
| 10788 | } |
| 10789 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10790 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 10791 | struct nlattr *attr, |
| 10792 | struct cfg80211_wowlan *trig) |
| 10793 | { |
| 10794 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 10795 | struct cfg80211_wowlan_tcp *cfg; |
| 10796 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 10797 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 10798 | u32 size; |
| 10799 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 10800 | int err, port; |
| 10801 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10802 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10803 | return -EINVAL; |
| 10804 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10805 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10806 | nl80211_wowlan_tcp_policy, NULL); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10807 | if (err) |
| 10808 | return err; |
| 10809 | |
| 10810 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 10811 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 10812 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 10813 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 10814 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 10815 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 10816 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 10817 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 10818 | return -EINVAL; |
| 10819 | |
| 10820 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10821 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10822 | return -EINVAL; |
| 10823 | |
| 10824 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10825 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 10826 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10827 | return -EINVAL; |
| 10828 | |
| 10829 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10830 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10831 | return -EINVAL; |
| 10832 | |
| 10833 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 10834 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 10835 | return -EINVAL; |
| 10836 | |
| 10837 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 10838 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10839 | |
| 10840 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10841 | tokens_size = tokln - sizeof(*tok); |
| 10842 | |
| 10843 | if (!tok->len || tokens_size % tok->len) |
| 10844 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10845 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10846 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10847 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10848 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10849 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10850 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10851 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10852 | return -EINVAL; |
| 10853 | if (tok->offset + tok->len > data_size) |
| 10854 | return -EINVAL; |
| 10855 | } |
| 10856 | |
| 10857 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 10858 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10859 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10860 | return -EINVAL; |
| 10861 | if (seq->len == 0 || seq->len > 4) |
| 10862 | return -EINVAL; |
| 10863 | if (seq->len + seq->offset > data_size) |
| 10864 | return -EINVAL; |
| 10865 | } |
| 10866 | |
| 10867 | size = sizeof(*cfg); |
| 10868 | size += data_size; |
| 10869 | size += wake_size + wake_mask_size; |
| 10870 | size += tokens_size; |
| 10871 | |
| 10872 | cfg = kzalloc(size, GFP_KERNEL); |
| 10873 | if (!cfg) |
| 10874 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 10875 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 10876 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10877 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 10878 | ETH_ALEN); |
| 10879 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 10880 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 10881 | else |
| 10882 | port = 0; |
| 10883 | #ifdef CONFIG_INET |
| 10884 | /* allocate a socket and port for it and use it */ |
| 10885 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 10886 | IPPROTO_TCP, &cfg->sock, 1); |
| 10887 | if (err) { |
| 10888 | kfree(cfg); |
| 10889 | return err; |
| 10890 | } |
| 10891 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 10892 | sock_release(cfg->sock); |
| 10893 | kfree(cfg); |
| 10894 | return -EADDRINUSE; |
| 10895 | } |
| 10896 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 10897 | #else |
| 10898 | if (!port) { |
| 10899 | kfree(cfg); |
| 10900 | return -EINVAL; |
| 10901 | } |
| 10902 | cfg->src_port = port; |
| 10903 | #endif |
| 10904 | |
| 10905 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 10906 | cfg->payload_len = data_size; |
| 10907 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 10908 | memcpy((void *)cfg->payload, |
| 10909 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 10910 | data_size); |
| 10911 | if (seq) |
| 10912 | cfg->payload_seq = *seq; |
| 10913 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 10914 | cfg->wake_len = wake_size; |
| 10915 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 10916 | memcpy((void *)cfg->wake_data, |
| 10917 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 10918 | wake_size); |
| 10919 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 10920 | data_size + wake_size; |
| 10921 | memcpy((void *)cfg->wake_mask, |
| 10922 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 10923 | wake_mask_size); |
| 10924 | if (tok) { |
| 10925 | cfg->tokens_size = tokens_size; |
| 10926 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 10927 | } |
| 10928 | |
| 10929 | trig->tcp = cfg; |
| 10930 | |
| 10931 | return 0; |
| 10932 | } |
| 10933 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10934 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 10935 | const struct wiphy_wowlan_support *wowlan, |
| 10936 | struct nlattr *attr, |
| 10937 | struct cfg80211_wowlan *trig) |
| 10938 | { |
| 10939 | struct nlattr **tb; |
| 10940 | int err; |
| 10941 | |
| 10942 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 10943 | if (!tb) |
| 10944 | return -ENOMEM; |
| 10945 | |
| 10946 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 10947 | err = -EOPNOTSUPP; |
| 10948 | goto out; |
| 10949 | } |
| 10950 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10951 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy, |
| 10952 | NULL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10953 | if (err) |
| 10954 | goto out; |
| 10955 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 10956 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 10957 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10958 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 10959 | if (err) |
| 10960 | trig->nd_config = NULL; |
| 10961 | |
| 10962 | out: |
| 10963 | kfree(tb); |
| 10964 | return err; |
| 10965 | } |
| 10966 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10967 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10968 | { |
| 10969 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10970 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10971 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10972 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10973 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10974 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10975 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10976 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10977 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10978 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10979 | return -EOPNOTSUPP; |
| 10980 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10981 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 10982 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10983 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10984 | goto set_wakeup; |
| 10985 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10986 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10987 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG, |
| 10988 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10989 | nl80211_wowlan_policy, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10990 | if (err) |
| 10991 | return err; |
| 10992 | |
| 10993 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 10994 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 10995 | return -EINVAL; |
| 10996 | new_triggers.any = true; |
| 10997 | } |
| 10998 | |
| 10999 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 11000 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 11001 | return -EINVAL; |
| 11002 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11003 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11004 | } |
| 11005 | |
| 11006 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 11007 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 11008 | return -EINVAL; |
| 11009 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11010 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11011 | } |
| 11012 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11013 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 11014 | return -EINVAL; |
| 11015 | |
| 11016 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 11017 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 11018 | return -EINVAL; |
| 11019 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11020 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11021 | } |
| 11022 | |
| 11023 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 11024 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 11025 | return -EINVAL; |
| 11026 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11027 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11028 | } |
| 11029 | |
| 11030 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 11031 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 11032 | return -EINVAL; |
| 11033 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11034 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11035 | } |
| 11036 | |
| 11037 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 11038 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 11039 | return -EINVAL; |
| 11040 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11041 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11042 | } |
| 11043 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11044 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 11045 | struct nlattr *pat; |
| 11046 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11047 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11048 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11049 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11050 | regular = true; |
| 11051 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11052 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 11053 | rem) |
| 11054 | n_patterns++; |
| 11055 | if (n_patterns > wowlan->n_patterns) |
| 11056 | return -EINVAL; |
| 11057 | |
| 11058 | new_triggers.patterns = kcalloc(n_patterns, |
| 11059 | sizeof(new_triggers.patterns[0]), |
| 11060 | GFP_KERNEL); |
| 11061 | if (!new_triggers.patterns) |
| 11062 | return -ENOMEM; |
| 11063 | |
| 11064 | new_triggers.n_patterns = n_patterns; |
| 11065 | i = 0; |
| 11066 | |
| 11067 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 11068 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11069 | u8 *mask_pat; |
| 11070 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11071 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 11072 | nl80211_packet_pattern_policy, |
| 11073 | info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11074 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11075 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 11076 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11077 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11078 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11079 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11080 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11081 | goto error; |
| 11082 | if (pat_len > wowlan->pattern_max_len || |
| 11083 | pat_len < wowlan->pattern_min_len) |
| 11084 | goto error; |
| 11085 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11086 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11087 | pkt_offset = 0; |
| 11088 | else |
| 11089 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11090 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11091 | if (pkt_offset > wowlan->max_pkt_offset) |
| 11092 | goto error; |
| 11093 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 11094 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11095 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 11096 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11097 | err = -ENOMEM; |
| 11098 | goto error; |
| 11099 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11100 | new_triggers.patterns[i].mask = mask_pat; |
| 11101 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11102 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11103 | mask_pat += mask_len; |
| 11104 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11105 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11106 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11107 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11108 | pat_len); |
| 11109 | i++; |
| 11110 | } |
| 11111 | } |
| 11112 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11113 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11114 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11115 | err = nl80211_parse_wowlan_tcp( |
| 11116 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 11117 | &new_triggers); |
| 11118 | if (err) |
| 11119 | goto error; |
| 11120 | } |
| 11121 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11122 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11123 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11124 | err = nl80211_parse_wowlan_nd( |
| 11125 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 11126 | &new_triggers); |
| 11127 | if (err) |
| 11128 | goto error; |
| 11129 | } |
| 11130 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11131 | /* The 'any' trigger means the device continues operating more or less |
| 11132 | * as in its normal operation mode and wakes up the host on most of the |
| 11133 | * normal interrupts (like packet RX, ...) |
| 11134 | * It therefore makes little sense to combine with the more constrained |
| 11135 | * wakeup trigger modes. |
| 11136 | */ |
| 11137 | if (new_triggers.any && regular) { |
| 11138 | err = -EINVAL; |
| 11139 | goto error; |
| 11140 | } |
| 11141 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11142 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 11143 | if (!ntrig) { |
| 11144 | err = -ENOMEM; |
| 11145 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11146 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11147 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11148 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11149 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11150 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11151 | if (rdev->ops->set_wakeup && |
| 11152 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 11153 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 11154 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11155 | return 0; |
| 11156 | error: |
| 11157 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 11158 | kfree(new_triggers.patterns[i].mask); |
| 11159 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11160 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 11161 | sock_release(new_triggers.tcp->sock); |
| 11162 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 11163 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11164 | return err; |
| 11165 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11166 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11167 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11168 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 11169 | struct cfg80211_registered_device *rdev) |
| 11170 | { |
| 11171 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 11172 | int i, j, pat_len; |
| 11173 | struct cfg80211_coalesce_rules *rule; |
| 11174 | |
| 11175 | if (!rdev->coalesce->n_rules) |
| 11176 | return 0; |
| 11177 | |
| 11178 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 11179 | if (!nl_rules) |
| 11180 | return -ENOBUFS; |
| 11181 | |
| 11182 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 11183 | nl_rule = nla_nest_start(msg, i + 1); |
| 11184 | if (!nl_rule) |
| 11185 | return -ENOBUFS; |
| 11186 | |
| 11187 | rule = &rdev->coalesce->rules[i]; |
| 11188 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 11189 | rule->delay)) |
| 11190 | return -ENOBUFS; |
| 11191 | |
| 11192 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 11193 | rule->condition)) |
| 11194 | return -ENOBUFS; |
| 11195 | |
| 11196 | nl_pats = nla_nest_start(msg, |
| 11197 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 11198 | if (!nl_pats) |
| 11199 | return -ENOBUFS; |
| 11200 | |
| 11201 | for (j = 0; j < rule->n_patterns; j++) { |
| 11202 | nl_pat = nla_nest_start(msg, j + 1); |
| 11203 | if (!nl_pat) |
| 11204 | return -ENOBUFS; |
| 11205 | pat_len = rule->patterns[j].pattern_len; |
| 11206 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 11207 | DIV_ROUND_UP(pat_len, 8), |
| 11208 | rule->patterns[j].mask) || |
| 11209 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 11210 | rule->patterns[j].pattern) || |
| 11211 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 11212 | rule->patterns[j].pkt_offset)) |
| 11213 | return -ENOBUFS; |
| 11214 | nla_nest_end(msg, nl_pat); |
| 11215 | } |
| 11216 | nla_nest_end(msg, nl_pats); |
| 11217 | nla_nest_end(msg, nl_rule); |
| 11218 | } |
| 11219 | nla_nest_end(msg, nl_rules); |
| 11220 | |
| 11221 | return 0; |
| 11222 | } |
| 11223 | |
| 11224 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 11225 | { |
| 11226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11227 | struct sk_buff *msg; |
| 11228 | void *hdr; |
| 11229 | |
| 11230 | if (!rdev->wiphy.coalesce) |
| 11231 | return -EOPNOTSUPP; |
| 11232 | |
| 11233 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11234 | if (!msg) |
| 11235 | return -ENOMEM; |
| 11236 | |
| 11237 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11238 | NL80211_CMD_GET_COALESCE); |
| 11239 | if (!hdr) |
| 11240 | goto nla_put_failure; |
| 11241 | |
| 11242 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 11243 | goto nla_put_failure; |
| 11244 | |
| 11245 | genlmsg_end(msg, hdr); |
| 11246 | return genlmsg_reply(msg, info); |
| 11247 | |
| 11248 | nla_put_failure: |
| 11249 | nlmsg_free(msg); |
| 11250 | return -ENOBUFS; |
| 11251 | } |
| 11252 | |
| 11253 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 11254 | { |
| 11255 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 11256 | int i, j; |
| 11257 | struct cfg80211_coalesce_rules *rule; |
| 11258 | |
| 11259 | if (!coalesce) |
| 11260 | return; |
| 11261 | |
| 11262 | for (i = 0; i < coalesce->n_rules; i++) { |
| 11263 | rule = &coalesce->rules[i]; |
| 11264 | for (j = 0; j < rule->n_patterns; j++) |
| 11265 | kfree(rule->patterns[j].mask); |
| 11266 | kfree(rule->patterns); |
| 11267 | } |
| 11268 | kfree(coalesce->rules); |
| 11269 | kfree(coalesce); |
| 11270 | rdev->coalesce = NULL; |
| 11271 | } |
| 11272 | |
| 11273 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 11274 | struct nlattr *rule, |
| 11275 | struct cfg80211_coalesce_rules *new_rule) |
| 11276 | { |
| 11277 | int err, i; |
| 11278 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 11279 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 11280 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 11281 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 11282 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11283 | err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 11284 | nl80211_coalesce_policy, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11285 | if (err) |
| 11286 | return err; |
| 11287 | |
| 11288 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 11289 | new_rule->delay = |
| 11290 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 11291 | if (new_rule->delay > coalesce->max_delay) |
| 11292 | return -EINVAL; |
| 11293 | |
| 11294 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 11295 | new_rule->condition = |
| 11296 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 11297 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 11298 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 11299 | return -EINVAL; |
| 11300 | |
| 11301 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 11302 | return -EINVAL; |
| 11303 | |
| 11304 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 11305 | rem) |
| 11306 | n_patterns++; |
| 11307 | if (n_patterns > coalesce->n_patterns) |
| 11308 | return -EINVAL; |
| 11309 | |
| 11310 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 11311 | GFP_KERNEL); |
| 11312 | if (!new_rule->patterns) |
| 11313 | return -ENOMEM; |
| 11314 | |
| 11315 | new_rule->n_patterns = n_patterns; |
| 11316 | i = 0; |
| 11317 | |
| 11318 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 11319 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11320 | u8 *mask_pat; |
| 11321 | |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 11322 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
| 11323 | nl80211_packet_pattern_policy, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11324 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 11325 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 11326 | return -EINVAL; |
| 11327 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 11328 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 11329 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 11330 | return -EINVAL; |
| 11331 | if (pat_len > coalesce->pattern_max_len || |
| 11332 | pat_len < coalesce->pattern_min_len) |
| 11333 | return -EINVAL; |
| 11334 | |
| 11335 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 11336 | pkt_offset = 0; |
| 11337 | else |
| 11338 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 11339 | if (pkt_offset > coalesce->max_pkt_offset) |
| 11340 | return -EINVAL; |
| 11341 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 11342 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11343 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 11344 | if (!mask_pat) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11345 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11346 | |
| 11347 | new_rule->patterns[i].mask = mask_pat; |
| 11348 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 11349 | mask_len); |
| 11350 | |
| 11351 | mask_pat += mask_len; |
| 11352 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11353 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11354 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 11355 | pat_len); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11356 | i++; |
| 11357 | } |
| 11358 | |
| 11359 | return 0; |
| 11360 | } |
| 11361 | |
| 11362 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 11363 | { |
| 11364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11365 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 11366 | struct cfg80211_coalesce new_coalesce = {}; |
| 11367 | struct cfg80211_coalesce *n_coalesce; |
| 11368 | int err, rem_rule, n_rules = 0, i, j; |
| 11369 | struct nlattr *rule; |
| 11370 | struct cfg80211_coalesce_rules *tmp_rule; |
| 11371 | |
| 11372 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 11373 | return -EOPNOTSUPP; |
| 11374 | |
| 11375 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 11376 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 11377 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11378 | return 0; |
| 11379 | } |
| 11380 | |
| 11381 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 11382 | rem_rule) |
| 11383 | n_rules++; |
| 11384 | if (n_rules > coalesce->n_rules) |
| 11385 | return -EINVAL; |
| 11386 | |
| 11387 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 11388 | GFP_KERNEL); |
| 11389 | if (!new_coalesce.rules) |
| 11390 | return -ENOMEM; |
| 11391 | |
| 11392 | new_coalesce.n_rules = n_rules; |
| 11393 | i = 0; |
| 11394 | |
| 11395 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 11396 | rem_rule) { |
| 11397 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 11398 | &new_coalesce.rules[i]); |
| 11399 | if (err) |
| 11400 | goto error; |
| 11401 | |
| 11402 | i++; |
| 11403 | } |
| 11404 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 11405 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11406 | if (err) |
| 11407 | goto error; |
| 11408 | |
| 11409 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 11410 | if (!n_coalesce) { |
| 11411 | err = -ENOMEM; |
| 11412 | goto error; |
| 11413 | } |
| 11414 | cfg80211_rdev_free_coalesce(rdev); |
| 11415 | rdev->coalesce = n_coalesce; |
| 11416 | |
| 11417 | return 0; |
| 11418 | error: |
| 11419 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 11420 | tmp_rule = &new_coalesce.rules[i]; |
| 11421 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 11422 | kfree(tmp_rule->patterns[j].mask); |
| 11423 | kfree(tmp_rule->patterns); |
| 11424 | } |
| 11425 | kfree(new_coalesce.rules); |
| 11426 | |
| 11427 | return err; |
| 11428 | } |
| 11429 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11430 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 11431 | { |
| 11432 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11433 | struct net_device *dev = info->user_ptr[1]; |
| 11434 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11435 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 11436 | struct cfg80211_gtk_rekey_data rekey_data; |
| 11437 | int err; |
| 11438 | |
| 11439 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 11440 | return -EINVAL; |
| 11441 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11442 | err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA, |
| 11443 | info->attrs[NL80211_ATTR_REKEY_DATA], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11444 | nl80211_rekey_policy, info->extack); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11445 | if (err) |
| 11446 | return err; |
| 11447 | |
Vladis Dronov | e785fa0 | 2017-09-13 00:21:21 +0200 | [diff] [blame] | 11448 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
| 11449 | !tb[NL80211_REKEY_DATA_KCK]) |
| 11450 | return -EINVAL; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11451 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 11452 | return -ERANGE; |
| 11453 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 11454 | return -ERANGE; |
| 11455 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 11456 | return -ERANGE; |
| 11457 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 11458 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 11459 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 11460 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11461 | |
| 11462 | wdev_lock(wdev); |
| 11463 | if (!wdev->current_bss) { |
| 11464 | err = -ENOTCONN; |
| 11465 | goto out; |
| 11466 | } |
| 11467 | |
| 11468 | if (!rdev->ops->set_rekey_data) { |
| 11469 | err = -EOPNOTSUPP; |
| 11470 | goto out; |
| 11471 | } |
| 11472 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11473 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11474 | out: |
| 11475 | wdev_unlock(wdev); |
| 11476 | return err; |
| 11477 | } |
| 11478 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11479 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 11480 | struct genl_info *info) |
| 11481 | { |
| 11482 | struct net_device *dev = info->user_ptr[1]; |
| 11483 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11484 | |
| 11485 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 11486 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 11487 | return -EINVAL; |
| 11488 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11489 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11490 | return -EBUSY; |
| 11491 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11492 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11493 | return 0; |
| 11494 | } |
| 11495 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11496 | static int nl80211_probe_client(struct sk_buff *skb, |
| 11497 | struct genl_info *info) |
| 11498 | { |
| 11499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11500 | struct net_device *dev = info->user_ptr[1]; |
| 11501 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11502 | struct sk_buff *msg; |
| 11503 | void *hdr; |
| 11504 | const u8 *addr; |
| 11505 | u64 cookie; |
| 11506 | int err; |
| 11507 | |
| 11508 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 11509 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 11510 | return -EOPNOTSUPP; |
| 11511 | |
| 11512 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 11513 | return -EINVAL; |
| 11514 | |
| 11515 | if (!rdev->ops->probe_client) |
| 11516 | return -EOPNOTSUPP; |
| 11517 | |
| 11518 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11519 | if (!msg) |
| 11520 | return -ENOMEM; |
| 11521 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11522 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11523 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 11524 | if (!hdr) { |
| 11525 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11526 | goto free_msg; |
| 11527 | } |
| 11528 | |
| 11529 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11530 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11531 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11532 | if (err) |
| 11533 | goto free_msg; |
| 11534 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11535 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11536 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11537 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11538 | |
| 11539 | genlmsg_end(msg, hdr); |
| 11540 | |
| 11541 | return genlmsg_reply(msg, info); |
| 11542 | |
| 11543 | nla_put_failure: |
| 11544 | err = -ENOBUFS; |
| 11545 | free_msg: |
| 11546 | nlmsg_free(msg); |
| 11547 | return err; |
| 11548 | } |
| 11549 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11550 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 11551 | { |
| 11552 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11553 | struct cfg80211_beacon_registration *reg, *nreg; |
| 11554 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11555 | |
| 11556 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 11557 | return -EOPNOTSUPP; |
| 11558 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11559 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 11560 | if (!nreg) |
| 11561 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11562 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11563 | /* First, check if already registered. */ |
| 11564 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11565 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11566 | if (reg->nlportid == info->snd_portid) { |
| 11567 | rv = -EALREADY; |
| 11568 | goto out_err; |
| 11569 | } |
| 11570 | } |
| 11571 | /* Add it to the list */ |
| 11572 | nreg->nlportid = info->snd_portid; |
| 11573 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 11574 | |
| 11575 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11576 | |
| 11577 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11578 | out_err: |
| 11579 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11580 | kfree(nreg); |
| 11581 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11582 | } |
| 11583 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11584 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 11585 | { |
| 11586 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11587 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11588 | int err; |
| 11589 | |
| 11590 | if (!rdev->ops->start_p2p_device) |
| 11591 | return -EOPNOTSUPP; |
| 11592 | |
| 11593 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 11594 | return -EOPNOTSUPP; |
| 11595 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11596 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11597 | return 0; |
| 11598 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 11599 | if (rfkill_blocked(rdev->rfkill)) |
| 11600 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11601 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 11602 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11603 | if (err) |
| 11604 | return err; |
| 11605 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11606 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11607 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11608 | |
| 11609 | return 0; |
| 11610 | } |
| 11611 | |
| 11612 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 11613 | { |
| 11614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11615 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11616 | |
| 11617 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 11618 | return -EOPNOTSUPP; |
| 11619 | |
| 11620 | if (!rdev->ops->stop_p2p_device) |
| 11621 | return -EOPNOTSUPP; |
| 11622 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 11623 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11624 | |
| 11625 | return 0; |
| 11626 | } |
| 11627 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11628 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 11629 | { |
| 11630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11631 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11632 | struct cfg80211_nan_conf conf = {}; |
| 11633 | int err; |
| 11634 | |
| 11635 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11636 | return -EOPNOTSUPP; |
| 11637 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 11638 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11639 | return -EEXIST; |
| 11640 | |
| 11641 | if (rfkill_blocked(rdev->rfkill)) |
| 11642 | return -ERFKILL; |
| 11643 | |
| 11644 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 11645 | return -EINVAL; |
| 11646 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11647 | conf.master_pref = |
| 11648 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11649 | if (!conf.master_pref) |
| 11650 | return -EINVAL; |
| 11651 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 11652 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 11653 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 11654 | |
| 11655 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 11656 | return -EOPNOTSUPP; |
| 11657 | |
| 11658 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 11659 | return -EINVAL; |
| 11660 | |
| 11661 | conf.bands = bands; |
| 11662 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11663 | |
| 11664 | err = rdev_start_nan(rdev, wdev, &conf); |
| 11665 | if (err) |
| 11666 | return err; |
| 11667 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11668 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11669 | rdev->opencount++; |
| 11670 | |
| 11671 | return 0; |
| 11672 | } |
| 11673 | |
| 11674 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 11675 | { |
| 11676 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11677 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11678 | |
| 11679 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11680 | return -EOPNOTSUPP; |
| 11681 | |
| 11682 | cfg80211_stop_nan(rdev, wdev); |
| 11683 | |
| 11684 | return 0; |
| 11685 | } |
| 11686 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11687 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 11688 | { |
| 11689 | struct nlattr *attr; |
| 11690 | int len = 0, n_entries = 0, rem; |
| 11691 | |
| 11692 | nla_for_each_nested(attr, filter_attr, rem) { |
| 11693 | len += nla_len(attr); |
| 11694 | n_entries++; |
| 11695 | } |
| 11696 | |
| 11697 | if (len >= U8_MAX) |
| 11698 | return -EINVAL; |
| 11699 | |
| 11700 | return n_entries; |
| 11701 | } |
| 11702 | |
| 11703 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 11704 | struct cfg80211_nan_func *func, |
| 11705 | bool tx) |
| 11706 | { |
| 11707 | struct nlattr *attr; |
| 11708 | int n_entries, rem, i; |
| 11709 | struct cfg80211_nan_func_filter *filter; |
| 11710 | |
| 11711 | n_entries = validate_nan_filter(attr_filter); |
| 11712 | if (n_entries < 0) |
| 11713 | return n_entries; |
| 11714 | |
| 11715 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 11716 | |
| 11717 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 11718 | if (!filter) |
| 11719 | return -ENOMEM; |
| 11720 | |
| 11721 | i = 0; |
| 11722 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 11723 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11724 | filter[i].len = nla_len(attr); |
| 11725 | i++; |
| 11726 | } |
| 11727 | if (tx) { |
| 11728 | func->num_tx_filters = n_entries; |
| 11729 | func->tx_filters = filter; |
| 11730 | } else { |
| 11731 | func->num_rx_filters = n_entries; |
| 11732 | func->rx_filters = filter; |
| 11733 | } |
| 11734 | |
| 11735 | return 0; |
| 11736 | } |
| 11737 | |
| 11738 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 11739 | struct genl_info *info) |
| 11740 | { |
| 11741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11742 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11743 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 11744 | struct cfg80211_nan_func *func; |
| 11745 | struct sk_buff *msg = NULL; |
| 11746 | void *hdr = NULL; |
| 11747 | int err = 0; |
| 11748 | |
| 11749 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11750 | return -EOPNOTSUPP; |
| 11751 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11752 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11753 | return -ENOTCONN; |
| 11754 | |
| 11755 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 11756 | return -EINVAL; |
| 11757 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11758 | err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 11759 | info->attrs[NL80211_ATTR_NAN_FUNC], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11760 | nl80211_nan_func_policy, info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11761 | if (err) |
| 11762 | return err; |
| 11763 | |
| 11764 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 11765 | if (!func) |
| 11766 | return -ENOMEM; |
| 11767 | |
| 11768 | func->cookie = wdev->wiphy->cookie_counter++; |
| 11769 | |
| 11770 | if (!tb[NL80211_NAN_FUNC_TYPE] || |
| 11771 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { |
| 11772 | err = -EINVAL; |
| 11773 | goto out; |
| 11774 | } |
| 11775 | |
| 11776 | |
| 11777 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 11778 | |
| 11779 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 11780 | err = -EINVAL; |
| 11781 | goto out; |
| 11782 | } |
| 11783 | |
| 11784 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 11785 | sizeof(func->service_id)); |
| 11786 | |
| 11787 | func->close_range = |
| 11788 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 11789 | |
| 11790 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 11791 | func->serv_spec_info_len = |
| 11792 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 11793 | func->serv_spec_info = |
| 11794 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 11795 | func->serv_spec_info_len, |
| 11796 | GFP_KERNEL); |
| 11797 | if (!func->serv_spec_info) { |
| 11798 | err = -ENOMEM; |
| 11799 | goto out; |
| 11800 | } |
| 11801 | } |
| 11802 | |
| 11803 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 11804 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 11805 | |
| 11806 | switch (func->type) { |
| 11807 | case NL80211_NAN_FUNC_PUBLISH: |
| 11808 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 11809 | err = -EINVAL; |
| 11810 | goto out; |
| 11811 | } |
| 11812 | |
| 11813 | func->publish_type = |
| 11814 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 11815 | func->publish_bcast = |
| 11816 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 11817 | |
| 11818 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 11819 | func->publish_bcast) { |
| 11820 | err = -EINVAL; |
| 11821 | goto out; |
| 11822 | } |
| 11823 | break; |
| 11824 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 11825 | func->subscribe_active = |
| 11826 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 11827 | break; |
| 11828 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 11829 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
Hao Chen | 3ea1545 | 2018-01-03 11:00:31 +0800 | [diff] [blame] | 11830 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
| 11831 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11832 | err = -EINVAL; |
| 11833 | goto out; |
| 11834 | } |
| 11835 | |
| 11836 | func->followup_id = |
| 11837 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 11838 | func->followup_reqid = |
| 11839 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 11840 | memcpy(func->followup_dest.addr, |
| 11841 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 11842 | sizeof(func->followup_dest.addr)); |
| 11843 | if (func->ttl) { |
| 11844 | err = -EINVAL; |
| 11845 | goto out; |
| 11846 | } |
| 11847 | break; |
| 11848 | default: |
| 11849 | err = -EINVAL; |
| 11850 | goto out; |
| 11851 | } |
| 11852 | |
| 11853 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 11854 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 11855 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11856 | err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX, |
| 11857 | tb[NL80211_NAN_FUNC_SRF], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11858 | nl80211_nan_srf_policy, info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11859 | if (err) |
| 11860 | goto out; |
| 11861 | |
| 11862 | func->srf_include = |
| 11863 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 11864 | |
| 11865 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 11866 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 11867 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 11868 | err = -EINVAL; |
| 11869 | goto out; |
| 11870 | } |
| 11871 | |
| 11872 | func->srf_bf_len = |
| 11873 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 11874 | func->srf_bf = |
| 11875 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 11876 | func->srf_bf_len, GFP_KERNEL); |
| 11877 | if (!func->srf_bf) { |
| 11878 | err = -ENOMEM; |
| 11879 | goto out; |
| 11880 | } |
| 11881 | |
| 11882 | func->srf_bf_idx = |
| 11883 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 11884 | } else { |
| 11885 | struct nlattr *attr, *mac_attr = |
| 11886 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 11887 | int n_entries, rem, i = 0; |
| 11888 | |
| 11889 | if (!mac_attr) { |
| 11890 | err = -EINVAL; |
| 11891 | goto out; |
| 11892 | } |
| 11893 | |
| 11894 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 11895 | if (n_entries <= 0) { |
| 11896 | err = -EINVAL; |
| 11897 | goto out; |
| 11898 | } |
| 11899 | |
| 11900 | func->srf_num_macs = n_entries; |
| 11901 | func->srf_macs = |
| 11902 | kzalloc(sizeof(*func->srf_macs) * n_entries, |
| 11903 | GFP_KERNEL); |
| 11904 | if (!func->srf_macs) { |
| 11905 | err = -ENOMEM; |
| 11906 | goto out; |
| 11907 | } |
| 11908 | |
| 11909 | nla_for_each_nested(attr, mac_attr, rem) |
| 11910 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 11911 | sizeof(*func->srf_macs)); |
| 11912 | } |
| 11913 | } |
| 11914 | |
| 11915 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 11916 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 11917 | func, true); |
| 11918 | if (err) |
| 11919 | goto out; |
| 11920 | } |
| 11921 | |
| 11922 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 11923 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 11924 | func, false); |
| 11925 | if (err) |
| 11926 | goto out; |
| 11927 | } |
| 11928 | |
| 11929 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11930 | if (!msg) { |
| 11931 | err = -ENOMEM; |
| 11932 | goto out; |
| 11933 | } |
| 11934 | |
| 11935 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11936 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 11937 | /* This can't really happen - we just allocated 4KB */ |
| 11938 | if (WARN_ON(!hdr)) { |
| 11939 | err = -ENOMEM; |
| 11940 | goto out; |
| 11941 | } |
| 11942 | |
| 11943 | err = rdev_add_nan_func(rdev, wdev, func); |
| 11944 | out: |
| 11945 | if (err < 0) { |
| 11946 | cfg80211_free_nan_func(func); |
| 11947 | nlmsg_free(msg); |
| 11948 | return err; |
| 11949 | } |
| 11950 | |
| 11951 | /* propagate the instance id and cookie to userspace */ |
| 11952 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 11953 | NL80211_ATTR_PAD)) |
| 11954 | goto nla_put_failure; |
| 11955 | |
| 11956 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11957 | if (!func_attr) |
| 11958 | goto nla_put_failure; |
| 11959 | |
| 11960 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 11961 | func->instance_id)) |
| 11962 | goto nla_put_failure; |
| 11963 | |
| 11964 | nla_nest_end(msg, func_attr); |
| 11965 | |
| 11966 | genlmsg_end(msg, hdr); |
| 11967 | return genlmsg_reply(msg, info); |
| 11968 | |
| 11969 | nla_put_failure: |
| 11970 | nlmsg_free(msg); |
| 11971 | return -ENOBUFS; |
| 11972 | } |
| 11973 | |
| 11974 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 11975 | struct genl_info *info) |
| 11976 | { |
| 11977 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11978 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11979 | u64 cookie; |
| 11980 | |
| 11981 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11982 | return -EOPNOTSUPP; |
| 11983 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11984 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11985 | return -ENOTCONN; |
| 11986 | |
| 11987 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11988 | return -EINVAL; |
| 11989 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11990 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11991 | |
| 11992 | rdev_del_nan_func(rdev, wdev, cookie); |
| 11993 | |
| 11994 | return 0; |
| 11995 | } |
| 11996 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11997 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 11998 | struct genl_info *info) |
| 11999 | { |
| 12000 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12001 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12002 | struct cfg80211_nan_conf conf = {}; |
| 12003 | u32 changed = 0; |
| 12004 | |
| 12005 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12006 | return -EOPNOTSUPP; |
| 12007 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12008 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12009 | return -ENOTCONN; |
| 12010 | |
| 12011 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 12012 | conf.master_pref = |
| 12013 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 12014 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 12015 | return -EINVAL; |
| 12016 | |
| 12017 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 12018 | } |
| 12019 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 12020 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 12021 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 12022 | |
| 12023 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 12024 | return -EOPNOTSUPP; |
| 12025 | |
| 12026 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 12027 | return -EINVAL; |
| 12028 | |
| 12029 | conf.bands = bands; |
| 12030 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12031 | } |
| 12032 | |
| 12033 | if (!changed) |
| 12034 | return -EINVAL; |
| 12035 | |
| 12036 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 12037 | } |
| 12038 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 12039 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 12040 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 12041 | { |
| 12042 | struct wiphy *wiphy = wdev->wiphy; |
| 12043 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12044 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 12045 | struct sk_buff *msg; |
| 12046 | void *hdr; |
| 12047 | |
| 12048 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 12049 | return; |
| 12050 | |
| 12051 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12052 | if (!msg) |
| 12053 | return; |
| 12054 | |
| 12055 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 12056 | if (!hdr) { |
| 12057 | nlmsg_free(msg); |
| 12058 | return; |
| 12059 | } |
| 12060 | |
| 12061 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12062 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12063 | wdev->netdev->ifindex)) || |
| 12064 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12065 | NL80211_ATTR_PAD)) |
| 12066 | goto nla_put_failure; |
| 12067 | |
| 12068 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 12069 | NL80211_ATTR_PAD) || |
| 12070 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 12071 | goto nla_put_failure; |
| 12072 | |
| 12073 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); |
| 12074 | if (!match_attr) |
| 12075 | goto nla_put_failure; |
| 12076 | |
| 12077 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); |
| 12078 | if (!local_func_attr) |
| 12079 | goto nla_put_failure; |
| 12080 | |
| 12081 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 12082 | goto nla_put_failure; |
| 12083 | |
| 12084 | nla_nest_end(msg, local_func_attr); |
| 12085 | |
| 12086 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); |
| 12087 | if (!peer_func_attr) |
| 12088 | goto nla_put_failure; |
| 12089 | |
| 12090 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 12091 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 12092 | goto nla_put_failure; |
| 12093 | |
| 12094 | if (match->info && match->info_len && |
| 12095 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 12096 | match->info)) |
| 12097 | goto nla_put_failure; |
| 12098 | |
| 12099 | nla_nest_end(msg, peer_func_attr); |
| 12100 | nla_nest_end(msg, match_attr); |
| 12101 | genlmsg_end(msg, hdr); |
| 12102 | |
| 12103 | if (!wdev->owner_nlportid) |
| 12104 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 12105 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 12106 | else |
| 12107 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 12108 | wdev->owner_nlportid); |
| 12109 | |
| 12110 | return; |
| 12111 | |
| 12112 | nla_put_failure: |
| 12113 | nlmsg_free(msg); |
| 12114 | } |
| 12115 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 12116 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 12117 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 12118 | u8 inst_id, |
| 12119 | enum nl80211_nan_func_term_reason reason, |
| 12120 | u64 cookie, gfp_t gfp) |
| 12121 | { |
| 12122 | struct wiphy *wiphy = wdev->wiphy; |
| 12123 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12124 | struct sk_buff *msg; |
| 12125 | struct nlattr *func_attr; |
| 12126 | void *hdr; |
| 12127 | |
| 12128 | if (WARN_ON(!inst_id)) |
| 12129 | return; |
| 12130 | |
| 12131 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12132 | if (!msg) |
| 12133 | return; |
| 12134 | |
| 12135 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 12136 | if (!hdr) { |
| 12137 | nlmsg_free(msg); |
| 12138 | return; |
| 12139 | } |
| 12140 | |
| 12141 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12142 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12143 | wdev->netdev->ifindex)) || |
| 12144 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12145 | NL80211_ATTR_PAD)) |
| 12146 | goto nla_put_failure; |
| 12147 | |
| 12148 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12149 | NL80211_ATTR_PAD)) |
| 12150 | goto nla_put_failure; |
| 12151 | |
| 12152 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 12153 | if (!func_attr) |
| 12154 | goto nla_put_failure; |
| 12155 | |
| 12156 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 12157 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 12158 | goto nla_put_failure; |
| 12159 | |
| 12160 | nla_nest_end(msg, func_attr); |
| 12161 | genlmsg_end(msg, hdr); |
| 12162 | |
| 12163 | if (!wdev->owner_nlportid) |
| 12164 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 12165 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 12166 | else |
| 12167 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 12168 | wdev->owner_nlportid); |
| 12169 | |
| 12170 | return; |
| 12171 | |
| 12172 | nla_put_failure: |
| 12173 | nlmsg_free(msg); |
| 12174 | } |
| 12175 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 12176 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 12177 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 12178 | struct genl_info *info) |
| 12179 | { |
| 12180 | void *hdr; |
| 12181 | struct sk_buff *msg; |
| 12182 | |
| 12183 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12184 | if (!msg) |
| 12185 | return -ENOMEM; |
| 12186 | |
| 12187 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12188 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 12189 | if (!hdr) |
| 12190 | goto nla_put_failure; |
| 12191 | |
| 12192 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 12193 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 12194 | goto nla_put_failure; |
| 12195 | |
| 12196 | genlmsg_end(msg, hdr); |
| 12197 | return genlmsg_reply(msg, info); |
| 12198 | |
| 12199 | nla_put_failure: |
| 12200 | kfree_skb(msg); |
| 12201 | return -ENOBUFS; |
| 12202 | } |
| 12203 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12204 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 12205 | { |
| 12206 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12207 | struct cfg80211_update_ft_ies_params ft_params; |
| 12208 | struct net_device *dev = info->user_ptr[1]; |
| 12209 | |
| 12210 | if (!rdev->ops->update_ft_ies) |
| 12211 | return -EOPNOTSUPP; |
| 12212 | |
| 12213 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 12214 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 12215 | return -EINVAL; |
| 12216 | |
| 12217 | memset(&ft_params, 0, sizeof(ft_params)); |
| 12218 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 12219 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 12220 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 12221 | |
| 12222 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 12223 | } |
| 12224 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12225 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 12226 | struct genl_info *info) |
| 12227 | { |
| 12228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12229 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12230 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 12231 | u16 duration; |
| 12232 | int ret; |
| 12233 | |
| 12234 | if (!rdev->ops->crit_proto_start) |
| 12235 | return -EOPNOTSUPP; |
| 12236 | |
| 12237 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 12238 | return -EINVAL; |
| 12239 | |
| 12240 | if (rdev->crit_proto_nlportid) |
| 12241 | return -EBUSY; |
| 12242 | |
| 12243 | /* determine protocol if provided */ |
| 12244 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 12245 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 12246 | |
| 12247 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 12248 | return -EINVAL; |
| 12249 | |
| 12250 | /* timeout must be provided */ |
| 12251 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 12252 | return -EINVAL; |
| 12253 | |
| 12254 | duration = |
| 12255 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 12256 | |
| 12257 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 12258 | return -ERANGE; |
| 12259 | |
| 12260 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 12261 | if (!ret) |
| 12262 | rdev->crit_proto_nlportid = info->snd_portid; |
| 12263 | |
| 12264 | return ret; |
| 12265 | } |
| 12266 | |
| 12267 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 12268 | struct genl_info *info) |
| 12269 | { |
| 12270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12271 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12272 | |
| 12273 | if (!rdev->ops->crit_proto_stop) |
| 12274 | return -EOPNOTSUPP; |
| 12275 | |
| 12276 | if (rdev->crit_proto_nlportid) { |
| 12277 | rdev->crit_proto_nlportid = 0; |
| 12278 | rdev_crit_proto_stop(rdev, wdev); |
| 12279 | } |
| 12280 | return 0; |
| 12281 | } |
| 12282 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12283 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 12284 | { |
| 12285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12286 | struct wireless_dev *wdev = |
| 12287 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 12288 | int i, err; |
| 12289 | u32 vid, subcmd; |
| 12290 | |
| 12291 | if (!rdev->wiphy.vendor_commands) |
| 12292 | return -EOPNOTSUPP; |
| 12293 | |
| 12294 | if (IS_ERR(wdev)) { |
| 12295 | err = PTR_ERR(wdev); |
| 12296 | if (err != -EINVAL) |
| 12297 | return err; |
| 12298 | wdev = NULL; |
| 12299 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 12300 | return -EINVAL; |
| 12301 | } |
| 12302 | |
| 12303 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 12304 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 12305 | return -EINVAL; |
| 12306 | |
| 12307 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 12308 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 12309 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 12310 | const struct wiphy_vendor_command *vcmd; |
| 12311 | void *data = NULL; |
| 12312 | int len = 0; |
| 12313 | |
| 12314 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 12315 | |
| 12316 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 12317 | continue; |
| 12318 | |
| 12319 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 12320 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 12321 | if (!wdev) |
| 12322 | return -EINVAL; |
| 12323 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 12324 | !wdev->netdev) |
| 12325 | return -EINVAL; |
| 12326 | |
| 12327 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12328 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12329 | return -ENETDOWN; |
| 12330 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12331 | |
| 12332 | if (!vcmd->doit) |
| 12333 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12334 | } else { |
| 12335 | wdev = NULL; |
| 12336 | } |
| 12337 | |
| 12338 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 12339 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 12340 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 12341 | } |
| 12342 | |
| 12343 | rdev->cur_cmd_info = info; |
| 12344 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 12345 | data, len); |
| 12346 | rdev->cur_cmd_info = NULL; |
| 12347 | return err; |
| 12348 | } |
| 12349 | |
| 12350 | return -EOPNOTSUPP; |
| 12351 | } |
| 12352 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12353 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 12354 | struct netlink_callback *cb, |
| 12355 | struct cfg80211_registered_device **rdev, |
| 12356 | struct wireless_dev **wdev) |
| 12357 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12358 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12359 | u32 vid, subcmd; |
| 12360 | unsigned int i; |
| 12361 | int vcmd_idx = -1; |
| 12362 | int err; |
| 12363 | void *data = NULL; |
| 12364 | unsigned int data_len = 0; |
| 12365 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12366 | if (cb->args[0]) { |
| 12367 | /* subtract the 1 again here */ |
| 12368 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 12369 | struct wireless_dev *tmp; |
| 12370 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12371 | if (!wiphy) |
| 12372 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12373 | *rdev = wiphy_to_rdev(wiphy); |
| 12374 | *wdev = NULL; |
| 12375 | |
| 12376 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 12377 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12378 | if (tmp->identifier == cb->args[1] - 1) { |
| 12379 | *wdev = tmp; |
| 12380 | break; |
| 12381 | } |
| 12382 | } |
| 12383 | } |
| 12384 | |
| 12385 | /* keep rtnl locked in successful case */ |
| 12386 | return 0; |
| 12387 | } |
| 12388 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 12389 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf, |
| 12390 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12391 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12392 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12393 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12394 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12395 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) |
| 12396 | return -EINVAL; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12397 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12398 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12399 | if (IS_ERR(*wdev)) |
| 12400 | *wdev = NULL; |
| 12401 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12402 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12403 | if (IS_ERR(*rdev)) |
| 12404 | return PTR_ERR(*rdev); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12405 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12406 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 12407 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12408 | |
| 12409 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 12410 | const struct wiphy_vendor_command *vcmd; |
| 12411 | |
| 12412 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 12413 | |
| 12414 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 12415 | continue; |
| 12416 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12417 | if (!vcmd->dumpit) |
| 12418 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12419 | |
| 12420 | vcmd_idx = i; |
| 12421 | break; |
| 12422 | } |
| 12423 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12424 | if (vcmd_idx < 0) |
| 12425 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12426 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 12427 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 12428 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 12429 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12430 | } |
| 12431 | |
| 12432 | /* 0 is the first index - add 1 to parse only once */ |
| 12433 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 12434 | /* add 1 to know if it was NULL */ |
| 12435 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 12436 | cb->args[2] = vcmd_idx; |
| 12437 | cb->args[3] = (unsigned long)data; |
| 12438 | cb->args[4] = data_len; |
| 12439 | |
| 12440 | /* keep rtnl locked in successful case */ |
| 12441 | return 0; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12442 | } |
| 12443 | |
| 12444 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 12445 | struct netlink_callback *cb) |
| 12446 | { |
| 12447 | struct cfg80211_registered_device *rdev; |
| 12448 | struct wireless_dev *wdev; |
| 12449 | unsigned int vcmd_idx; |
| 12450 | const struct wiphy_vendor_command *vcmd; |
| 12451 | void *data; |
| 12452 | int data_len; |
| 12453 | int err; |
| 12454 | struct nlattr *vendor_data; |
| 12455 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12456 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12457 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 12458 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12459 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12460 | |
| 12461 | vcmd_idx = cb->args[2]; |
| 12462 | data = (void *)cb->args[3]; |
| 12463 | data_len = cb->args[4]; |
| 12464 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 12465 | |
| 12466 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 12467 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12468 | if (!wdev) { |
| 12469 | err = -EINVAL; |
| 12470 | goto out; |
| 12471 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12472 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12473 | !wdev->netdev) { |
| 12474 | err = -EINVAL; |
| 12475 | goto out; |
| 12476 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12477 | |
| 12478 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12479 | if (!wdev_running(wdev)) { |
| 12480 | err = -ENETDOWN; |
| 12481 | goto out; |
| 12482 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12483 | } |
| 12484 | } |
| 12485 | |
| 12486 | while (1) { |
| 12487 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 12488 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 12489 | NL80211_CMD_VENDOR); |
| 12490 | if (!hdr) |
| 12491 | break; |
| 12492 | |
| 12493 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12494 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 12495 | wdev_id(wdev), |
| 12496 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12497 | genlmsg_cancel(skb, hdr); |
| 12498 | break; |
| 12499 | } |
| 12500 | |
| 12501 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 12502 | if (!vendor_data) { |
| 12503 | genlmsg_cancel(skb, hdr); |
| 12504 | break; |
| 12505 | } |
| 12506 | |
| 12507 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 12508 | (unsigned long *)&cb->args[5]); |
| 12509 | nla_nest_end(skb, vendor_data); |
| 12510 | |
| 12511 | if (err == -ENOBUFS || err == -ENOENT) { |
| 12512 | genlmsg_cancel(skb, hdr); |
| 12513 | break; |
| 12514 | } else if (err) { |
| 12515 | genlmsg_cancel(skb, hdr); |
| 12516 | goto out; |
| 12517 | } |
| 12518 | |
| 12519 | genlmsg_end(skb, hdr); |
| 12520 | } |
| 12521 | |
| 12522 | err = skb->len; |
| 12523 | out: |
| 12524 | rtnl_unlock(); |
| 12525 | return err; |
| 12526 | } |
| 12527 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12528 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 12529 | enum nl80211_commands cmd, |
| 12530 | enum nl80211_attrs attr, |
| 12531 | int approxlen) |
| 12532 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12533 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12534 | |
| 12535 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 12536 | return NULL; |
| 12537 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 12538 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12539 | rdev->cur_cmd_info->snd_portid, |
| 12540 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 12541 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12542 | } |
| 12543 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 12544 | |
| 12545 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 12546 | { |
| 12547 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 12548 | void *hdr = ((void **)skb->cb)[1]; |
| 12549 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 12550 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 12551 | /* clear CB data for netlink core to own from now on */ |
| 12552 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 12553 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12554 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 12555 | kfree_skb(skb); |
| 12556 | return -EINVAL; |
| 12557 | } |
| 12558 | |
| 12559 | nla_nest_end(skb, data); |
| 12560 | genlmsg_end(skb, hdr); |
| 12561 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 12562 | } |
| 12563 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 12564 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12565 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 12566 | struct genl_info *info) |
| 12567 | { |
| 12568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12569 | struct cfg80211_qos_map *qos_map = NULL; |
| 12570 | struct net_device *dev = info->user_ptr[1]; |
| 12571 | u8 *pos, len, num_des, des_len, des; |
| 12572 | int ret; |
| 12573 | |
| 12574 | if (!rdev->ops->set_qos_map) |
| 12575 | return -EOPNOTSUPP; |
| 12576 | |
| 12577 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 12578 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 12579 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 12580 | |
| 12581 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 12582 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 12583 | return -EINVAL; |
| 12584 | |
| 12585 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 12586 | if (!qos_map) |
| 12587 | return -ENOMEM; |
| 12588 | |
| 12589 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 12590 | if (num_des) { |
| 12591 | des_len = num_des * |
| 12592 | sizeof(struct cfg80211_dscp_exception); |
| 12593 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 12594 | qos_map->num_des = num_des; |
| 12595 | for (des = 0; des < num_des; des++) { |
| 12596 | if (qos_map->dscp_exception[des].up > 7) { |
| 12597 | kfree(qos_map); |
| 12598 | return -EINVAL; |
| 12599 | } |
| 12600 | } |
| 12601 | pos += des_len; |
| 12602 | } |
| 12603 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 12604 | } |
| 12605 | |
| 12606 | wdev_lock(dev->ieee80211_ptr); |
| 12607 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 12608 | if (!ret) |
| 12609 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 12610 | wdev_unlock(dev->ieee80211_ptr); |
| 12611 | |
| 12612 | kfree(qos_map); |
| 12613 | return ret; |
| 12614 | } |
| 12615 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12616 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12617 | { |
| 12618 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12619 | struct net_device *dev = info->user_ptr[1]; |
| 12620 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12621 | const u8 *peer; |
| 12622 | u8 tsid, up; |
| 12623 | u16 admitted_time = 0; |
| 12624 | int err; |
| 12625 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12626 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12627 | return -EOPNOTSUPP; |
| 12628 | |
| 12629 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 12630 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 12631 | return -EINVAL; |
| 12632 | |
| 12633 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12634 | if (tsid >= IEEE80211_NUM_TIDS) |
| 12635 | return -EINVAL; |
| 12636 | |
| 12637 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 12638 | if (up >= IEEE80211_NUM_UPS) |
| 12639 | return -EINVAL; |
| 12640 | |
| 12641 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12642 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12643 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12644 | * need more attributes for that (e.g. BA session requirement); |
| 12645 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12646 | */ |
| 12647 | return -EINVAL; |
| 12648 | } |
| 12649 | |
| 12650 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12651 | |
| 12652 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 12653 | admitted_time = |
| 12654 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 12655 | if (!admitted_time) |
| 12656 | return -EINVAL; |
| 12657 | } |
| 12658 | |
| 12659 | wdev_lock(wdev); |
| 12660 | switch (wdev->iftype) { |
| 12661 | case NL80211_IFTYPE_STATION: |
| 12662 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12663 | if (wdev->current_bss) |
| 12664 | break; |
| 12665 | err = -ENOTCONN; |
| 12666 | goto out; |
| 12667 | default: |
| 12668 | err = -EOPNOTSUPP; |
| 12669 | goto out; |
| 12670 | } |
| 12671 | |
| 12672 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 12673 | |
| 12674 | out: |
| 12675 | wdev_unlock(wdev); |
| 12676 | return err; |
| 12677 | } |
| 12678 | |
| 12679 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12680 | { |
| 12681 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12682 | struct net_device *dev = info->user_ptr[1]; |
| 12683 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12684 | const u8 *peer; |
| 12685 | u8 tsid; |
| 12686 | int err; |
| 12687 | |
| 12688 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 12689 | return -EINVAL; |
| 12690 | |
| 12691 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12692 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12693 | |
| 12694 | wdev_lock(wdev); |
| 12695 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 12696 | wdev_unlock(wdev); |
| 12697 | |
| 12698 | return err; |
| 12699 | } |
| 12700 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12701 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 12702 | struct genl_info *info) |
| 12703 | { |
| 12704 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12705 | struct net_device *dev = info->user_ptr[1]; |
| 12706 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12707 | struct cfg80211_chan_def chandef = {}; |
| 12708 | const u8 *addr; |
| 12709 | u8 oper_class; |
| 12710 | int err; |
| 12711 | |
| 12712 | if (!rdev->ops->tdls_channel_switch || |
| 12713 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12714 | return -EOPNOTSUPP; |
| 12715 | |
| 12716 | switch (dev->ieee80211_ptr->iftype) { |
| 12717 | case NL80211_IFTYPE_STATION: |
| 12718 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12719 | break; |
| 12720 | default: |
| 12721 | return -EOPNOTSUPP; |
| 12722 | } |
| 12723 | |
| 12724 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 12725 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 12726 | return -EINVAL; |
| 12727 | |
| 12728 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 12729 | if (err) |
| 12730 | return err; |
| 12731 | |
| 12732 | /* |
| 12733 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 12734 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 12735 | * specification is not defined for them. |
| 12736 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 12737 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12738 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 12739 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 12740 | return -EINVAL; |
| 12741 | |
| 12742 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 12743 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 12744 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12745 | return -EINVAL; |
| 12746 | |
| 12747 | /* don't allow switching to DFS channels */ |
| 12748 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 12749 | return -EINVAL; |
| 12750 | |
| 12751 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12752 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 12753 | |
| 12754 | wdev_lock(wdev); |
| 12755 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 12756 | wdev_unlock(wdev); |
| 12757 | |
| 12758 | return err; |
| 12759 | } |
| 12760 | |
| 12761 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 12762 | struct genl_info *info) |
| 12763 | { |
| 12764 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12765 | struct net_device *dev = info->user_ptr[1]; |
| 12766 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12767 | const u8 *addr; |
| 12768 | |
| 12769 | if (!rdev->ops->tdls_channel_switch || |
| 12770 | !rdev->ops->tdls_cancel_channel_switch || |
| 12771 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12772 | return -EOPNOTSUPP; |
| 12773 | |
| 12774 | switch (dev->ieee80211_ptr->iftype) { |
| 12775 | case NL80211_IFTYPE_STATION: |
| 12776 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12777 | break; |
| 12778 | default: |
| 12779 | return -EOPNOTSUPP; |
| 12780 | } |
| 12781 | |
| 12782 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12783 | return -EINVAL; |
| 12784 | |
| 12785 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12786 | |
| 12787 | wdev_lock(wdev); |
| 12788 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 12789 | wdev_unlock(wdev); |
| 12790 | |
| 12791 | return 0; |
| 12792 | } |
| 12793 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12794 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 12795 | struct genl_info *info) |
| 12796 | { |
| 12797 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12798 | struct net_device *dev = info->user_ptr[1]; |
| 12799 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12800 | const struct nlattr *nla; |
| 12801 | bool enabled; |
| 12802 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12803 | if (!rdev->ops->set_multicast_to_unicast) |
| 12804 | return -EOPNOTSUPP; |
| 12805 | |
| 12806 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12807 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12808 | return -EOPNOTSUPP; |
| 12809 | |
| 12810 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 12811 | enabled = nla_get_flag(nla); |
| 12812 | |
| 12813 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 12814 | } |
| 12815 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 12816 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 12817 | { |
| 12818 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12819 | struct net_device *dev = info->user_ptr[1]; |
| 12820 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12821 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 12822 | int ret; |
| 12823 | |
| 12824 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 12825 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 12826 | return -EOPNOTSUPP; |
| 12827 | |
| 12828 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 12829 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 12830 | return -EOPNOTSUPP; |
| 12831 | |
| 12832 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 12833 | return -EINVAL; |
| 12834 | |
| 12835 | wdev_lock(wdev); |
| 12836 | if (!wdev->current_bss) { |
| 12837 | ret = -ENOTCONN; |
| 12838 | goto out; |
| 12839 | } |
| 12840 | |
| 12841 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12842 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 12843 | ret = -EINVAL; |
| 12844 | goto out; |
| 12845 | } |
| 12846 | |
| 12847 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 12848 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 12849 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 12850 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 12851 | ret = -EINVAL; |
| 12852 | goto out; |
| 12853 | } |
| 12854 | |
| 12855 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { |
| 12856 | int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 12857 | |
| 12858 | if (r0_name_len != WLAN_PMK_NAME_LEN) { |
| 12859 | ret = -EINVAL; |
| 12860 | goto out; |
| 12861 | } |
| 12862 | |
| 12863 | pmk_conf.pmk_r0_name = |
| 12864 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 12865 | } |
| 12866 | |
| 12867 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 12868 | out: |
| 12869 | wdev_unlock(wdev); |
| 12870 | return ret; |
| 12871 | } |
| 12872 | |
| 12873 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 12874 | { |
| 12875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12876 | struct net_device *dev = info->user_ptr[1]; |
| 12877 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12878 | const u8 *aa; |
| 12879 | int ret; |
| 12880 | |
| 12881 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 12882 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 12883 | return -EOPNOTSUPP; |
| 12884 | |
| 12885 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 12886 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 12887 | return -EOPNOTSUPP; |
| 12888 | |
| 12889 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12890 | return -EINVAL; |
| 12891 | |
| 12892 | wdev_lock(wdev); |
| 12893 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12894 | ret = rdev_del_pmk(rdev, dev, aa); |
| 12895 | wdev_unlock(wdev); |
| 12896 | |
| 12897 | return ret; |
| 12898 | } |
| 12899 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 12900 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
| 12901 | { |
| 12902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12903 | struct net_device *dev = info->user_ptr[1]; |
| 12904 | struct cfg80211_external_auth_params params; |
| 12905 | |
Srinivas Dasari | db8d93a | 2018-02-02 11:15:27 +0200 | [diff] [blame] | 12906 | if (!rdev->ops->external_auth) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 12907 | return -EOPNOTSUPP; |
| 12908 | |
| 12909 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 12910 | return -EINVAL; |
| 12911 | |
| 12912 | if (!info->attrs[NL80211_ATTR_BSSID]) |
| 12913 | return -EINVAL; |
| 12914 | |
| 12915 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) |
| 12916 | return -EINVAL; |
| 12917 | |
| 12918 | memset(¶ms, 0, sizeof(params)); |
| 12919 | |
| 12920 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 12921 | if (params.ssid.ssid_len == 0 || |
| 12922 | params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 12923 | return -EINVAL; |
| 12924 | memcpy(params.ssid.ssid, nla_data(info->attrs[NL80211_ATTR_SSID]), |
| 12925 | params.ssid.ssid_len); |
| 12926 | |
| 12927 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), |
| 12928 | ETH_ALEN); |
| 12929 | |
| 12930 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 12931 | |
| 12932 | return rdev_external_auth(rdev, dev, ¶ms); |
| 12933 | } |
| 12934 | |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 12935 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) |
| 12936 | { |
| 12937 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12938 | struct net_device *dev = info->user_ptr[1]; |
| 12939 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12940 | const u8 *buf; |
| 12941 | size_t len; |
| 12942 | u8 *dest; |
| 12943 | u16 proto; |
| 12944 | bool noencrypt; |
| 12945 | int err; |
| 12946 | |
| 12947 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 12948 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 12949 | return -EOPNOTSUPP; |
| 12950 | |
| 12951 | if (!rdev->ops->tx_control_port) |
| 12952 | return -EOPNOTSUPP; |
| 12953 | |
| 12954 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 12955 | !info->attrs[NL80211_ATTR_MAC] || |
| 12956 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 12957 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); |
| 12958 | return -EINVAL; |
| 12959 | } |
| 12960 | |
| 12961 | wdev_lock(wdev); |
| 12962 | |
| 12963 | switch (wdev->iftype) { |
| 12964 | case NL80211_IFTYPE_AP: |
| 12965 | case NL80211_IFTYPE_P2P_GO: |
| 12966 | case NL80211_IFTYPE_MESH_POINT: |
| 12967 | break; |
| 12968 | case NL80211_IFTYPE_ADHOC: |
| 12969 | case NL80211_IFTYPE_STATION: |
| 12970 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12971 | if (wdev->current_bss) |
| 12972 | break; |
| 12973 | err = -ENOTCONN; |
| 12974 | goto out; |
| 12975 | default: |
| 12976 | err = -EOPNOTSUPP; |
| 12977 | goto out; |
| 12978 | } |
| 12979 | |
| 12980 | wdev_unlock(wdev); |
| 12981 | |
| 12982 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 12983 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 12984 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12985 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 12986 | noencrypt = |
| 12987 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); |
| 12988 | |
| 12989 | return rdev_tx_control_port(rdev, dev, buf, len, |
| 12990 | dest, cpu_to_be16(proto), noencrypt); |
| 12991 | |
| 12992 | out: |
| 12993 | wdev_unlock(wdev); |
| 12994 | return err; |
| 12995 | } |
| 12996 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12997 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 12998 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 12999 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13000 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 13001 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 13002 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13003 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13004 | /* 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] | 13005 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 13006 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13007 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13008 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 13009 | 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] | 13010 | struct genl_info *info) |
| 13011 | { |
| 13012 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13013 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13014 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13015 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 13016 | |
| 13017 | if (rtnl) |
| 13018 | rtnl_lock(); |
| 13019 | |
| 13020 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 13021 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13022 | if (IS_ERR(rdev)) { |
| 13023 | if (rtnl) |
| 13024 | rtnl_unlock(); |
| 13025 | return PTR_ERR(rdev); |
| 13026 | } |
| 13027 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13028 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 13029 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 13030 | ASSERT_RTNL(); |
| 13031 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13032 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 13033 | info->attrs); |
| 13034 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13035 | if (rtnl) |
| 13036 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13037 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13038 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13039 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13040 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13041 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13042 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13043 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 13044 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13045 | if (rtnl) |
| 13046 | rtnl_unlock(); |
| 13047 | return -EINVAL; |
| 13048 | } |
| 13049 | |
| 13050 | info->user_ptr[1] = dev; |
| 13051 | } else { |
| 13052 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13053 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 13054 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13055 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 13056 | !wdev_running(wdev)) { |
| 13057 | if (rtnl) |
| 13058 | rtnl_unlock(); |
| 13059 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13060 | } |
| 13061 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13062 | if (dev) |
| 13063 | dev_hold(dev); |
| 13064 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13065 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13066 | } |
| 13067 | |
| 13068 | return 0; |
| 13069 | } |
| 13070 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 13071 | 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] | 13072 | struct genl_info *info) |
| 13073 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 13074 | if (info->user_ptr[1]) { |
| 13075 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 13076 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13077 | |
| 13078 | if (wdev->netdev) |
| 13079 | dev_put(wdev->netdev); |
| 13080 | } else { |
| 13081 | dev_put(info->user_ptr[1]); |
| 13082 | } |
| 13083 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13084 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13085 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 13086 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13087 | |
| 13088 | /* If needed, clear the netlink message payload from the SKB |
| 13089 | * as it might contain key data that shouldn't stick around on |
| 13090 | * the heap after the SKB is freed. The netlink message header |
| 13091 | * is still needed for further processing, so leave it intact. |
| 13092 | */ |
| 13093 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 13094 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 13095 | |
| 13096 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 13097 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13098 | } |
| 13099 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 13100 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13101 | { |
| 13102 | .cmd = NL80211_CMD_GET_WIPHY, |
| 13103 | .doit = nl80211_get_wiphy, |
| 13104 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 13105 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13106 | .policy = nl80211_policy, |
| 13107 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 13108 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13109 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13110 | }, |
| 13111 | { |
| 13112 | .cmd = NL80211_CMD_SET_WIPHY, |
| 13113 | .doit = nl80211_set_wiphy, |
| 13114 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13115 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13116 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13117 | }, |
| 13118 | { |
| 13119 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 13120 | .doit = nl80211_get_interface, |
| 13121 | .dumpit = nl80211_dump_interface, |
| 13122 | .policy = nl80211_policy, |
| 13123 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 13124 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13125 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13126 | }, |
| 13127 | { |
| 13128 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 13129 | .doit = nl80211_set_interface, |
| 13130 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13131 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13132 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13133 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13134 | }, |
| 13135 | { |
| 13136 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 13137 | .doit = nl80211_new_interface, |
| 13138 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13139 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13140 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13141 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13142 | }, |
| 13143 | { |
| 13144 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 13145 | .doit = nl80211_del_interface, |
| 13146 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13147 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 13148 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13149 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13150 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 13151 | { |
| 13152 | .cmd = NL80211_CMD_GET_KEY, |
| 13153 | .doit = nl80211_get_key, |
| 13154 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13155 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13156 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13157 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 13158 | }, |
| 13159 | { |
| 13160 | .cmd = NL80211_CMD_SET_KEY, |
| 13161 | .doit = nl80211_set_key, |
| 13162 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13163 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13164 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13165 | NL80211_FLAG_NEED_RTNL | |
| 13166 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 13167 | }, |
| 13168 | { |
| 13169 | .cmd = NL80211_CMD_NEW_KEY, |
| 13170 | .doit = nl80211_new_key, |
| 13171 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13172 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13173 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13174 | NL80211_FLAG_NEED_RTNL | |
| 13175 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 13176 | }, |
| 13177 | { |
| 13178 | .cmd = NL80211_CMD_DEL_KEY, |
| 13179 | .doit = nl80211_del_key, |
| 13180 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13181 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13182 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13183 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 13184 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13185 | { |
| 13186 | .cmd = NL80211_CMD_SET_BEACON, |
| 13187 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13188 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 13189 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13190 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13191 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13192 | }, |
| 13193 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 13194 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13195 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13196 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 13197 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13198 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13199 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13200 | }, |
| 13201 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 13202 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13203 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13204 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 13205 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13206 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13207 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 13208 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13209 | { |
| 13210 | .cmd = NL80211_CMD_GET_STATION, |
| 13211 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13212 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13213 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13214 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13215 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13216 | }, |
| 13217 | { |
| 13218 | .cmd = NL80211_CMD_SET_STATION, |
| 13219 | .doit = nl80211_set_station, |
| 13220 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13221 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13222 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13223 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13224 | }, |
| 13225 | { |
| 13226 | .cmd = NL80211_CMD_NEW_STATION, |
| 13227 | .doit = nl80211_new_station, |
| 13228 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13229 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13230 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13231 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13232 | }, |
| 13233 | { |
| 13234 | .cmd = NL80211_CMD_DEL_STATION, |
| 13235 | .doit = nl80211_del_station, |
| 13236 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13237 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13238 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13239 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 13240 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13241 | { |
| 13242 | .cmd = NL80211_CMD_GET_MPATH, |
| 13243 | .doit = nl80211_get_mpath, |
| 13244 | .dumpit = nl80211_dump_mpath, |
| 13245 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13246 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13247 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13248 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13249 | }, |
| 13250 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 13251 | .cmd = NL80211_CMD_GET_MPP, |
| 13252 | .doit = nl80211_get_mpp, |
| 13253 | .dumpit = nl80211_dump_mpp, |
| 13254 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13255 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 13256 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13257 | NL80211_FLAG_NEED_RTNL, |
| 13258 | }, |
| 13259 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13260 | .cmd = NL80211_CMD_SET_MPATH, |
| 13261 | .doit = nl80211_set_mpath, |
| 13262 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13263 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13264 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13265 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13266 | }, |
| 13267 | { |
| 13268 | .cmd = NL80211_CMD_NEW_MPATH, |
| 13269 | .doit = nl80211_new_mpath, |
| 13270 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13271 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13272 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13273 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13274 | }, |
| 13275 | { |
| 13276 | .cmd = NL80211_CMD_DEL_MPATH, |
| 13277 | .doit = nl80211_del_mpath, |
| 13278 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13279 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13280 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13281 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 13282 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 13283 | { |
| 13284 | .cmd = NL80211_CMD_SET_BSS, |
| 13285 | .doit = nl80211_set_bss, |
| 13286 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13287 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13288 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13289 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 13290 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 13291 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 13292 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13293 | .doit = nl80211_get_reg_do, |
| 13294 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 13295 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 13296 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 13297 | /* can be retrieved by unprivileged users */ |
| 13298 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 13299 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 13300 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 13301 | .cmd = NL80211_CMD_SET_REG, |
| 13302 | .doit = nl80211_set_reg, |
| 13303 | .policy = nl80211_policy, |
| 13304 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 13305 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 13306 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 13307 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 13308 | { |
| 13309 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 13310 | .doit = nl80211_req_set_reg, |
| 13311 | .policy = nl80211_policy, |
| 13312 | .flags = GENL_ADMIN_PERM, |
| 13313 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 13314 | { |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 13315 | .cmd = NL80211_CMD_RELOAD_REGDB, |
| 13316 | .doit = nl80211_reload_regdb, |
| 13317 | .policy = nl80211_policy, |
| 13318 | .flags = GENL_ADMIN_PERM, |
| 13319 | }, |
| 13320 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 13321 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 13322 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 13323 | .policy = nl80211_policy, |
| 13324 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13325 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13326 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 13327 | }, |
| 13328 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 13329 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 13330 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 13331 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13332 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13333 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13334 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 13335 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 13336 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13337 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 13338 | .doit = nl80211_trigger_scan, |
| 13339 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13340 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13341 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13342 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13343 | }, |
| 13344 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 13345 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 13346 | .doit = nl80211_abort_scan, |
| 13347 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13348 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 13349 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13350 | NL80211_FLAG_NEED_RTNL, |
| 13351 | }, |
| 13352 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13353 | .cmd = NL80211_CMD_GET_SCAN, |
| 13354 | .policy = nl80211_policy, |
| 13355 | .dumpit = nl80211_dump_scan, |
| 13356 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13357 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13358 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 13359 | .doit = nl80211_start_sched_scan, |
| 13360 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13361 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13362 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13363 | NL80211_FLAG_NEED_RTNL, |
| 13364 | }, |
| 13365 | { |
| 13366 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 13367 | .doit = nl80211_stop_sched_scan, |
| 13368 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13369 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13370 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13371 | NL80211_FLAG_NEED_RTNL, |
| 13372 | }, |
| 13373 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13374 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 13375 | .doit = nl80211_authenticate, |
| 13376 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13377 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13378 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13379 | NL80211_FLAG_NEED_RTNL | |
| 13380 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13381 | }, |
| 13382 | { |
| 13383 | .cmd = NL80211_CMD_ASSOCIATE, |
| 13384 | .doit = nl80211_associate, |
| 13385 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13386 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13387 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13388 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13389 | }, |
| 13390 | { |
| 13391 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 13392 | .doit = nl80211_deauthenticate, |
| 13393 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13394 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13395 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13396 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13397 | }, |
| 13398 | { |
| 13399 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 13400 | .doit = nl80211_disassociate, |
| 13401 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13402 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13403 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13404 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 13405 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13406 | { |
| 13407 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 13408 | .doit = nl80211_join_ibss, |
| 13409 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13410 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13411 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13412 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13413 | }, |
| 13414 | { |
| 13415 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 13416 | .doit = nl80211_leave_ibss, |
| 13417 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13418 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13419 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13420 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13421 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 13422 | #ifdef CONFIG_NL80211_TESTMODE |
| 13423 | { |
| 13424 | .cmd = NL80211_CMD_TESTMODE, |
| 13425 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 13426 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 13427 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13428 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13429 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13430 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 13431 | }, |
| 13432 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13433 | { |
| 13434 | .cmd = NL80211_CMD_CONNECT, |
| 13435 | .doit = nl80211_connect, |
| 13436 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13437 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13438 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13439 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13440 | }, |
| 13441 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 13442 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
| 13443 | .doit = nl80211_update_connect_params, |
| 13444 | .policy = nl80211_policy, |
| 13445 | .flags = GENL_ADMIN_PERM, |
| 13446 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13447 | NL80211_FLAG_NEED_RTNL, |
| 13448 | }, |
| 13449 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13450 | .cmd = NL80211_CMD_DISCONNECT, |
| 13451 | .doit = nl80211_disconnect, |
| 13452 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13453 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 13454 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13455 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13456 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13457 | { |
| 13458 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 13459 | .doit = nl80211_wiphy_netns, |
| 13460 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13461 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13462 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13463 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13464 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 13465 | { |
| 13466 | .cmd = NL80211_CMD_GET_SURVEY, |
| 13467 | .policy = nl80211_policy, |
| 13468 | .dumpit = nl80211_dump_survey, |
| 13469 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 13470 | { |
| 13471 | .cmd = NL80211_CMD_SET_PMKSA, |
| 13472 | .doit = nl80211_setdel_pmksa, |
| 13473 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13474 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13475 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13476 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 13477 | }, |
| 13478 | { |
| 13479 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 13480 | .doit = nl80211_setdel_pmksa, |
| 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, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 13485 | }, |
| 13486 | { |
| 13487 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 13488 | .doit = nl80211_flush_pmksa, |
| 13489 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13490 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 13493 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13494 | { |
| 13495 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 13496 | .doit = nl80211_remain_on_channel, |
| 13497 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13498 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13499 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13500 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13501 | }, |
| 13502 | { |
| 13503 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 13504 | .doit = nl80211_cancel_remain_on_channel, |
| 13505 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13506 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13507 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13508 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13509 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 13510 | { |
| 13511 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 13512 | .doit = nl80211_set_tx_bitrate_mask, |
| 13513 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13514 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13515 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13516 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 13517 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13518 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 13519 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 13520 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13521 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13522 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13523 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13524 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13525 | }, |
| 13526 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 13527 | .cmd = NL80211_CMD_FRAME, |
| 13528 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13529 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13530 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13531 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13532 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13533 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 13534 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 13535 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 13536 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 13537 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13538 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13539 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 13540 | NL80211_FLAG_NEED_RTNL, |
| 13541 | }, |
| 13542 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 13543 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 13544 | .doit = nl80211_set_power_save, |
| 13545 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13546 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13547 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13548 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 13549 | }, |
| 13550 | { |
| 13551 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 13552 | .doit = nl80211_get_power_save, |
| 13553 | .policy = nl80211_policy, |
| 13554 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13555 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13556 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 13557 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13558 | { |
| 13559 | .cmd = NL80211_CMD_SET_CQM, |
| 13560 | .doit = nl80211_set_cqm, |
| 13561 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13562 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13563 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13564 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13565 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 13566 | { |
| 13567 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 13568 | .doit = nl80211_set_channel, |
| 13569 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13570 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13571 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13572 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 13573 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 13574 | { |
| 13575 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 13576 | .doit = nl80211_set_wds_peer, |
| 13577 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13578 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 13579 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13580 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 13581 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13582 | { |
| 13583 | .cmd = NL80211_CMD_JOIN_MESH, |
| 13584 | .doit = nl80211_join_mesh, |
| 13585 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13586 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13587 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13588 | NL80211_FLAG_NEED_RTNL, |
| 13589 | }, |
| 13590 | { |
| 13591 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 13592 | .doit = nl80211_leave_mesh, |
| 13593 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13594 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13595 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13596 | NL80211_FLAG_NEED_RTNL, |
| 13597 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 13598 | { |
| 13599 | .cmd = NL80211_CMD_JOIN_OCB, |
| 13600 | .doit = nl80211_join_ocb, |
| 13601 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13602 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 13603 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13604 | NL80211_FLAG_NEED_RTNL, |
| 13605 | }, |
| 13606 | { |
| 13607 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 13608 | .doit = nl80211_leave_ocb, |
| 13609 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13610 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 13611 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13612 | NL80211_FLAG_NEED_RTNL, |
| 13613 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 13614 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 13615 | { |
| 13616 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 13617 | .doit = nl80211_get_wowlan, |
| 13618 | .policy = nl80211_policy, |
| 13619 | /* can be retrieved by unprivileged users */ |
| 13620 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13621 | NL80211_FLAG_NEED_RTNL, |
| 13622 | }, |
| 13623 | { |
| 13624 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 13625 | .doit = nl80211_set_wowlan, |
| 13626 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13627 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 13628 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13629 | NL80211_FLAG_NEED_RTNL, |
| 13630 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 13631 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13632 | { |
| 13633 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 13634 | .doit = nl80211_set_rekey_data, |
| 13635 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13636 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13637 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13638 | NL80211_FLAG_NEED_RTNL | |
| 13639 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13640 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13641 | { |
| 13642 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 13643 | .doit = nl80211_tdls_mgmt, |
| 13644 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13645 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13646 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13647 | NL80211_FLAG_NEED_RTNL, |
| 13648 | }, |
| 13649 | { |
| 13650 | .cmd = NL80211_CMD_TDLS_OPER, |
| 13651 | .doit = nl80211_tdls_oper, |
| 13652 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13653 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13654 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13655 | NL80211_FLAG_NEED_RTNL, |
| 13656 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13657 | { |
| 13658 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 13659 | .doit = nl80211_register_unexpected_frame, |
| 13660 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13661 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13662 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13663 | NL80211_FLAG_NEED_RTNL, |
| 13664 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13665 | { |
| 13666 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 13667 | .doit = nl80211_probe_client, |
| 13668 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13669 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13670 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13671 | NL80211_FLAG_NEED_RTNL, |
| 13672 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13673 | { |
| 13674 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 13675 | .doit = nl80211_register_beacons, |
| 13676 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13677 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13678 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13679 | NL80211_FLAG_NEED_RTNL, |
| 13680 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 13681 | { |
| 13682 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 13683 | .doit = nl80211_set_noack_map, |
| 13684 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13685 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 13686 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13687 | NL80211_FLAG_NEED_RTNL, |
| 13688 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13689 | { |
| 13690 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 13691 | .doit = nl80211_start_p2p_device, |
| 13692 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13693 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13694 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13695 | NL80211_FLAG_NEED_RTNL, |
| 13696 | }, |
| 13697 | { |
| 13698 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 13699 | .doit = nl80211_stop_p2p_device, |
| 13700 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13701 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13702 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13703 | NL80211_FLAG_NEED_RTNL, |
| 13704 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13705 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13706 | .cmd = NL80211_CMD_START_NAN, |
| 13707 | .doit = nl80211_start_nan, |
| 13708 | .policy = nl80211_policy, |
| 13709 | .flags = GENL_ADMIN_PERM, |
| 13710 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13711 | NL80211_FLAG_NEED_RTNL, |
| 13712 | }, |
| 13713 | { |
| 13714 | .cmd = NL80211_CMD_STOP_NAN, |
| 13715 | .doit = nl80211_stop_nan, |
| 13716 | .policy = nl80211_policy, |
| 13717 | .flags = GENL_ADMIN_PERM, |
| 13718 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13719 | NL80211_FLAG_NEED_RTNL, |
| 13720 | }, |
| 13721 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13722 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
| 13723 | .doit = nl80211_nan_add_func, |
| 13724 | .policy = nl80211_policy, |
| 13725 | .flags = GENL_ADMIN_PERM, |
| 13726 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13727 | NL80211_FLAG_NEED_RTNL, |
| 13728 | }, |
| 13729 | { |
| 13730 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
| 13731 | .doit = nl80211_nan_del_func, |
| 13732 | .policy = nl80211_policy, |
| 13733 | .flags = GENL_ADMIN_PERM, |
| 13734 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13735 | NL80211_FLAG_NEED_RTNL, |
| 13736 | }, |
| 13737 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13738 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
| 13739 | .doit = nl80211_nan_change_config, |
| 13740 | .policy = nl80211_policy, |
| 13741 | .flags = GENL_ADMIN_PERM, |
| 13742 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13743 | NL80211_FLAG_NEED_RTNL, |
| 13744 | }, |
| 13745 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13746 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 13747 | .doit = nl80211_set_mcast_rate, |
| 13748 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13749 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13750 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13751 | NL80211_FLAG_NEED_RTNL, |
| 13752 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 13753 | { |
| 13754 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 13755 | .doit = nl80211_set_mac_acl, |
| 13756 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13757 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 13758 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13759 | NL80211_FLAG_NEED_RTNL, |
| 13760 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13761 | { |
| 13762 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 13763 | .doit = nl80211_start_radar_detection, |
| 13764 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13765 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13766 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13767 | NL80211_FLAG_NEED_RTNL, |
| 13768 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 13769 | { |
| 13770 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 13771 | .doit = nl80211_get_protocol_features, |
| 13772 | .policy = nl80211_policy, |
| 13773 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13774 | { |
| 13775 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 13776 | .doit = nl80211_update_ft_ies, |
| 13777 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13778 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13779 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13780 | NL80211_FLAG_NEED_RTNL, |
| 13781 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13782 | { |
| 13783 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 13784 | .doit = nl80211_crit_protocol_start, |
| 13785 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13786 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13787 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13788 | NL80211_FLAG_NEED_RTNL, |
| 13789 | }, |
| 13790 | { |
| 13791 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 13792 | .doit = nl80211_crit_protocol_stop, |
| 13793 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13794 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13795 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13796 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13797 | }, |
| 13798 | { |
| 13799 | .cmd = NL80211_CMD_GET_COALESCE, |
| 13800 | .doit = nl80211_get_coalesce, |
| 13801 | .policy = nl80211_policy, |
| 13802 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13803 | NL80211_FLAG_NEED_RTNL, |
| 13804 | }, |
| 13805 | { |
| 13806 | .cmd = NL80211_CMD_SET_COALESCE, |
| 13807 | .doit = nl80211_set_coalesce, |
| 13808 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13809 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13810 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13811 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 13812 | }, |
| 13813 | { |
| 13814 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 13815 | .doit = nl80211_channel_switch, |
| 13816 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13817 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 13818 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13819 | NL80211_FLAG_NEED_RTNL, |
| 13820 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13821 | { |
| 13822 | .cmd = NL80211_CMD_VENDOR, |
| 13823 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13824 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13825 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13826 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13827 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13828 | NL80211_FLAG_NEED_RTNL, |
| 13829 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13830 | { |
| 13831 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 13832 | .doit = nl80211_set_qos_map, |
| 13833 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13834 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13835 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13836 | NL80211_FLAG_NEED_RTNL, |
| 13837 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13838 | { |
| 13839 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 13840 | .doit = nl80211_add_tx_ts, |
| 13841 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13842 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13843 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13844 | NL80211_FLAG_NEED_RTNL, |
| 13845 | }, |
| 13846 | { |
| 13847 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 13848 | .doit = nl80211_del_tx_ts, |
| 13849 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13850 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13851 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13852 | NL80211_FLAG_NEED_RTNL, |
| 13853 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13854 | { |
| 13855 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 13856 | .doit = nl80211_tdls_channel_switch, |
| 13857 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13858 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13859 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13860 | NL80211_FLAG_NEED_RTNL, |
| 13861 | }, |
| 13862 | { |
| 13863 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 13864 | .doit = nl80211_tdls_cancel_channel_switch, |
| 13865 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13866 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13867 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13868 | NL80211_FLAG_NEED_RTNL, |
| 13869 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13870 | { |
| 13871 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
| 13872 | .doit = nl80211_set_multicast_to_unicast, |
| 13873 | .policy = nl80211_policy, |
| 13874 | .flags = GENL_UNS_ADMIN_PERM, |
| 13875 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13876 | NL80211_FLAG_NEED_RTNL, |
| 13877 | }, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 13878 | { |
| 13879 | .cmd = NL80211_CMD_SET_PMK, |
| 13880 | .doit = nl80211_set_pmk, |
| 13881 | .policy = nl80211_policy, |
| 13882 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13883 | NL80211_FLAG_NEED_RTNL, |
| 13884 | }, |
| 13885 | { |
| 13886 | .cmd = NL80211_CMD_DEL_PMK, |
| 13887 | .doit = nl80211_del_pmk, |
| 13888 | .policy = nl80211_policy, |
| 13889 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13890 | NL80211_FLAG_NEED_RTNL, |
| 13891 | }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13892 | { |
| 13893 | .cmd = NL80211_CMD_EXTERNAL_AUTH, |
| 13894 | .doit = nl80211_external_auth, |
| 13895 | .policy = nl80211_policy, |
| 13896 | .flags = GENL_ADMIN_PERM, |
| 13897 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13898 | NL80211_FLAG_NEED_RTNL, |
| 13899 | }, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 13900 | { |
| 13901 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, |
| 13902 | .doit = nl80211_tx_control_port, |
| 13903 | .policy = nl80211_policy, |
| 13904 | .flags = GENL_UNS_ADMIN_PERM, |
| 13905 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13906 | NL80211_FLAG_NEED_RTNL, |
| 13907 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13908 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13909 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 13910 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 13911 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 13912 | .hdrsize = 0, /* no private header */ |
| 13913 | .version = 1, /* no particular meaning now */ |
| 13914 | .maxattr = NL80211_ATTR_MAX, |
| 13915 | .netnsok = true, |
| 13916 | .pre_doit = nl80211_pre_doit, |
| 13917 | .post_doit = nl80211_post_doit, |
| 13918 | .module = THIS_MODULE, |
| 13919 | .ops = nl80211_ops, |
| 13920 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| 13921 | .mcgrps = nl80211_mcgrps, |
| 13922 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
| 13923 | }; |
| 13924 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13925 | /* notification functions */ |
| 13926 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13927 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 13928 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13929 | { |
| 13930 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 13931 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13932 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13933 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 13934 | cmd != NL80211_CMD_DEL_WIPHY); |
| 13935 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13936 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13937 | if (!msg) |
| 13938 | return; |
| 13939 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13940 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13941 | nlmsg_free(msg); |
| 13942 | return; |
| 13943 | } |
| 13944 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13945 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13946 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13947 | } |
| 13948 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 13949 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 13950 | struct wireless_dev *wdev, |
| 13951 | enum nl80211_commands cmd) |
| 13952 | { |
| 13953 | struct sk_buff *msg; |
| 13954 | |
| 13955 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 13956 | cmd != NL80211_CMD_DEL_INTERFACE); |
| 13957 | |
| 13958 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13959 | if (!msg) |
| 13960 | return; |
| 13961 | |
| 13962 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, |
| 13963 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { |
| 13964 | nlmsg_free(msg); |
| 13965 | return; |
| 13966 | } |
| 13967 | |
| 13968 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 13969 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 13970 | } |
| 13971 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13972 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 13973 | struct cfg80211_registered_device *rdev) |
| 13974 | { |
| 13975 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 13976 | struct nlattr *nest; |
| 13977 | int i; |
| 13978 | |
| 13979 | if (WARN_ON(!req)) |
| 13980 | return 0; |
| 13981 | |
| 13982 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 13983 | if (!nest) |
| 13984 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13985 | for (i = 0; i < req->n_ssids; i++) { |
| 13986 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 13987 | goto nla_put_failure; |
| 13988 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13989 | nla_nest_end(msg, nest); |
| 13990 | |
| 13991 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 13992 | if (!nest) |
| 13993 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13994 | for (i = 0; i < req->n_channels; i++) { |
| 13995 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 13996 | goto nla_put_failure; |
| 13997 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13998 | nla_nest_end(msg, nest); |
| 13999 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14000 | if (req->ie && |
| 14001 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 14002 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 14003 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14004 | if (req->flags && |
| 14005 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 14006 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 14007 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 14008 | if (req->info.scan_start_tsf && |
| 14009 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 14010 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 14011 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 14012 | req->info.tsf_bssid))) |
| 14013 | goto nla_put_failure; |
| 14014 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 14015 | return 0; |
| 14016 | nla_put_failure: |
| 14017 | return -ENOBUFS; |
| 14018 | } |
| 14019 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 14020 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14021 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 14022 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14023 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14024 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14025 | { |
| 14026 | void *hdr; |
| 14027 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14028 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14029 | if (!hdr) |
| 14030 | return -1; |
| 14031 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14032 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 14033 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14034 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14035 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14036 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14037 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14038 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 14039 | /* ignore errors and send incomplete event anyway */ |
| 14040 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14041 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 14042 | genlmsg_end(msg, hdr); |
| 14043 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14044 | |
| 14045 | nla_put_failure: |
| 14046 | genlmsg_cancel(msg, hdr); |
| 14047 | return -EMSGSIZE; |
| 14048 | } |
| 14049 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14050 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 14051 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14052 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14053 | { |
| 14054 | void *hdr; |
| 14055 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14056 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14057 | if (!hdr) |
| 14058 | return -1; |
| 14059 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14060 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 14061 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 14062 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 14063 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 14064 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14065 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14066 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 14067 | genlmsg_end(msg, hdr); |
| 14068 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14069 | |
| 14070 | nla_put_failure: |
| 14071 | genlmsg_cancel(msg, hdr); |
| 14072 | return -EMSGSIZE; |
| 14073 | } |
| 14074 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14075 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 14076 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14077 | { |
| 14078 | struct sk_buff *msg; |
| 14079 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14080 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14081 | if (!msg) |
| 14082 | return; |
| 14083 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 14084 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14085 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 14086 | nlmsg_free(msg); |
| 14087 | return; |
| 14088 | } |
| 14089 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14090 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14091 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 14092 | } |
| 14093 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 14094 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 14095 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14096 | { |
| 14097 | struct sk_buff *msg; |
| 14098 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 14099 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14100 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 14101 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14102 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 14103 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 14104 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 14105 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14106 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 14107 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14108 | } |
| 14109 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 14110 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14111 | } |
| 14112 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 14113 | /* send message created by nl80211_build_scan_msg() */ |
| 14114 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 14115 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14116 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14117 | if (!msg) |
| 14118 | return; |
| 14119 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14120 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14121 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14122 | } |
| 14123 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14124 | 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] | 14125 | { |
| 14126 | struct sk_buff *msg; |
| 14127 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14128 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14129 | if (!msg) |
| 14130 | return; |
| 14131 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14132 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14133 | nlmsg_free(msg); |
| 14134 | return; |
| 14135 | } |
| 14136 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 14137 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14138 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14139 | } |
| 14140 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 14141 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 14142 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14143 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14144 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14145 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 14146 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14147 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14148 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 14149 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 14150 | NL80211_REGDOM_TYPE_WORLD)) |
| 14151 | goto nla_put_failure; |
| 14152 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 14153 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 14154 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 14155 | goto nla_put_failure; |
| 14156 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 14157 | request->intersect) { |
| 14158 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 14159 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 14160 | goto nla_put_failure; |
| 14161 | } else { |
| 14162 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 14163 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 14164 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 14165 | request->alpha2)) |
| 14166 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14167 | } |
| 14168 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 14169 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 14170 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 14171 | |
| 14172 | if (wiphy && |
| 14173 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 14174 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 14175 | |
| 14176 | if (wiphy && |
| 14177 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 14178 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 14179 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 14180 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14181 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 14182 | return true; |
| 14183 | |
| 14184 | nla_put_failure: |
| 14185 | return false; |
| 14186 | } |
| 14187 | |
| 14188 | /* |
| 14189 | * This can happen on global regulatory changes or device specific settings |
| 14190 | * based on custom regulatory domains. |
| 14191 | */ |
| 14192 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 14193 | struct regulatory_request *request) |
| 14194 | { |
| 14195 | struct sk_buff *msg; |
| 14196 | void *hdr; |
| 14197 | |
| 14198 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14199 | if (!msg) |
| 14200 | return; |
| 14201 | |
| 14202 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 14203 | if (!hdr) { |
| 14204 | nlmsg_free(msg); |
| 14205 | return; |
| 14206 | } |
| 14207 | |
| 14208 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 14209 | goto nla_put_failure; |
| 14210 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14211 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14212 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 14213 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14214 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14215 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 14216 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14217 | |
| 14218 | return; |
| 14219 | |
| 14220 | nla_put_failure: |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 14221 | nlmsg_free(msg); |
| 14222 | } |
| 14223 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14224 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 14225 | struct net_device *netdev, |
| 14226 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14227 | enum nl80211_commands cmd, gfp_t gfp, |
| 14228 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14229 | { |
| 14230 | struct sk_buff *msg; |
| 14231 | void *hdr; |
| 14232 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14233 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14234 | if (!msg) |
| 14235 | return; |
| 14236 | |
| 14237 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 14238 | if (!hdr) { |
| 14239 | nlmsg_free(msg); |
| 14240 | return; |
| 14241 | } |
| 14242 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14243 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14244 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14245 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 14246 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14247 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14248 | if (uapsd_queues >= 0) { |
| 14249 | struct nlattr *nla_wmm = |
| 14250 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 14251 | if (!nla_wmm) |
| 14252 | goto nla_put_failure; |
| 14253 | |
| 14254 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 14255 | uapsd_queues)) |
| 14256 | goto nla_put_failure; |
| 14257 | |
| 14258 | nla_nest_end(msg, nla_wmm); |
| 14259 | } |
| 14260 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14261 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14262 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14263 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14264 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14265 | return; |
| 14266 | |
| 14267 | nla_put_failure: |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14268 | nlmsg_free(msg); |
| 14269 | } |
| 14270 | |
| 14271 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14272 | struct net_device *netdev, const u8 *buf, |
| 14273 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14274 | { |
| 14275 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14276 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14277 | } |
| 14278 | |
| 14279 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 14280 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14281 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14282 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14283 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14284 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14285 | } |
| 14286 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 14287 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14288 | struct net_device *netdev, const u8 *buf, |
| 14289 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14290 | { |
| 14291 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14292 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14293 | } |
| 14294 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 14295 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 14296 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14297 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14298 | { |
| 14299 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14300 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14301 | } |
| 14302 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 14303 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 14304 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 14305 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14306 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14307 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14308 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 14309 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 14310 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 14311 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 14312 | if (WARN_ON(len < 2)) |
| 14313 | return; |
| 14314 | |
| 14315 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 14316 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 14317 | else |
| 14318 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 14319 | |
| 14320 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 14321 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 14322 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 14323 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 14324 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 14325 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 14326 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14327 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14328 | { |
| 14329 | struct sk_buff *msg; |
| 14330 | void *hdr; |
| 14331 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14332 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14333 | if (!msg) |
| 14334 | return; |
| 14335 | |
| 14336 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 14337 | if (!hdr) { |
| 14338 | nlmsg_free(msg); |
| 14339 | return; |
| 14340 | } |
| 14341 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14342 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14343 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14344 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 14345 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 14346 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14347 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14348 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14349 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14350 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14351 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14352 | return; |
| 14353 | |
| 14354 | nla_put_failure: |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14355 | nlmsg_free(msg); |
| 14356 | } |
| 14357 | |
| 14358 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14359 | struct net_device *netdev, const u8 *addr, |
| 14360 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14361 | { |
| 14362 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14363 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14364 | } |
| 14365 | |
| 14366 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14367 | struct net_device *netdev, const u8 *addr, |
| 14368 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14369 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14370 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 14371 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 14372 | } |
| 14373 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14374 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 14375 | struct net_device *netdev, |
| 14376 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 14377 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14378 | { |
| 14379 | struct sk_buff *msg; |
| 14380 | void *hdr; |
| 14381 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 14382 | 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] | 14383 | cr->fils.kek_len + cr->fils.pmk_len + |
| 14384 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14385 | if (!msg) |
| 14386 | return; |
| 14387 | |
| 14388 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 14389 | if (!hdr) { |
| 14390 | nlmsg_free(msg); |
| 14391 | return; |
| 14392 | } |
| 14393 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14394 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14395 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 14396 | (cr->bssid && |
| 14397 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 14398 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 14399 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 14400 | cr->status) || |
| 14401 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 14402 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 14403 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 14404 | cr->timeout_reason))) || |
| 14405 | (cr->req_ie && |
| 14406 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 14407 | (cr->resp_ie && |
| 14408 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 14409 | cr->resp_ie)) || |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 14410 | (cr->fils.update_erp_next_seq_num && |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 14411 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 14412 | cr->fils.erp_next_seq_num)) || |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 14413 | (cr->status == WLAN_STATUS_SUCCESS && |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 14414 | ((cr->fils.kek && |
| 14415 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, |
| 14416 | cr->fils.kek)) || |
| 14417 | (cr->fils.pmk && |
| 14418 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || |
| 14419 | (cr->fils.pmkid && |
| 14420 | 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] | 14421 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14422 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14423 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14424 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14425 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14426 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14427 | return; |
| 14428 | |
| 14429 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14430 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14431 | } |
| 14432 | |
| 14433 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 14434 | struct net_device *netdev, |
| 14435 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14436 | { |
| 14437 | struct sk_buff *msg; |
| 14438 | void *hdr; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 14439 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14440 | |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 14441 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + |
| 14442 | info->fils.kek_len + info->fils.pmk_len + |
| 14443 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14444 | if (!msg) |
| 14445 | return; |
| 14446 | |
| 14447 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 14448 | if (!hdr) { |
| 14449 | nlmsg_free(msg); |
| 14450 | return; |
| 14451 | } |
| 14452 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14453 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14454 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14455 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 14456 | (info->req_ie && |
| 14457 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 14458 | info->req_ie)) || |
| 14459 | (info->resp_ie && |
| 14460 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 14461 | info->resp_ie)) || |
| 14462 | (info->fils.update_erp_next_seq_num && |
| 14463 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 14464 | info->fils.erp_next_seq_num)) || |
| 14465 | (info->fils.kek && |
| 14466 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, |
| 14467 | info->fils.kek)) || |
| 14468 | (info->fils.pmk && |
| 14469 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || |
| 14470 | (info->fils.pmkid && |
| 14471 | 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] | 14472 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14473 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14474 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14475 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14476 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14477 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14478 | return; |
| 14479 | |
| 14480 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14481 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14482 | } |
| 14483 | |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 14484 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, |
| 14485 | struct net_device *netdev, const u8 *bssid) |
| 14486 | { |
| 14487 | struct sk_buff *msg; |
| 14488 | void *hdr; |
| 14489 | |
| 14490 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14491 | if (!msg) |
| 14492 | return; |
| 14493 | |
| 14494 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); |
| 14495 | if (!hdr) { |
| 14496 | nlmsg_free(msg); |
| 14497 | return; |
| 14498 | } |
| 14499 | |
| 14500 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 14501 | goto nla_put_failure; |
| 14502 | |
| 14503 | genlmsg_end(msg, hdr); |
| 14504 | |
| 14505 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 14506 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 14507 | return; |
| 14508 | |
| 14509 | nla_put_failure: |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 14510 | nlmsg_free(msg); |
| 14511 | } |
| 14512 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14513 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 14514 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 14515 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14516 | { |
| 14517 | struct sk_buff *msg; |
| 14518 | void *hdr; |
| 14519 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14520 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14521 | if (!msg) |
| 14522 | return; |
| 14523 | |
| 14524 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 14525 | if (!hdr) { |
| 14526 | nlmsg_free(msg); |
| 14527 | return; |
| 14528 | } |
| 14529 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14530 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14531 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
David Spinadel | 86b6c46 | 2017-12-18 12:14:05 +0200 | [diff] [blame] | 14532 | (reason && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14533 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 14534 | (from_ap && |
| 14535 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 14536 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 14537 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14538 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14539 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14540 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14541 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14542 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14543 | return; |
| 14544 | |
| 14545 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14546 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14547 | } |
| 14548 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14549 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 14550 | struct net_device *netdev, const u8 *bssid, |
| 14551 | gfp_t gfp) |
| 14552 | { |
| 14553 | struct sk_buff *msg; |
| 14554 | void *hdr; |
| 14555 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 14556 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14557 | if (!msg) |
| 14558 | return; |
| 14559 | |
| 14560 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 14561 | if (!hdr) { |
| 14562 | nlmsg_free(msg); |
| 14563 | return; |
| 14564 | } |
| 14565 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14566 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14567 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14568 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 14569 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14570 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14571 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14572 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14573 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14574 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14575 | return; |
| 14576 | |
| 14577 | nla_put_failure: |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14578 | nlmsg_free(msg); |
| 14579 | } |
| 14580 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14581 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 14582 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14583 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14584 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14585 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14586 | struct sk_buff *msg; |
| 14587 | void *hdr; |
| 14588 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14589 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 14590 | return; |
| 14591 | |
| 14592 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 14593 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14594 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14595 | if (!msg) |
| 14596 | return; |
| 14597 | |
| 14598 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 14599 | if (!hdr) { |
| 14600 | nlmsg_free(msg); |
| 14601 | return; |
| 14602 | } |
| 14603 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14604 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14605 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14606 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14607 | (ie_len && ie && |
| 14608 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 14609 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14610 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14611 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14612 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14613 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14614 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14615 | return; |
| 14616 | |
| 14617 | nla_put_failure: |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14618 | nlmsg_free(msg); |
| 14619 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14620 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14621 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14622 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 14623 | struct net_device *netdev, const u8 *addr, |
| 14624 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14625 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14626 | { |
| 14627 | struct sk_buff *msg; |
| 14628 | void *hdr; |
| 14629 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14630 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14631 | if (!msg) |
| 14632 | return; |
| 14633 | |
| 14634 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 14635 | if (!hdr) { |
| 14636 | nlmsg_free(msg); |
| 14637 | return; |
| 14638 | } |
| 14639 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14640 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14641 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14642 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 14643 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 14644 | (key_id != -1 && |
| 14645 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 14646 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 14647 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14648 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14649 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14650 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14651 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14652 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14653 | return; |
| 14654 | |
| 14655 | nla_put_failure: |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14656 | nlmsg_free(msg); |
| 14657 | } |
| 14658 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14659 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 14660 | struct ieee80211_channel *channel_before, |
| 14661 | struct ieee80211_channel *channel_after) |
| 14662 | { |
| 14663 | struct sk_buff *msg; |
| 14664 | void *hdr; |
| 14665 | struct nlattr *nl_freq; |
| 14666 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 14667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14668 | if (!msg) |
| 14669 | return; |
| 14670 | |
| 14671 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 14672 | if (!hdr) { |
| 14673 | nlmsg_free(msg); |
| 14674 | return; |
| 14675 | } |
| 14676 | |
| 14677 | /* |
| 14678 | * Since we are applying the beacon hint to a wiphy we know its |
| 14679 | * wiphy_idx is valid |
| 14680 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14681 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 14682 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14683 | |
| 14684 | /* Before */ |
| 14685 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 14686 | if (!nl_freq) |
| 14687 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 14688 | |
| 14689 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14690 | goto nla_put_failure; |
| 14691 | nla_nest_end(msg, nl_freq); |
| 14692 | |
| 14693 | /* After */ |
| 14694 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 14695 | if (!nl_freq) |
| 14696 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 14697 | |
| 14698 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14699 | goto nla_put_failure; |
| 14700 | nla_nest_end(msg, nl_freq); |
| 14701 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14702 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14703 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14704 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14705 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14706 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14707 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14708 | |
| 14709 | return; |
| 14710 | |
| 14711 | nla_put_failure: |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14712 | nlmsg_free(msg); |
| 14713 | } |
| 14714 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14715 | static void nl80211_send_remain_on_chan_event( |
| 14716 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14717 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14718 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14719 | unsigned int duration, gfp_t gfp) |
| 14720 | { |
| 14721 | struct sk_buff *msg; |
| 14722 | void *hdr; |
| 14723 | |
| 14724 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14725 | if (!msg) |
| 14726 | return; |
| 14727 | |
| 14728 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 14729 | if (!hdr) { |
| 14730 | nlmsg_free(msg); |
| 14731 | return; |
| 14732 | } |
| 14733 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14734 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14735 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14736 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14737 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14738 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14739 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14740 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 14741 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14742 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14743 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14744 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14745 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14746 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 14747 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 14748 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14749 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14750 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14751 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14752 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14753 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14754 | return; |
| 14755 | |
| 14756 | nla_put_failure: |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14757 | nlmsg_free(msg); |
| 14758 | } |
| 14759 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14760 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 14761 | struct ieee80211_channel *chan, |
| 14762 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14763 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14764 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14765 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14766 | |
| 14767 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14768 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14769 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14770 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14771 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14772 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14773 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14774 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 14775 | struct ieee80211_channel *chan, |
| 14776 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14777 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14778 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14779 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14780 | |
| 14781 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14782 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14783 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14784 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14785 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14786 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14787 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 14788 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14789 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14790 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14791 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14792 | struct sk_buff *msg; |
| 14793 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14794 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 14795 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14796 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14797 | if (!msg) |
| 14798 | return; |
| 14799 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14800 | 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] | 14801 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14802 | nlmsg_free(msg); |
| 14803 | return; |
| 14804 | } |
| 14805 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14806 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14807 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14808 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14809 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14810 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14811 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 14812 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14813 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14814 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14815 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14816 | struct sk_buff *msg; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 14817 | struct station_info empty_sinfo = {}; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14818 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 14819 | if (!sinfo) |
| 14820 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14821 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14822 | trace_cfg80211_del_sta(dev, mac_addr); |
| 14823 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14824 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 14825 | if (!msg) { |
| 14826 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 14827 | return; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 14828 | } |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14829 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14830 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 14831 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14832 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 14833 | return; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14834 | } |
| 14835 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14836 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14837 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14838 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14839 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14840 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14841 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 14842 | enum nl80211_connect_failed_reason reason, |
| 14843 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14844 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14845 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14846 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14847 | struct sk_buff *msg; |
| 14848 | void *hdr; |
| 14849 | |
| 14850 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 14851 | if (!msg) |
| 14852 | return; |
| 14853 | |
| 14854 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 14855 | if (!hdr) { |
| 14856 | nlmsg_free(msg); |
| 14857 | return; |
| 14858 | } |
| 14859 | |
| 14860 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14861 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 14862 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 14863 | goto nla_put_failure; |
| 14864 | |
| 14865 | genlmsg_end(msg, hdr); |
| 14866 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14867 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14868 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14869 | return; |
| 14870 | |
| 14871 | nla_put_failure: |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14872 | nlmsg_free(msg); |
| 14873 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14874 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14875 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14876 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 14877 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14878 | { |
| 14879 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14880 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14881 | struct sk_buff *msg; |
| 14882 | void *hdr; |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 14883 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14884 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14885 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14886 | return false; |
| 14887 | |
| 14888 | msg = nlmsg_new(100, gfp); |
| 14889 | if (!msg) |
| 14890 | return true; |
| 14891 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14892 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14893 | if (!hdr) { |
| 14894 | nlmsg_free(msg); |
| 14895 | return true; |
| 14896 | } |
| 14897 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14898 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14899 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14900 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 14901 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14902 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14903 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14904 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14905 | return true; |
| 14906 | |
| 14907 | nla_put_failure: |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14908 | nlmsg_free(msg); |
| 14909 | return true; |
| 14910 | } |
| 14911 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14912 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 14913 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14914 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14915 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14916 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14917 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14918 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 14919 | |
| 14920 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 14921 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 14922 | trace_cfg80211_return_bool(false); |
| 14923 | return false; |
| 14924 | } |
| 14925 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 14926 | addr, gfp); |
| 14927 | trace_cfg80211_return_bool(ret); |
| 14928 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14929 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14930 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 14931 | |
| 14932 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 14933 | const u8 *addr, gfp_t gfp) |
| 14934 | { |
| 14935 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14936 | bool ret; |
| 14937 | |
| 14938 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 14939 | |
| 14940 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 14941 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 14942 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 14943 | trace_cfg80211_return_bool(false); |
| 14944 | return false; |
| 14945 | } |
| 14946 | ret = __nl80211_unexpected_frame(dev, |
| 14947 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 14948 | addr, gfp); |
| 14949 | trace_cfg80211_return_bool(ret); |
| 14950 | return ret; |
| 14951 | } |
| 14952 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14953 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14954 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14955 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 14956 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14957 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14958 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14959 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14960 | struct sk_buff *msg; |
| 14961 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14962 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14963 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14964 | if (!msg) |
| 14965 | return -ENOMEM; |
| 14966 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14967 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14968 | if (!hdr) { |
| 14969 | nlmsg_free(msg); |
| 14970 | return -ENOMEM; |
| 14971 | } |
| 14972 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14973 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14974 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14975 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14976 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14977 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14978 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 14979 | (sig_dbm && |
| 14980 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14981 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 14982 | (flags && |
| 14983 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14984 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14985 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14986 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14987 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14988 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14989 | |
| 14990 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14991 | nlmsg_free(msg); |
| 14992 | return -ENOBUFS; |
| 14993 | } |
| 14994 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14995 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 14996 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14997 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14998 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14999 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15000 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15001 | struct sk_buff *msg; |
| 15002 | void *hdr; |
| 15003 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15004 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 15005 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 15006 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15007 | if (!msg) |
| 15008 | return; |
| 15009 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15010 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15011 | if (!hdr) { |
| 15012 | nlmsg_free(msg); |
| 15013 | return; |
| 15014 | } |
| 15015 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15016 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15017 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15018 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15019 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15020 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15021 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15022 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 15023 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15024 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 15025 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15026 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15027 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15028 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15029 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15030 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15031 | return; |
| 15032 | |
| 15033 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15034 | nlmsg_free(msg); |
| 15035 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15036 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15037 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 15038 | static int __nl80211_rx_control_port(struct net_device *dev, |
| 15039 | const u8 *buf, size_t len, |
| 15040 | const u8 *addr, u16 proto, |
| 15041 | bool unencrypted, gfp_t gfp) |
| 15042 | { |
| 15043 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15044 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 15045 | struct sk_buff *msg; |
| 15046 | void *hdr; |
| 15047 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); |
| 15048 | |
| 15049 | if (!nlportid) |
| 15050 | return -ENOENT; |
| 15051 | |
| 15052 | msg = nlmsg_new(100 + len, gfp); |
| 15053 | if (!msg) |
| 15054 | return -ENOMEM; |
| 15055 | |
| 15056 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 15057 | if (!hdr) { |
| 15058 | nlmsg_free(msg); |
| 15059 | return -ENOBUFS; |
| 15060 | } |
| 15061 | |
| 15062 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15063 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15064 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15065 | NL80211_ATTR_PAD) || |
| 15066 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 15067 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 15068 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 15069 | (unencrypted && nla_put_flag(msg, |
| 15070 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 15071 | goto nla_put_failure; |
| 15072 | |
| 15073 | genlmsg_end(msg, hdr); |
| 15074 | |
| 15075 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 15076 | |
| 15077 | nla_put_failure: |
| 15078 | nlmsg_free(msg); |
| 15079 | return -ENOBUFS; |
| 15080 | } |
| 15081 | |
| 15082 | bool cfg80211_rx_control_port(struct net_device *dev, |
| 15083 | const u8 *buf, size_t len, |
| 15084 | const u8 *addr, u16 proto, bool unencrypted) |
| 15085 | { |
| 15086 | int ret; |
| 15087 | |
| 15088 | trace_cfg80211_rx_control_port(dev, buf, len, addr, proto, unencrypted); |
| 15089 | ret = __nl80211_rx_control_port(dev, buf, len, addr, proto, |
| 15090 | unencrypted, GFP_ATOMIC); |
| 15091 | trace_cfg80211_return_bool(ret == 0); |
| 15092 | return ret == 0; |
| 15093 | } |
| 15094 | EXPORT_SYMBOL(cfg80211_rx_control_port); |
| 15095 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15096 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 15097 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15098 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15099 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15100 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 15101 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15102 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15103 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15104 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15105 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15106 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15107 | cb = (void **)msg->cb; |
| 15108 | |
| 15109 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 15110 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15111 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15112 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15113 | } |
| 15114 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15115 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15116 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15117 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15118 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15119 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15120 | goto nla_put_failure; |
| 15121 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15122 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 15123 | if (!cb[1]) |
| 15124 | goto nla_put_failure; |
| 15125 | |
| 15126 | cb[2] = rdev; |
| 15127 | |
| 15128 | return msg; |
| 15129 | nla_put_failure: |
| 15130 | nlmsg_free(msg); |
| 15131 | return NULL; |
| 15132 | } |
| 15133 | |
| 15134 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 15135 | { |
| 15136 | void **cb = (void **)msg->cb; |
| 15137 | struct cfg80211_registered_device *rdev = cb[2]; |
| 15138 | |
| 15139 | nla_nest_end(msg, cb[1]); |
| 15140 | genlmsg_end(msg, cb[0]); |
| 15141 | |
| 15142 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 15143 | |
| 15144 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15145 | NL80211_MCGRP_MLME, gfp); |
| 15146 | } |
| 15147 | |
| 15148 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 15149 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 15150 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15151 | { |
| 15152 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 15153 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15154 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15155 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 15156 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15157 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 15158 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 15159 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 15160 | return; |
| 15161 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 15162 | if (wdev->cqm_config) { |
| 15163 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 15164 | |
| 15165 | cfg80211_cqm_rssi_update(rdev, dev); |
| 15166 | |
| 15167 | if (rssi_level == 0) |
| 15168 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 15169 | } |
| 15170 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15171 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 15172 | if (!msg) |
| 15173 | return; |
| 15174 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15175 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 15176 | rssi_event)) |
| 15177 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15178 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 15179 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 15180 | rssi_level)) |
| 15181 | goto nla_put_failure; |
| 15182 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15183 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15184 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15185 | return; |
| 15186 | |
| 15187 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15188 | nlmsg_free(msg); |
| 15189 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15190 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15191 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 15192 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 15193 | const u8 *peer, u32 num_packets, |
| 15194 | u32 rate, u32 intvl, gfp_t gfp) |
| 15195 | { |
| 15196 | struct sk_buff *msg; |
| 15197 | |
| 15198 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 15199 | if (!msg) |
| 15200 | return; |
| 15201 | |
| 15202 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 15203 | goto nla_put_failure; |
| 15204 | |
| 15205 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 15206 | goto nla_put_failure; |
| 15207 | |
| 15208 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 15209 | goto nla_put_failure; |
| 15210 | |
| 15211 | cfg80211_send_cqm(msg, gfp); |
| 15212 | return; |
| 15213 | |
| 15214 | nla_put_failure: |
| 15215 | nlmsg_free(msg); |
| 15216 | } |
| 15217 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 15218 | |
| 15219 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 15220 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 15221 | { |
| 15222 | struct sk_buff *msg; |
| 15223 | |
| 15224 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 15225 | |
| 15226 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 15227 | if (!msg) |
| 15228 | return; |
| 15229 | |
| 15230 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 15231 | goto nla_put_failure; |
| 15232 | |
| 15233 | cfg80211_send_cqm(msg, gfp); |
| 15234 | return; |
| 15235 | |
| 15236 | nla_put_failure: |
| 15237 | nlmsg_free(msg); |
| 15238 | } |
| 15239 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 15240 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 15241 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 15242 | { |
| 15243 | struct sk_buff *msg; |
| 15244 | |
| 15245 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 15246 | if (!msg) |
| 15247 | return; |
| 15248 | |
| 15249 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 15250 | goto nla_put_failure; |
| 15251 | |
| 15252 | cfg80211_send_cqm(msg, gfp); |
| 15253 | return; |
| 15254 | |
| 15255 | nla_put_failure: |
| 15256 | nlmsg_free(msg); |
| 15257 | } |
| 15258 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 15259 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15260 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 15261 | struct net_device *netdev, const u8 *bssid, |
| 15262 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15263 | { |
| 15264 | struct sk_buff *msg; |
| 15265 | struct nlattr *rekey_attr; |
| 15266 | void *hdr; |
| 15267 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15268 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15269 | if (!msg) |
| 15270 | return; |
| 15271 | |
| 15272 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 15273 | if (!hdr) { |
| 15274 | nlmsg_free(msg); |
| 15275 | return; |
| 15276 | } |
| 15277 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15278 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15279 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15280 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 15281 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15282 | |
| 15283 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 15284 | if (!rekey_attr) |
| 15285 | goto nla_put_failure; |
| 15286 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15287 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 15288 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 15289 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15290 | |
| 15291 | nla_nest_end(msg, rekey_attr); |
| 15292 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15293 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15294 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15295 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15296 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15297 | return; |
| 15298 | |
| 15299 | nla_put_failure: |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15300 | nlmsg_free(msg); |
| 15301 | } |
| 15302 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15303 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 15304 | const u8 *replay_ctr, gfp_t gfp) |
| 15305 | { |
| 15306 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15307 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15308 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15309 | |
| 15310 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 15311 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 15312 | } |
| 15313 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 15314 | |
| 15315 | static void |
| 15316 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 15317 | struct net_device *netdev, int index, |
| 15318 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15319 | { |
| 15320 | struct sk_buff *msg; |
| 15321 | struct nlattr *attr; |
| 15322 | void *hdr; |
| 15323 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15324 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15325 | if (!msg) |
| 15326 | return; |
| 15327 | |
| 15328 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 15329 | if (!hdr) { |
| 15330 | nlmsg_free(msg); |
| 15331 | return; |
| 15332 | } |
| 15333 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15334 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15335 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 15336 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15337 | |
| 15338 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 15339 | if (!attr) |
| 15340 | goto nla_put_failure; |
| 15341 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15342 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 15343 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 15344 | (preauth && |
| 15345 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 15346 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15347 | |
| 15348 | nla_nest_end(msg, attr); |
| 15349 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15350 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15351 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15352 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15353 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15354 | return; |
| 15355 | |
| 15356 | nla_put_failure: |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 15357 | nlmsg_free(msg); |
| 15358 | } |
| 15359 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15360 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 15361 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 15362 | { |
| 15363 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15364 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15365 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15366 | |
| 15367 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 15368 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 15369 | } |
| 15370 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 15371 | |
| 15372 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 15373 | struct net_device *netdev, |
| 15374 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 15375 | gfp_t gfp, |
| 15376 | enum nl80211_commands notif, |
| 15377 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15378 | { |
| 15379 | struct sk_buff *msg; |
| 15380 | void *hdr; |
| 15381 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15382 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15383 | if (!msg) |
| 15384 | return; |
| 15385 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 15386 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15387 | if (!hdr) { |
| 15388 | nlmsg_free(msg); |
| 15389 | return; |
| 15390 | } |
| 15391 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 15392 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 15393 | goto nla_put_failure; |
| 15394 | |
| 15395 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 15396 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15397 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 15398 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 15399 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 15400 | goto nla_put_failure; |
| 15401 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15402 | genlmsg_end(msg, hdr); |
| 15403 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15404 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15405 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15406 | return; |
| 15407 | |
| 15408 | nla_put_failure: |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 15409 | nlmsg_free(msg); |
| 15410 | } |
| 15411 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15412 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 15413 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 15414 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15415 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15416 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15417 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15418 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 15419 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15420 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 15421 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15422 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 15423 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 15424 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 15425 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 15426 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15427 | } |
| 15428 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 15429 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 15430 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 15431 | struct cfg80211_chan_def *chandef, |
| 15432 | u8 count) |
| 15433 | { |
| 15434 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15435 | struct wiphy *wiphy = wdev->wiphy; |
| 15436 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 15437 | |
| 15438 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 15439 | |
| 15440 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 15441 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 15442 | } |
| 15443 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 15444 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 15445 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15446 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 15447 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15448 | enum nl80211_radar_event event, |
| 15449 | struct net_device *netdev, gfp_t gfp) |
| 15450 | { |
| 15451 | struct sk_buff *msg; |
| 15452 | void *hdr; |
| 15453 | |
| 15454 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15455 | if (!msg) |
| 15456 | return; |
| 15457 | |
| 15458 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 15459 | if (!hdr) { |
| 15460 | nlmsg_free(msg); |
| 15461 | return; |
| 15462 | } |
| 15463 | |
| 15464 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 15465 | goto nla_put_failure; |
| 15466 | |
| 15467 | /* NOP and radar events don't need a netdev parameter */ |
| 15468 | if (netdev) { |
| 15469 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 15470 | |
| 15471 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15472 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15473 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15474 | goto nla_put_failure; |
| 15475 | } |
| 15476 | |
| 15477 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 15478 | goto nla_put_failure; |
| 15479 | |
| 15480 | if (nl80211_send_chandef(msg, chandef)) |
| 15481 | goto nla_put_failure; |
| 15482 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15483 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15484 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15485 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15486 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15487 | return; |
| 15488 | |
| 15489 | nla_put_failure: |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15490 | nlmsg_free(msg); |
| 15491 | } |
| 15492 | |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 15493 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, |
| 15494 | struct sta_opmode_info *sta_opmode, |
| 15495 | gfp_t gfp) |
| 15496 | { |
| 15497 | struct sk_buff *msg; |
| 15498 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15499 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 15500 | void *hdr; |
| 15501 | |
| 15502 | if (WARN_ON(!mac)) |
| 15503 | return; |
| 15504 | |
| 15505 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15506 | if (!msg) |
| 15507 | return; |
| 15508 | |
| 15509 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); |
| 15510 | if (!hdr) { |
| 15511 | nlmsg_free(msg); |
| 15512 | return; |
| 15513 | } |
| 15514 | |
| 15515 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 15516 | goto nla_put_failure; |
| 15517 | |
| 15518 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 15519 | goto nla_put_failure; |
| 15520 | |
| 15521 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
| 15522 | goto nla_put_failure; |
| 15523 | |
| 15524 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && |
| 15525 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) |
| 15526 | goto nla_put_failure; |
| 15527 | |
| 15528 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && |
| 15529 | nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) |
| 15530 | goto nla_put_failure; |
| 15531 | |
| 15532 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && |
| 15533 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) |
| 15534 | goto nla_put_failure; |
| 15535 | |
| 15536 | genlmsg_end(msg, hdr); |
| 15537 | |
| 15538 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15539 | NL80211_MCGRP_MLME, gfp); |
| 15540 | |
| 15541 | return; |
| 15542 | |
| 15543 | nla_put_failure: |
| 15544 | nlmsg_free(msg); |
| 15545 | } |
| 15546 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); |
| 15547 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15548 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 15549 | u64 cookie, bool acked, s32 ack_signal, |
| 15550 | bool is_valid_ack_signal, gfp_t gfp) |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15551 | { |
| 15552 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15553 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15554 | struct sk_buff *msg; |
| 15555 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15556 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 15557 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 15558 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15559 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 15560 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15561 | if (!msg) |
| 15562 | return; |
| 15563 | |
| 15564 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 15565 | if (!hdr) { |
| 15566 | nlmsg_free(msg); |
| 15567 | return; |
| 15568 | } |
| 15569 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15570 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15571 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15572 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15573 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 15574 | NL80211_ATTR_PAD) || |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 15575 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
| 15576 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, |
| 15577 | ack_signal))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15578 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15579 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15580 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15581 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15582 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15583 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15584 | return; |
| 15585 | |
| 15586 | nla_put_failure: |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15587 | nlmsg_free(msg); |
| 15588 | } |
| 15589 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 15590 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15591 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 15592 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15593 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15594 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15595 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15596 | struct sk_buff *msg; |
| 15597 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15598 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15599 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 15600 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 15601 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15602 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 15603 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 15604 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 15605 | if (!msg) { |
| 15606 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 15607 | return; |
| 15608 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15609 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15610 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 15611 | if (!hdr) |
| 15612 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15613 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15614 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15615 | (freq && |
| 15616 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 15617 | (sig_dbm && |
| 15618 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 15619 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 15620 | goto nla_put_failure; |
| 15621 | |
| 15622 | genlmsg_end(msg, hdr); |
| 15623 | |
| 15624 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15625 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15626 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15627 | return; |
| 15628 | |
| 15629 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15630 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15631 | nlmsg_free(msg); |
| 15632 | } |
| 15633 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 15634 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15635 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 15636 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 15637 | struct cfg80211_wowlan_wakeup *wakeup) |
| 15638 | { |
| 15639 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 15640 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 15641 | int i, j; |
| 15642 | |
| 15643 | nl_results = nla_nest_start( |
| 15644 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 15645 | if (!nl_results) |
| 15646 | return -EMSGSIZE; |
| 15647 | |
| 15648 | for (i = 0; i < nd->n_matches; i++) { |
| 15649 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 15650 | |
| 15651 | nl_match = nla_nest_start(msg, i); |
| 15652 | if (!nl_match) |
| 15653 | break; |
| 15654 | |
| 15655 | /* The SSID attribute is optional in nl80211, but for |
| 15656 | * simplicity reasons it's always present in the |
| 15657 | * cfg80211 structure. If a driver can't pass the |
| 15658 | * SSID, that needs to be changed. A zero length SSID |
| 15659 | * is still a valid SSID (wildcard), so it cannot be |
| 15660 | * used for this purpose. |
| 15661 | */ |
| 15662 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 15663 | match->ssid.ssid)) { |
| 15664 | nla_nest_cancel(msg, nl_match); |
| 15665 | goto out; |
| 15666 | } |
| 15667 | |
| 15668 | if (match->n_channels) { |
| 15669 | nl_freqs = nla_nest_start( |
| 15670 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 15671 | if (!nl_freqs) { |
| 15672 | nla_nest_cancel(msg, nl_match); |
| 15673 | goto out; |
| 15674 | } |
| 15675 | |
| 15676 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 15677 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 15678 | nla_nest_cancel(msg, nl_freqs); |
| 15679 | nla_nest_cancel(msg, nl_match); |
| 15680 | goto out; |
| 15681 | } |
| 15682 | } |
| 15683 | |
| 15684 | nla_nest_end(msg, nl_freqs); |
| 15685 | } |
| 15686 | |
| 15687 | nla_nest_end(msg, nl_match); |
| 15688 | } |
| 15689 | |
| 15690 | out: |
| 15691 | nla_nest_end(msg, nl_results); |
| 15692 | return 0; |
| 15693 | } |
| 15694 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15695 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 15696 | struct cfg80211_wowlan_wakeup *wakeup, |
| 15697 | gfp_t gfp) |
| 15698 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15699 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15700 | struct sk_buff *msg; |
| 15701 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15702 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15703 | |
| 15704 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 15705 | |
| 15706 | if (wakeup) |
| 15707 | size += wakeup->packet_present_len; |
| 15708 | |
| 15709 | msg = nlmsg_new(size, gfp); |
| 15710 | if (!msg) |
| 15711 | return; |
| 15712 | |
| 15713 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 15714 | if (!hdr) |
| 15715 | goto free_msg; |
| 15716 | |
| 15717 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15718 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15719 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15720 | goto free_msg; |
| 15721 | |
| 15722 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15723 | wdev->netdev->ifindex)) |
| 15724 | goto free_msg; |
| 15725 | |
| 15726 | if (wakeup) { |
| 15727 | struct nlattr *reasons; |
| 15728 | |
| 15729 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 15730 | if (!reasons) |
| 15731 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15732 | |
| 15733 | if (wakeup->disconnect && |
| 15734 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 15735 | goto free_msg; |
| 15736 | if (wakeup->magic_pkt && |
| 15737 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 15738 | goto free_msg; |
| 15739 | if (wakeup->gtk_rekey_failure && |
| 15740 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 15741 | goto free_msg; |
| 15742 | if (wakeup->eap_identity_req && |
| 15743 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 15744 | goto free_msg; |
| 15745 | if (wakeup->four_way_handshake && |
| 15746 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 15747 | goto free_msg; |
| 15748 | if (wakeup->rfkill_release && |
| 15749 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 15750 | goto free_msg; |
| 15751 | |
| 15752 | if (wakeup->pattern_idx >= 0 && |
| 15753 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 15754 | wakeup->pattern_idx)) |
| 15755 | goto free_msg; |
| 15756 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15757 | if (wakeup->tcp_match && |
| 15758 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 15759 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 15760 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15761 | if (wakeup->tcp_connlost && |
| 15762 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 15763 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 15764 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15765 | if (wakeup->tcp_nomoretokens && |
| 15766 | nla_put_flag(msg, |
| 15767 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 15768 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 15769 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15770 | if (wakeup->packet) { |
| 15771 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 15772 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 15773 | |
| 15774 | if (!wakeup->packet_80211) { |
| 15775 | pkt_attr = |
| 15776 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 15777 | len_attr = |
| 15778 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 15779 | } |
| 15780 | |
| 15781 | if (wakeup->packet_len && |
| 15782 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 15783 | goto free_msg; |
| 15784 | |
| 15785 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 15786 | wakeup->packet)) |
| 15787 | goto free_msg; |
| 15788 | } |
| 15789 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 15790 | if (wakeup->net_detect && |
| 15791 | cfg80211_net_detect_results(msg, wakeup)) |
| 15792 | goto free_msg; |
| 15793 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15794 | nla_nest_end(msg, reasons); |
| 15795 | } |
| 15796 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15797 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15798 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15799 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15800 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15801 | return; |
| 15802 | |
| 15803 | free_msg: |
| 15804 | nlmsg_free(msg); |
| 15805 | } |
| 15806 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 15807 | #endif |
| 15808 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15809 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 15810 | enum nl80211_tdls_operation oper, |
| 15811 | u16 reason_code, gfp_t gfp) |
| 15812 | { |
| 15813 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15814 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15815 | struct sk_buff *msg; |
| 15816 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15817 | |
| 15818 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 15819 | reason_code); |
| 15820 | |
| 15821 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15822 | if (!msg) |
| 15823 | return; |
| 15824 | |
| 15825 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 15826 | if (!hdr) { |
| 15827 | nlmsg_free(msg); |
| 15828 | return; |
| 15829 | } |
| 15830 | |
| 15831 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15832 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15833 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 15834 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 15835 | (reason_code > 0 && |
| 15836 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 15837 | goto nla_put_failure; |
| 15838 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15839 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15840 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15841 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15842 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15843 | return; |
| 15844 | |
| 15845 | nla_put_failure: |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15846 | nlmsg_free(msg); |
| 15847 | } |
| 15848 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 15849 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15850 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 15851 | unsigned long state, |
| 15852 | void *_notify) |
| 15853 | { |
| 15854 | struct netlink_notify *notify = _notify; |
| 15855 | struct cfg80211_registered_device *rdev; |
| 15856 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15857 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15858 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 15859 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15860 | return NOTIFY_DONE; |
| 15861 | |
| 15862 | rcu_read_lock(); |
| 15863 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15864 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15865 | struct cfg80211_sched_scan_request *sched_scan_req; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 15866 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15867 | list_for_each_entry_rcu(sched_scan_req, |
| 15868 | &rdev->sched_scan_req_list, |
| 15869 | list) { |
| 15870 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 15871 | sched_scan_req->nl_owner_dead = true; |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 15872 | schedule_work(&rdev->sched_scan_stop_wk); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15873 | } |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 15874 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 15875 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 15876 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15877 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15878 | |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 15879 | if (wdev->owner_nlportid == notify->portid) { |
| 15880 | wdev->nl_owner_dead = true; |
| 15881 | schedule_work(&rdev->destroy_work); |
| 15882 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 15883 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 15884 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 15885 | } |
| 15886 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15887 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 15888 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 15889 | list) { |
| 15890 | if (reg->nlportid == notify->portid) { |
| 15891 | list_del(®->list); |
| 15892 | kfree(reg); |
| 15893 | break; |
| 15894 | } |
| 15895 | } |
| 15896 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15897 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15898 | |
| 15899 | rcu_read_unlock(); |
| 15900 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 15901 | /* |
| 15902 | * It is possible that the user space process that is controlling the |
| 15903 | * indoor setting disappeared, so notify the regulatory core. |
| 15904 | */ |
| 15905 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 15906 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15907 | } |
| 15908 | |
| 15909 | static struct notifier_block nl80211_netlink_notifier = { |
| 15910 | .notifier_call = nl80211_netlink_notify, |
| 15911 | }; |
| 15912 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15913 | void cfg80211_ft_event(struct net_device *netdev, |
| 15914 | struct cfg80211_ft_event_params *ft_event) |
| 15915 | { |
| 15916 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15917 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15918 | struct sk_buff *msg; |
| 15919 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15920 | |
| 15921 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 15922 | |
| 15923 | if (!ft_event->target_ap) |
| 15924 | return; |
| 15925 | |
Dedy Lansky | 1039d08 | 2018-05-17 16:25:03 +0300 | [diff] [blame] | 15926 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
| 15927 | GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15928 | if (!msg) |
| 15929 | return; |
| 15930 | |
| 15931 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15932 | if (!hdr) |
| 15933 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15934 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15935 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15936 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15937 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 15938 | goto out; |
| 15939 | |
| 15940 | if (ft_event->ies && |
| 15941 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 15942 | goto out; |
| 15943 | if (ft_event->ric_ies && |
| 15944 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 15945 | ft_event->ric_ies)) |
| 15946 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15947 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15948 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15949 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15950 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15951 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15952 | return; |
| 15953 | out: |
| 15954 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15955 | } |
| 15956 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 15957 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15958 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 15959 | { |
| 15960 | struct cfg80211_registered_device *rdev; |
| 15961 | struct sk_buff *msg; |
| 15962 | void *hdr; |
| 15963 | u32 nlportid; |
| 15964 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15965 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15966 | if (!rdev->crit_proto_nlportid) |
| 15967 | return; |
| 15968 | |
| 15969 | nlportid = rdev->crit_proto_nlportid; |
| 15970 | rdev->crit_proto_nlportid = 0; |
| 15971 | |
| 15972 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15973 | if (!msg) |
| 15974 | return; |
| 15975 | |
| 15976 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 15977 | if (!hdr) |
| 15978 | goto nla_put_failure; |
| 15979 | |
| 15980 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15981 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15982 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15983 | goto nla_put_failure; |
| 15984 | |
| 15985 | genlmsg_end(msg, hdr); |
| 15986 | |
| 15987 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 15988 | return; |
| 15989 | |
| 15990 | nla_put_failure: |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15991 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15992 | } |
| 15993 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 15994 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15995 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 15996 | { |
| 15997 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15998 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15999 | struct sk_buff *msg; |
| 16000 | void *hdr; |
| 16001 | |
| 16002 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 16003 | if (!msg) |
| 16004 | return; |
| 16005 | |
| 16006 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 16007 | if (!hdr) |
| 16008 | goto out; |
| 16009 | |
| 16010 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16011 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16012 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16013 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 16014 | goto out; |
| 16015 | |
| 16016 | genlmsg_end(msg, hdr); |
| 16017 | |
| 16018 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 16019 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 16020 | return; |
| 16021 | out: |
| 16022 | nlmsg_free(msg); |
| 16023 | } |
| 16024 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 16025 | int cfg80211_external_auth_request(struct net_device *dev, |
| 16026 | struct cfg80211_external_auth_params *params, |
| 16027 | gfp_t gfp) |
| 16028 | { |
| 16029 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16030 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16031 | struct sk_buff *msg; |
| 16032 | void *hdr; |
| 16033 | |
| 16034 | if (!wdev->conn_owner_nlportid) |
| 16035 | return -EINVAL; |
| 16036 | |
| 16037 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16038 | if (!msg) |
| 16039 | return -ENOMEM; |
| 16040 | |
| 16041 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 16042 | if (!hdr) |
| 16043 | goto nla_put_failure; |
| 16044 | |
| 16045 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16046 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16047 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || |
| 16048 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, |
| 16049 | params->action) || |
| 16050 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || |
| 16051 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, |
| 16052 | params->ssid.ssid)) |
| 16053 | goto nla_put_failure; |
| 16054 | |
| 16055 | genlmsg_end(msg, hdr); |
| 16056 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 16057 | wdev->conn_owner_nlportid); |
| 16058 | return 0; |
| 16059 | |
| 16060 | nla_put_failure: |
| 16061 | nlmsg_free(msg); |
| 16062 | return -ENOBUFS; |
| 16063 | } |
| 16064 | EXPORT_SYMBOL(cfg80211_external_auth_request); |
| 16065 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16066 | /* initialisation/exit functions */ |
| 16067 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 16068 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16069 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 16070 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16071 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 16072 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16073 | if (err) |
| 16074 | return err; |
| 16075 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16076 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 16077 | if (err) |
| 16078 | goto err_out; |
| 16079 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16080 | return 0; |
| 16081 | err_out: |
| 16082 | genl_unregister_family(&nl80211_fam); |
| 16083 | return err; |
| 16084 | } |
| 16085 | |
| 16086 | void nl80211_exit(void) |
| 16087 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16088 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16089 | genl_unregister_family(&nl80211_fam); |
| 16090 | } |