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 |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/if.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13 | #include <linux/list.h> |
| 14 | #include <linux/if_ether.h> |
| 15 | #include <linux/ieee80211.h> |
| 16 | #include <linux/nl80211.h> |
| 17 | #include <linux/rtnetlink.h> |
| 18 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 19 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 20 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 21 | #include <net/genetlink.h> |
| 22 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 23 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 24 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | #include "core.h" |
| 26 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 27 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 28 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 29 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 30 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 31 | struct genl_info *info, |
| 32 | struct cfg80211_crypto_settings *settings, |
| 33 | int cipher_limit); |
| 34 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 35 | /* the netlink family */ |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 36 | static struct genl_family nl80211_fam; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 38 | /* multicast groups */ |
| 39 | enum nl80211_multicast_groups { |
| 40 | NL80211_MCGRP_CONFIG, |
| 41 | NL80211_MCGRP_SCAN, |
| 42 | NL80211_MCGRP_REGULATORY, |
| 43 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 44 | NL80211_MCGRP_VENDOR, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 45 | NL80211_MCGRP_NAN, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 46 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 47 | }; |
| 48 | |
| 49 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 50 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 51 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 52 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 53 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 54 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 55 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 56 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 57 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 58 | #endif |
| 59 | }; |
| 60 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 61 | /* returns ERR_PTR values */ |
| 62 | static struct wireless_dev * |
| 63 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 64 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 65 | struct cfg80211_registered_device *rdev; |
| 66 | struct wireless_dev *result = NULL; |
| 67 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 68 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 69 | u64 wdev_id; |
| 70 | int wiphy_idx = -1; |
| 71 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 73 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 74 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 75 | if (!have_ifidx && !have_wdev_id) |
| 76 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 77 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 78 | if (have_ifidx) |
| 79 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 80 | if (have_wdev_id) { |
| 81 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 82 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 83 | } |
| 84 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 85 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 86 | struct wireless_dev *wdev; |
| 87 | |
| 88 | if (wiphy_net(&rdev->wiphy) != netns) |
| 89 | continue; |
| 90 | |
| 91 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 92 | continue; |
| 93 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 94 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 95 | if (have_ifidx && wdev->netdev && |
| 96 | wdev->netdev->ifindex == ifidx) { |
| 97 | result = wdev; |
| 98 | break; |
| 99 | } |
| 100 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 101 | result = wdev; |
| 102 | break; |
| 103 | } |
| 104 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 105 | |
| 106 | if (result) |
| 107 | break; |
| 108 | } |
| 109 | |
| 110 | if (result) |
| 111 | return result; |
| 112 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 115 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 116 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 117 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 118 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 119 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 120 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 121 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 123 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 124 | !attrs[NL80211_ATTR_IFINDEX] && |
| 125 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 126 | return ERR_PTR(-EINVAL); |
| 127 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 128 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 129 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 130 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 131 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 132 | if (attrs[NL80211_ATTR_WDEV]) { |
| 133 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 134 | struct wireless_dev *wdev; |
| 135 | bool found = false; |
| 136 | |
| 137 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 138 | if (tmp) { |
| 139 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 140 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 141 | if (wdev->identifier != (u32)wdev_id) |
| 142 | continue; |
| 143 | found = true; |
| 144 | break; |
| 145 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 146 | |
| 147 | if (!found) |
| 148 | tmp = NULL; |
| 149 | |
| 150 | if (rdev && tmp != rdev) |
| 151 | return ERR_PTR(-EINVAL); |
| 152 | rdev = tmp; |
| 153 | } |
| 154 | } |
| 155 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 156 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 157 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 158 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 159 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 160 | if (netdev) { |
| 161 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 162 | tmp = wiphy_to_rdev( |
| 163 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 164 | else |
| 165 | tmp = NULL; |
| 166 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 167 | /* not wireless device -- return error */ |
| 168 | if (!tmp) |
| 169 | return ERR_PTR(-EINVAL); |
| 170 | |
| 171 | /* mismatch -- return error */ |
| 172 | if (rdev && tmp != rdev) |
| 173 | return ERR_PTR(-EINVAL); |
| 174 | |
| 175 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 176 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 179 | if (!rdev) |
| 180 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 181 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 182 | if (netns != wiphy_net(&rdev->wiphy)) |
| 183 | return ERR_PTR(-ENODEV); |
| 184 | |
| 185 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /* |
| 189 | * This function returns a pointer to the driver |
| 190 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 191 | * |
| 192 | * The result of this can be a PTR_ERR and hence must |
| 193 | * be checked with IS_ERR() for errors. |
| 194 | */ |
| 195 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 196 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 197 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 198 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 199 | } |
| 200 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 201 | /* policy for the attributes */ |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 202 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 203 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 204 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 205 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 206 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 207 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 208 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 209 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 210 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 211 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 212 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 213 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 214 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 215 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 216 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 217 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 219 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 220 | |
| 221 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 223 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 224 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 225 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 226 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 227 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 229 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 230 | .len = WLAN_MAX_KEY_LEN }, |
| 231 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 232 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 233 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 235 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 236 | |
| 237 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 238 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 239 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 240 | .len = IEEE80211_MAX_DATA_LEN }, |
| 241 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 242 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 243 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 244 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 245 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 246 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 247 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 249 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 250 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 251 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 252 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 253 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 254 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 255 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 256 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 257 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 258 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 259 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 260 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 261 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 262 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 263 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 264 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 265 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 266 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 267 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 269 | |
| 270 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 271 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 272 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 273 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 274 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 275 | |
| 276 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 277 | .len = IEEE80211_MAX_SSID_LEN }, |
| 278 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 279 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 280 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 281 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 282 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 283 | [NL80211_ATTR_STA_FLAGS2] = { |
| 284 | .len = sizeof(struct nl80211_sta_flag_update), |
| 285 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 286 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 287 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 288 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 289 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 290 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 291 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 293 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Srinivas Dasari | 9361df1 | 2017-07-07 01:43:39 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 295 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 296 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 298 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 299 | .len = IEEE80211_MAX_DATA_LEN }, |
| 300 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 301 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 302 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 303 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 304 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 306 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 308 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 309 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 310 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 311 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 314 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 315 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 318 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 319 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 320 | .len = IEEE80211_MAX_DATA_LEN }, |
| 321 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 322 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 323 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 325 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 326 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 327 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 328 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 329 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 330 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 331 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 332 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 333 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 334 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 335 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 336 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 337 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 338 | .len = NL80211_HT_CAPABILITY_LEN |
| 339 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 340 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 341 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 342 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 343 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 344 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 345 | [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 346 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 347 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 348 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 349 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Srinivas Dasari | 8feb69c | 2017-07-07 01:43:41 +0300 | [diff] [blame] | 350 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 351 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 352 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 353 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 354 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 355 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 356 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 357 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 358 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 359 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 360 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 361 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 362 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 363 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 364 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 365 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 366 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 367 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 368 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 369 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 370 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 372 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 373 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 374 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 375 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 376 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 377 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 379 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 380 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 381 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 382 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 383 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 384 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 385 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 386 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 387 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 388 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 389 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 390 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 391 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 392 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 393 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 394 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 395 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 396 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 397 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 398 | }, |
| 399 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 400 | [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 }, |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 401 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 402 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 403 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 404 | .len = FILS_MAX_KEK_LEN }, |
| 405 | [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 406 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 407 | [NL80211_ATTR_BSSID] = { .len = ETH_ALEN }, |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 408 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 409 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 410 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 411 | }, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 412 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 413 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 414 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 415 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 416 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 417 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 418 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 419 | .len = FILS_ERP_MAX_RRK_LEN }, |
| 420 | [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 }, |
| 421 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 422 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 423 | }; |
| 424 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 425 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 426 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 427 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 428 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 429 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 430 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 431 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 432 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 433 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 434 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 435 | }; |
| 436 | |
| 437 | /* policy for the key default flags */ |
| 438 | static const struct nla_policy |
| 439 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 440 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 441 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 442 | }; |
| 443 | |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 444 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 445 | /* policy for WoWLAN attributes */ |
| 446 | static const struct nla_policy |
| 447 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 448 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 449 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 450 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 451 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 452 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 453 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 454 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 455 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 456 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 457 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 458 | }; |
| 459 | |
| 460 | static const struct nla_policy |
| 461 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 462 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 463 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 464 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 465 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 466 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 467 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 468 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 469 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 470 | }, |
| 471 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 472 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 473 | }, |
| 474 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 475 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 476 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 477 | }; |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 478 | #endif /* CONFIG_PM */ |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 479 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 480 | /* policy for coalesce rule attributes */ |
| 481 | static const struct nla_policy |
| 482 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 483 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 484 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 485 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 486 | }; |
| 487 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 488 | /* policy for GTK rekey offload attributes */ |
| 489 | static const struct nla_policy |
| 490 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 491 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 492 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 493 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 494 | }; |
| 495 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 496 | static const struct nla_policy |
| 497 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 498 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 499 | .len = IEEE80211_MAX_SSID_LEN }, |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 500 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 501 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 502 | }; |
| 503 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 504 | static const struct nla_policy |
| 505 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 506 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 507 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 508 | }; |
| 509 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 510 | static const struct nla_policy |
| 511 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 512 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 513 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 514 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 515 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 516 | }, |
| 517 | }; |
| 518 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 519 | /* policy for NAN function attributes */ |
| 520 | static const struct nla_policy |
| 521 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
| 522 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, |
Srinivas Dasari | 0a27844 | 2017-07-07 01:43:40 +0300 | [diff] [blame] | 523 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 524 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 525 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 526 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 527 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 528 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 529 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
| 530 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN }, |
| 531 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 532 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 533 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 534 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 535 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 536 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 537 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 538 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 539 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 540 | }; |
| 541 | |
| 542 | /* policy for Service Response Filter attributes */ |
| 543 | static const struct nla_policy |
| 544 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 545 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 546 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 547 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 548 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 549 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 550 | }; |
| 551 | |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 552 | /* policy for packet pattern attributes */ |
| 553 | static const struct nla_policy |
| 554 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { |
| 555 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, |
| 556 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, |
| 557 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, |
| 558 | }; |
| 559 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 560 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 561 | struct netlink_callback *cb, |
| 562 | struct cfg80211_registered_device **rdev, |
| 563 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 564 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 565 | int err; |
| 566 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 567 | if (!cb->args[0]) { |
| 568 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 569 | genl_family_attrbuf(&nl80211_fam), |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 570 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 571 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 572 | return err; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 573 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 574 | *wdev = __cfg80211_wdev_from_attrs( |
| 575 | sock_net(skb->sk), |
| 576 | genl_family_attrbuf(&nl80211_fam)); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 577 | if (IS_ERR(*wdev)) |
| 578 | return PTR_ERR(*wdev); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 579 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 580 | /* 0 is the first index - add 1 to parse only once */ |
| 581 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 582 | cb->args[1] = (*wdev)->identifier; |
| 583 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 584 | /* subtract the 1 again here */ |
| 585 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 586 | struct wireless_dev *tmp; |
| 587 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 588 | if (!wiphy) |
| 589 | return -ENODEV; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 590 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 591 | *wdev = NULL; |
| 592 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 593 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 594 | if (tmp->identifier == cb->args[1]) { |
| 595 | *wdev = tmp; |
| 596 | break; |
| 597 | } |
| 598 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 599 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 600 | if (!*wdev) |
| 601 | return -ENODEV; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 602 | } |
| 603 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 604 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 605 | } |
| 606 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 607 | /* IE validation */ |
| 608 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 609 | { |
| 610 | const u8 *pos; |
| 611 | int len; |
| 612 | |
| 613 | if (!attr) |
| 614 | return true; |
| 615 | |
| 616 | pos = nla_data(attr); |
| 617 | len = nla_len(attr); |
| 618 | |
| 619 | while (len) { |
| 620 | u8 elemlen; |
| 621 | |
| 622 | if (len < 2) |
| 623 | return false; |
| 624 | len -= 2; |
| 625 | |
| 626 | elemlen = pos[1]; |
| 627 | if (elemlen > len) |
| 628 | return false; |
| 629 | |
| 630 | len -= elemlen; |
| 631 | pos += 2 + elemlen; |
| 632 | } |
| 633 | |
| 634 | return true; |
| 635 | } |
| 636 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 637 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 638 | 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] | 639 | int flags, u8 cmd) |
| 640 | { |
| 641 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 642 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 643 | } |
| 644 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 645 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 646 | struct ieee80211_channel *chan, |
| 647 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 648 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 649 | /* Some channels must be completely excluded from the |
| 650 | * list to protect old user-space tools from breaking |
| 651 | */ |
| 652 | if (!large && chan->flags & |
| 653 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 654 | return 0; |
| 655 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 656 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 657 | chan->center_freq)) |
| 658 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 659 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 660 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 661 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 662 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 663 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 664 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 665 | goto nla_put_failure; |
| 666 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 667 | goto nla_put_failure; |
| 668 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 669 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 670 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 671 | goto nla_put_failure; |
| 672 | if (large) { |
| 673 | u32 time; |
| 674 | |
| 675 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 676 | |
| 677 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 678 | chan->dfs_state)) |
| 679 | goto nla_put_failure; |
| 680 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 681 | time)) |
| 682 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 683 | if (nla_put_u32(msg, |
| 684 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 685 | chan->dfs_cac_ms)) |
| 686 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 687 | } |
| 688 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 689 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 690 | if (large) { |
| 691 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 692 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 693 | goto nla_put_failure; |
| 694 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 695 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 696 | goto nla_put_failure; |
| 697 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 698 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 699 | goto nla_put_failure; |
| 700 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 701 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 702 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 703 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 704 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 705 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 706 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 707 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 708 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 709 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 710 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 711 | goto nla_put_failure; |
| 712 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 713 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 714 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 715 | } |
| 716 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 717 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 718 | DBM_TO_MBM(chan->max_power))) |
| 719 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 720 | |
| 721 | return 0; |
| 722 | |
| 723 | nla_put_failure: |
| 724 | return -ENOBUFS; |
| 725 | } |
| 726 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 727 | /* netlink command implementations */ |
| 728 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 729 | struct key_parse { |
| 730 | struct key_params p; |
| 731 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 732 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 733 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 734 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 735 | }; |
| 736 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 737 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
| 738 | struct key_parse *k) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 739 | { |
| 740 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 741 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 742 | nl80211_key_policy, info->extack); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 743 | if (err) |
| 744 | return err; |
| 745 | |
| 746 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 747 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 748 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 749 | if (k->def) { |
| 750 | k->def_uni = true; |
| 751 | k->def_multi = true; |
| 752 | } |
| 753 | if (k->defmgmt) |
| 754 | k->def_multi = true; |
| 755 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 756 | if (tb[NL80211_KEY_IDX]) |
| 757 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 758 | |
| 759 | if (tb[NL80211_KEY_DATA]) { |
| 760 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 761 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 762 | } |
| 763 | |
| 764 | if (tb[NL80211_KEY_SEQ]) { |
| 765 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 766 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 767 | } |
| 768 | |
| 769 | if (tb[NL80211_KEY_CIPHER]) |
| 770 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 771 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 772 | if (tb[NL80211_KEY_TYPE]) { |
| 773 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 774 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 775 | return genl_err_attr(info, -EINVAL, |
| 776 | tb[NL80211_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 777 | } |
| 778 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 779 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 780 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 781 | |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 782 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 783 | tb[NL80211_KEY_DEFAULT_TYPES], |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 784 | nl80211_key_default_policy, |
| 785 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 786 | if (err) |
| 787 | return err; |
| 788 | |
| 789 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 790 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 791 | } |
| 792 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 797 | { |
| 798 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 799 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 800 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 801 | } |
| 802 | |
| 803 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 804 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 805 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 806 | } |
| 807 | |
| 808 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 809 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 810 | |
| 811 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 812 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 813 | |
| 814 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 815 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 816 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 817 | if (k->def) { |
| 818 | k->def_uni = true; |
| 819 | k->def_multi = true; |
| 820 | } |
| 821 | if (k->defmgmt) |
| 822 | k->def_multi = true; |
| 823 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 824 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 825 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 826 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) { |
| 827 | GENL_SET_ERR_MSG(info, "key type out of range"); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 828 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 829 | } |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 830 | } |
| 831 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 832 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 833 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 834 | int err = nla_parse_nested(kdt, |
| 835 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 836 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 837 | nl80211_key_default_policy, |
| 838 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 839 | if (err) |
| 840 | return err; |
| 841 | |
| 842 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 843 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 844 | } |
| 845 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 850 | { |
| 851 | int err; |
| 852 | |
| 853 | memset(k, 0, sizeof(*k)); |
| 854 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 855 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 856 | |
| 857 | if (info->attrs[NL80211_ATTR_KEY]) |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 858 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 859 | else |
| 860 | err = nl80211_parse_key_old(info, k); |
| 861 | |
| 862 | if (err) |
| 863 | return err; |
| 864 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 865 | if (k->def && k->defmgmt) { |
| 866 | GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 867 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 868 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 869 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 870 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 871 | if (k->def_uni || !k->def_multi) { |
| 872 | GENL_SET_ERR_MSG(info, "defmgmt key must be mcast"); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 873 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 874 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 875 | } |
| 876 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 877 | if (k->idx != -1) { |
| 878 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 879 | if (k->idx < 4 || k->idx > 5) { |
| 880 | GENL_SET_ERR_MSG(info, |
| 881 | "defmgmt key idx not 4 or 5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 882 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 883 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 884 | } else if (k->def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 885 | if (k->idx < 0 || k->idx > 3) { |
| 886 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 887 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 888 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 889 | } else { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 890 | if (k->idx < 0 || k->idx > 5) { |
| 891 | GENL_SET_ERR_MSG(info, "key idx not 0-5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 892 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 893 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 900 | static struct cfg80211_cached_keys * |
| 901 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 902 | struct genl_info *info, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 903 | { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 904 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 905 | struct key_parse parse; |
| 906 | struct nlattr *key; |
| 907 | struct cfg80211_cached_keys *result; |
| 908 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 909 | bool have_key = false; |
| 910 | |
| 911 | nla_for_each_nested(key, keys, rem) { |
| 912 | have_key = true; |
| 913 | break; |
| 914 | } |
| 915 | |
| 916 | if (!have_key) |
| 917 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 918 | |
| 919 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 920 | if (!result) |
| 921 | return ERR_PTR(-ENOMEM); |
| 922 | |
| 923 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 924 | |
| 925 | nla_for_each_nested(key, keys, rem) { |
| 926 | memset(&parse, 0, sizeof(parse)); |
| 927 | parse.idx = -1; |
| 928 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 929 | err = nl80211_parse_key_new(info, key, &parse); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 930 | if (err) |
| 931 | goto error; |
| 932 | err = -EINVAL; |
| 933 | if (!parse.p.key) |
| 934 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 935 | if (parse.idx < 0 || parse.idx > 3) { |
| 936 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 937 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 938 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 939 | if (parse.def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 940 | if (def) { |
| 941 | GENL_SET_ERR_MSG(info, |
| 942 | "only one key can be default"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 943 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 944 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 945 | def = 1; |
| 946 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 947 | if (!parse.def_uni || !parse.def_multi) |
| 948 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 949 | } else if (parse.defmgmt) |
| 950 | goto error; |
| 951 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 952 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 953 | if (err) |
| 954 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 955 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 956 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 957 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 958 | err = -EINVAL; |
| 959 | goto error; |
| 960 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 961 | result->params[parse.idx].cipher = parse.p.cipher; |
| 962 | result->params[parse.idx].key_len = parse.p.key_len; |
| 963 | result->params[parse.idx].key = result->data[parse.idx]; |
| 964 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 965 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 966 | /* must be WEP key if we got here */ |
| 967 | if (no_ht) |
| 968 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 969 | } |
| 970 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 971 | if (result->def < 0) { |
| 972 | err = -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 973 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 974 | goto error; |
| 975 | } |
| 976 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 977 | return result; |
| 978 | error: |
| 979 | kfree(result); |
| 980 | return ERR_PTR(err); |
| 981 | } |
| 982 | |
| 983 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 984 | { |
| 985 | ASSERT_WDEV_LOCK(wdev); |
| 986 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 987 | switch (wdev->iftype) { |
| 988 | case NL80211_IFTYPE_AP: |
| 989 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 990 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 991 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 992 | break; |
| 993 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 994 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 995 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 996 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 997 | return -ENOLINK; |
| 998 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 999 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 1000 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1001 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 1002 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1003 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1004 | case NL80211_IFTYPE_WDS: |
| 1005 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1006 | return -EINVAL; |
| 1007 | } |
| 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1012 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 1013 | struct nlattr *tb) |
| 1014 | { |
| 1015 | struct ieee80211_channel *chan; |
| 1016 | |
| 1017 | if (tb == NULL) |
| 1018 | return NULL; |
| 1019 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 1020 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1021 | return NULL; |
| 1022 | return chan; |
| 1023 | } |
| 1024 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1025 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1026 | { |
| 1027 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 1028 | int i; |
| 1029 | |
| 1030 | if (!nl_modes) |
| 1031 | goto nla_put_failure; |
| 1032 | |
| 1033 | i = 0; |
| 1034 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1035 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1036 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1037 | ifmodes >>= 1; |
| 1038 | i++; |
| 1039 | } |
| 1040 | |
| 1041 | nla_nest_end(msg, nl_modes); |
| 1042 | return 0; |
| 1043 | |
| 1044 | nla_put_failure: |
| 1045 | return -ENOBUFS; |
| 1046 | } |
| 1047 | |
| 1048 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1049 | struct sk_buff *msg, |
| 1050 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1051 | { |
| 1052 | struct nlattr *nl_combis; |
| 1053 | int i, j; |
| 1054 | |
| 1055 | nl_combis = nla_nest_start(msg, |
| 1056 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 1057 | if (!nl_combis) |
| 1058 | goto nla_put_failure; |
| 1059 | |
| 1060 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1061 | const struct ieee80211_iface_combination *c; |
| 1062 | struct nlattr *nl_combi, *nl_limits; |
| 1063 | |
| 1064 | c = &wiphy->iface_combinations[i]; |
| 1065 | |
| 1066 | nl_combi = nla_nest_start(msg, i + 1); |
| 1067 | if (!nl_combi) |
| 1068 | goto nla_put_failure; |
| 1069 | |
| 1070 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 1071 | if (!nl_limits) |
| 1072 | goto nla_put_failure; |
| 1073 | |
| 1074 | for (j = 0; j < c->n_limits; j++) { |
| 1075 | struct nlattr *nl_limit; |
| 1076 | |
| 1077 | nl_limit = nla_nest_start(msg, j + 1); |
| 1078 | if (!nl_limit) |
| 1079 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1080 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1081 | c->limits[j].max)) |
| 1082 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1083 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1084 | c->limits[j].types)) |
| 1085 | goto nla_put_failure; |
| 1086 | nla_nest_end(msg, nl_limit); |
| 1087 | } |
| 1088 | |
| 1089 | nla_nest_end(msg, nl_limits); |
| 1090 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1091 | if (c->beacon_int_infra_match && |
| 1092 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1093 | goto nla_put_failure; |
| 1094 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1095 | c->num_different_channels) || |
| 1096 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1097 | c->max_interfaces)) |
| 1098 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1099 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1100 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1101 | c->radar_detect_widths) || |
| 1102 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1103 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1104 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1105 | if (c->beacon_int_min_gcd && |
| 1106 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1107 | c->beacon_int_min_gcd)) |
| 1108 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1109 | |
| 1110 | nla_nest_end(msg, nl_combi); |
| 1111 | } |
| 1112 | |
| 1113 | nla_nest_end(msg, nl_combis); |
| 1114 | |
| 1115 | return 0; |
| 1116 | nla_put_failure: |
| 1117 | return -ENOBUFS; |
| 1118 | } |
| 1119 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1120 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1121 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1122 | struct sk_buff *msg) |
| 1123 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1124 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1125 | struct nlattr *nl_tcp; |
| 1126 | |
| 1127 | if (!tcp) |
| 1128 | return 0; |
| 1129 | |
| 1130 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1131 | if (!nl_tcp) |
| 1132 | return -ENOBUFS; |
| 1133 | |
| 1134 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1135 | tcp->data_payload_max)) |
| 1136 | return -ENOBUFS; |
| 1137 | |
| 1138 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1139 | tcp->data_payload_max)) |
| 1140 | return -ENOBUFS; |
| 1141 | |
| 1142 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1143 | return -ENOBUFS; |
| 1144 | |
| 1145 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1146 | sizeof(*tcp->tok), tcp->tok)) |
| 1147 | return -ENOBUFS; |
| 1148 | |
| 1149 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1150 | tcp->data_interval_max)) |
| 1151 | return -ENOBUFS; |
| 1152 | |
| 1153 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1154 | tcp->wake_payload_max)) |
| 1155 | return -ENOBUFS; |
| 1156 | |
| 1157 | nla_nest_end(msg, nl_tcp); |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1161 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1162 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1163 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1164 | { |
| 1165 | struct nlattr *nl_wowlan; |
| 1166 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1167 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1168 | return 0; |
| 1169 | |
| 1170 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1171 | if (!nl_wowlan) |
| 1172 | return -ENOBUFS; |
| 1173 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1174 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1175 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1176 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1177 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1178 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1179 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1180 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1181 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1182 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1183 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1184 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1185 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1186 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1187 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1188 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1189 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1190 | return -ENOBUFS; |
| 1191 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1192 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1193 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1194 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1195 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1196 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1197 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1198 | }; |
| 1199 | |
| 1200 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1201 | sizeof(pat), &pat)) |
| 1202 | return -ENOBUFS; |
| 1203 | } |
| 1204 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1205 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1206 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1207 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1208 | return -ENOBUFS; |
| 1209 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1210 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1211 | return -ENOBUFS; |
| 1212 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1213 | nla_nest_end(msg, nl_wowlan); |
| 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | #endif |
| 1218 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1219 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1220 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1221 | { |
| 1222 | struct nl80211_coalesce_rule_support rule; |
| 1223 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1224 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1225 | return 0; |
| 1226 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1227 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1228 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1229 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1230 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1231 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1232 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1233 | |
| 1234 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1235 | return -ENOBUFS; |
| 1236 | |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1240 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1241 | struct ieee80211_supported_band *sband) |
| 1242 | { |
| 1243 | struct nlattr *nl_rates, *nl_rate; |
| 1244 | struct ieee80211_rate *rate; |
| 1245 | int i; |
| 1246 | |
| 1247 | /* add HT info */ |
| 1248 | if (sband->ht_cap.ht_supported && |
| 1249 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1250 | sizeof(sband->ht_cap.mcs), |
| 1251 | &sband->ht_cap.mcs) || |
| 1252 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1253 | sband->ht_cap.cap) || |
| 1254 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1255 | sband->ht_cap.ampdu_factor) || |
| 1256 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1257 | sband->ht_cap.ampdu_density))) |
| 1258 | return -ENOBUFS; |
| 1259 | |
| 1260 | /* add VHT info */ |
| 1261 | if (sband->vht_cap.vht_supported && |
| 1262 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1263 | sizeof(sband->vht_cap.vht_mcs), |
| 1264 | &sband->vht_cap.vht_mcs) || |
| 1265 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1266 | sband->vht_cap.cap))) |
| 1267 | return -ENOBUFS; |
| 1268 | |
| 1269 | /* add bitrates */ |
| 1270 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1271 | if (!nl_rates) |
| 1272 | return -ENOBUFS; |
| 1273 | |
| 1274 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1275 | nl_rate = nla_nest_start(msg, i); |
| 1276 | if (!nl_rate) |
| 1277 | return -ENOBUFS; |
| 1278 | |
| 1279 | rate = &sband->bitrates[i]; |
| 1280 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1281 | rate->bitrate)) |
| 1282 | return -ENOBUFS; |
| 1283 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1284 | nla_put_flag(msg, |
| 1285 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1286 | return -ENOBUFS; |
| 1287 | |
| 1288 | nla_nest_end(msg, nl_rate); |
| 1289 | } |
| 1290 | |
| 1291 | nla_nest_end(msg, nl_rates); |
| 1292 | |
| 1293 | return 0; |
| 1294 | } |
| 1295 | |
| 1296 | static int |
| 1297 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1298 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1299 | { |
| 1300 | u16 stypes; |
| 1301 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1302 | enum nl80211_iftype ift; |
| 1303 | int i; |
| 1304 | |
| 1305 | if (!mgmt_stypes) |
| 1306 | return 0; |
| 1307 | |
| 1308 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1309 | if (!nl_ifs) |
| 1310 | return -ENOBUFS; |
| 1311 | |
| 1312 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1313 | nl_ftypes = nla_nest_start(msg, ift); |
| 1314 | if (!nl_ftypes) |
| 1315 | return -ENOBUFS; |
| 1316 | i = 0; |
| 1317 | stypes = mgmt_stypes[ift].tx; |
| 1318 | while (stypes) { |
| 1319 | if ((stypes & 1) && |
| 1320 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1321 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1322 | return -ENOBUFS; |
| 1323 | stypes >>= 1; |
| 1324 | i++; |
| 1325 | } |
| 1326 | nla_nest_end(msg, nl_ftypes); |
| 1327 | } |
| 1328 | |
| 1329 | nla_nest_end(msg, nl_ifs); |
| 1330 | |
| 1331 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1332 | if (!nl_ifs) |
| 1333 | return -ENOBUFS; |
| 1334 | |
| 1335 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1336 | nl_ftypes = nla_nest_start(msg, ift); |
| 1337 | if (!nl_ftypes) |
| 1338 | return -ENOBUFS; |
| 1339 | i = 0; |
| 1340 | stypes = mgmt_stypes[ift].rx; |
| 1341 | while (stypes) { |
| 1342 | if ((stypes & 1) && |
| 1343 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1344 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1345 | return -ENOBUFS; |
| 1346 | stypes >>= 1; |
| 1347 | i++; |
| 1348 | } |
| 1349 | nla_nest_end(msg, nl_ftypes); |
| 1350 | } |
| 1351 | nla_nest_end(msg, nl_ifs); |
| 1352 | |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1356 | #define CMD(op, n) \ |
| 1357 | do { \ |
| 1358 | if (rdev->ops->op) { \ |
| 1359 | i++; \ |
| 1360 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1361 | goto nla_put_failure; \ |
| 1362 | } \ |
| 1363 | } while (0) |
| 1364 | |
| 1365 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1366 | struct sk_buff *msg) |
| 1367 | { |
| 1368 | int i = 0; |
| 1369 | |
| 1370 | /* |
| 1371 | * do *NOT* add anything into this function, new things need to be |
| 1372 | * advertised only to new versions of userspace that can deal with |
| 1373 | * the split (and they can't possibly care about new features... |
| 1374 | */ |
| 1375 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1376 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1377 | CMD(add_key, NEW_KEY); |
| 1378 | CMD(start_ap, START_AP); |
| 1379 | CMD(add_station, NEW_STATION); |
| 1380 | CMD(add_mpath, NEW_MPATH); |
| 1381 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1382 | CMD(change_bss, SET_BSS); |
| 1383 | CMD(auth, AUTHENTICATE); |
| 1384 | CMD(assoc, ASSOCIATE); |
| 1385 | CMD(deauth, DEAUTHENTICATE); |
| 1386 | CMD(disassoc, DISASSOCIATE); |
| 1387 | CMD(join_ibss, JOIN_IBSS); |
| 1388 | CMD(join_mesh, JOIN_MESH); |
| 1389 | CMD(set_pmksa, SET_PMKSA); |
| 1390 | CMD(del_pmksa, DEL_PMKSA); |
| 1391 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1392 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1393 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1394 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1395 | CMD(mgmt_tx, FRAME); |
| 1396 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1397 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1398 | i++; |
| 1399 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1400 | goto nla_put_failure; |
| 1401 | } |
| 1402 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1403 | rdev->ops->join_mesh) { |
| 1404 | i++; |
| 1405 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1406 | goto nla_put_failure; |
| 1407 | } |
| 1408 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1409 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1410 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1411 | CMD(tdls_oper, TDLS_OPER); |
| 1412 | } |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1413 | if (rdev->wiphy.max_sched_scan_reqs) |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1414 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1415 | CMD(probe_client, PROBE_CLIENT); |
| 1416 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1417 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1418 | i++; |
| 1419 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1420 | goto nla_put_failure; |
| 1421 | } |
| 1422 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1423 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1424 | #ifdef CONFIG_NL80211_TESTMODE |
| 1425 | CMD(testmode_cmd, TESTMODE); |
| 1426 | #endif |
| 1427 | |
| 1428 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1429 | i++; |
| 1430 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1431 | goto nla_put_failure; |
| 1432 | } |
| 1433 | |
| 1434 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1435 | i++; |
| 1436 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1437 | goto nla_put_failure; |
| 1438 | } |
| 1439 | |
| 1440 | return i; |
| 1441 | nla_put_failure: |
| 1442 | return -ENOBUFS; |
| 1443 | } |
| 1444 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1445 | struct nl80211_dump_wiphy_state { |
| 1446 | s64 filter_wiphy; |
| 1447 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1448 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1449 | bool split; |
| 1450 | }; |
| 1451 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1452 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1453 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1454 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1455 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1456 | { |
| 1457 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1458 | struct nlattr *nl_bands, *nl_band; |
| 1459 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1460 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1461 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1462 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1463 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1464 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1465 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1466 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1467 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1468 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1469 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1470 | return -ENOBUFS; |
| 1471 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1472 | if (WARN_ON(!state)) |
| 1473 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1474 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1475 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1476 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1477 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1478 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1479 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1480 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1481 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1482 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1483 | goto finish; |
| 1484 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1485 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1486 | case 0: |
| 1487 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1488 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1489 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1490 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1491 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1492 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1493 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1494 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1495 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1496 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1497 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1498 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1499 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1500 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1501 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1502 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1504 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1505 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1506 | rdev->wiphy.max_match_sets) || |
| 1507 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1508 | rdev->wiphy.max_sched_scan_plans) || |
| 1509 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1510 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1511 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1512 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1513 | goto nla_put_failure; |
| 1514 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1515 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1516 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1517 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1518 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1519 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1520 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1521 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1522 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1523 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1524 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1525 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1526 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1527 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1528 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1529 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1530 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1531 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1532 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1533 | state->split_start++; |
| 1534 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | break; |
| 1536 | case 1: |
| 1537 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1538 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1539 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1540 | goto nla_put_failure; |
| 1541 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1542 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1543 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1544 | goto nla_put_failure; |
| 1545 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1546 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1547 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1548 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1549 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1550 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1551 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1552 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1553 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1554 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1555 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1556 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1557 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1558 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1559 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1560 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1561 | if ((rdev->wiphy.available_antennas_tx || |
| 1562 | rdev->wiphy.available_antennas_rx) && |
| 1563 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | u32 tx_ant = 0, rx_ant = 0; |
| 1565 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1566 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1567 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1568 | if (!res) { |
| 1569 | if (nla_put_u32(msg, |
| 1570 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1571 | tx_ant) || |
| 1572 | nla_put_u32(msg, |
| 1573 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1574 | rx_ant)) |
| 1575 | goto nla_put_failure; |
| 1576 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1577 | } |
| 1578 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1579 | state->split_start++; |
| 1580 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1581 | break; |
| 1582 | case 2: |
| 1583 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1584 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1585 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1586 | state->split_start++; |
| 1587 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1588 | break; |
| 1589 | case 3: |
| 1590 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1591 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1592 | goto nla_put_failure; |
| 1593 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1594 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1595 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1596 | struct ieee80211_supported_band *sband; |
| 1597 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1598 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1599 | |
| 1600 | if (!sband) |
| 1601 | continue; |
| 1602 | |
| 1603 | nl_band = nla_nest_start(msg, band); |
| 1604 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1605 | goto nla_put_failure; |
| 1606 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1607 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1608 | case 0: |
| 1609 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1610 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1611 | state->chan_start++; |
| 1612 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1613 | break; |
| 1614 | default: |
| 1615 | /* add frequencies */ |
| 1616 | nl_freqs = nla_nest_start( |
| 1617 | msg, NL80211_BAND_ATTR_FREQS); |
| 1618 | if (!nl_freqs) |
| 1619 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1620 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1621 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1622 | i < sband->n_channels; |
| 1623 | i++) { |
| 1624 | nl_freq = nla_nest_start(msg, i); |
| 1625 | if (!nl_freq) |
| 1626 | goto nla_put_failure; |
| 1627 | |
| 1628 | chan = &sband->channels[i]; |
| 1629 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1630 | if (nl80211_msg_put_channel( |
| 1631 | msg, chan, |
| 1632 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1633 | goto nla_put_failure; |
| 1634 | |
| 1635 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1636 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1637 | break; |
| 1638 | } |
| 1639 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1640 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1641 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1642 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1643 | nla_nest_end(msg, nl_freqs); |
| 1644 | } |
| 1645 | |
| 1646 | nla_nest_end(msg, nl_band); |
| 1647 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1648 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1649 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1650 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1651 | band--; |
| 1652 | break; |
| 1653 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1654 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1655 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1656 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1657 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1658 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1659 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1660 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1661 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1662 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1663 | if (state->band_start == 0 && state->chan_start == 0) |
| 1664 | state->split_start++; |
| 1665 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1666 | break; |
| 1667 | case 4: |
| 1668 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1669 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1670 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1671 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1672 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 1673 | if (i < 0) |
| 1674 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1675 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1676 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1677 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1678 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1679 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1680 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1681 | if (rdev->wiphy.features & |
| 1682 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1683 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 1684 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 1685 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1686 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1687 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1688 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1689 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1690 | state->split_start++; |
| 1691 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1692 | break; |
| 1693 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1694 | if (rdev->ops->remain_on_channel && |
| 1695 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1696 | nla_put_u32(msg, |
| 1697 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1698 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1699 | goto nla_put_failure; |
| 1700 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1701 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1702 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1703 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1704 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1705 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1706 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1707 | state->split_start++; |
| 1708 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1709 | break; |
| 1710 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1711 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1712 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1713 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1714 | state->split_start++; |
| 1715 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1716 | break; |
| 1717 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1718 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1719 | #endif |
| 1720 | case 7: |
| 1721 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1722 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1723 | goto nla_put_failure; |
| 1724 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1725 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1726 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1727 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1728 | |
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 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1733 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1734 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1735 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1736 | goto nla_put_failure; |
| 1737 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1738 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1739 | /* |
| 1740 | * We can only add the per-channel limit information if the |
| 1741 | * dump is split, otherwise it makes it too big. Therefore |
| 1742 | * only advertise it in that case. |
| 1743 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1744 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1745 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1746 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1747 | goto nla_put_failure; |
| 1748 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1749 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1750 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1751 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1752 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1753 | goto nla_put_failure; |
| 1754 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1755 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1756 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1757 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1758 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1759 | goto nla_put_failure; |
| 1760 | |
| 1761 | /* |
| 1762 | * Any information below this point is only available to |
| 1763 | * applications that can deal with it being split. This |
| 1764 | * helps ensure that newly added capabilities don't break |
| 1765 | * older tools by overrunning their buffers. |
| 1766 | * |
| 1767 | * We still increment split_start so that in the split |
| 1768 | * case we'll continue with more data in the next round, |
| 1769 | * but break unconditionally so unsplit data stops here. |
| 1770 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1771 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1772 | break; |
| 1773 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1774 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1775 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1776 | rdev->wiphy.extended_capabilities_len, |
| 1777 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1778 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1779 | rdev->wiphy.extended_capabilities_len, |
| 1780 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1781 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1782 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1783 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1784 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1785 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1786 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1787 | goto nla_put_failure; |
| 1788 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1789 | state->split_start++; |
| 1790 | break; |
| 1791 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1792 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1793 | goto nla_put_failure; |
| 1794 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1795 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1796 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1797 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1798 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1799 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1800 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1801 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1802 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1803 | goto nla_put_failure; |
| 1804 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1805 | state->split_start++; |
| 1806 | break; |
| 1807 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1808 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1809 | const struct nl80211_vendor_cmd_info *info; |
| 1810 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1811 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1812 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1813 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1814 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1815 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1816 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1817 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1818 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1819 | goto nla_put_failure; |
| 1820 | } |
| 1821 | nla_nest_end(msg, nested); |
| 1822 | } |
| 1823 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1824 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1825 | const struct nl80211_vendor_cmd_info *info; |
| 1826 | struct nlattr *nested; |
| 1827 | |
| 1828 | nested = nla_nest_start(msg, |
| 1829 | NL80211_ATTR_VENDOR_EVENTS); |
| 1830 | if (!nested) |
| 1831 | goto nla_put_failure; |
| 1832 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1833 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1834 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1835 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1836 | goto nla_put_failure; |
| 1837 | } |
| 1838 | nla_nest_end(msg, nested); |
| 1839 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1840 | state->split_start++; |
| 1841 | break; |
| 1842 | case 12: |
| 1843 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1844 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1845 | rdev->wiphy.max_num_csa_counters)) |
| 1846 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1847 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1848 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1849 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1850 | goto nla_put_failure; |
| 1851 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1852 | if (rdev->wiphy.max_sched_scan_reqs && |
| 1853 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, |
| 1854 | rdev->wiphy.max_sched_scan_reqs)) |
| 1855 | goto nla_put_failure; |
| 1856 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1857 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1858 | sizeof(rdev->wiphy.ext_features), |
| 1859 | rdev->wiphy.ext_features)) |
| 1860 | goto nla_put_failure; |
| 1861 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 1862 | if (rdev->wiphy.bss_select_support) { |
| 1863 | struct nlattr *nested; |
| 1864 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 1865 | |
| 1866 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 1867 | if (!nested) |
| 1868 | goto nla_put_failure; |
| 1869 | |
| 1870 | i = 0; |
| 1871 | while (bss_select_support) { |
| 1872 | if ((bss_select_support & 1) && |
| 1873 | nla_put_flag(msg, i)) |
| 1874 | goto nla_put_failure; |
| 1875 | i++; |
| 1876 | bss_select_support >>= 1; |
| 1877 | } |
| 1878 | nla_nest_end(msg, nested); |
| 1879 | } |
| 1880 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1881 | state->split_start++; |
| 1882 | break; |
| 1883 | case 13: |
| 1884 | if (rdev->wiphy.num_iftype_ext_capab && |
| 1885 | rdev->wiphy.iftype_ext_capab) { |
| 1886 | struct nlattr *nested_ext_capab, *nested; |
| 1887 | |
| 1888 | nested = nla_nest_start(msg, |
| 1889 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 1890 | if (!nested) |
| 1891 | goto nla_put_failure; |
| 1892 | |
| 1893 | for (i = state->capa_start; |
| 1894 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 1895 | const struct wiphy_iftype_ext_capab *capab; |
| 1896 | |
| 1897 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 1898 | |
| 1899 | nested_ext_capab = nla_nest_start(msg, i); |
| 1900 | if (!nested_ext_capab || |
| 1901 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1902 | capab->iftype) || |
| 1903 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1904 | capab->extended_capabilities_len, |
| 1905 | capab->extended_capabilities) || |
| 1906 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1907 | capab->extended_capabilities_len, |
| 1908 | capab->extended_capabilities_mask)) |
| 1909 | goto nla_put_failure; |
| 1910 | |
| 1911 | nla_nest_end(msg, nested_ext_capab); |
| 1912 | if (state->split) |
| 1913 | break; |
| 1914 | } |
| 1915 | nla_nest_end(msg, nested); |
| 1916 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 1917 | state->capa_start = i + 1; |
| 1918 | break; |
| 1919 | } |
| 1920 | } |
| 1921 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 1922 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 1923 | rdev->wiphy.nan_supported_bands)) |
| 1924 | goto nla_put_failure; |
| 1925 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1926 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1927 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1928 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1929 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1930 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1931 | genlmsg_end(msg, hdr); |
| 1932 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1933 | |
| 1934 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1935 | genlmsg_cancel(msg, hdr); |
| 1936 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1937 | } |
| 1938 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1939 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1940 | struct netlink_callback *cb, |
| 1941 | struct nl80211_dump_wiphy_state *state) |
| 1942 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 1943 | struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 1944 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb, |
| 1945 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1946 | /* ignore parse errors for backward compatibility */ |
| 1947 | if (ret) |
| 1948 | return 0; |
| 1949 | |
| 1950 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1951 | if (tb[NL80211_ATTR_WIPHY]) |
| 1952 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1953 | if (tb[NL80211_ATTR_WDEV]) |
| 1954 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1955 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1956 | struct net_device *netdev; |
| 1957 | struct cfg80211_registered_device *rdev; |
| 1958 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1959 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1960 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1961 | if (!netdev) |
| 1962 | return -ENODEV; |
| 1963 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1964 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1965 | netdev->ieee80211_ptr->wiphy); |
| 1966 | state->filter_wiphy = rdev->wiphy_idx; |
| 1967 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | return 0; |
| 1971 | } |
| 1972 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1973 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1974 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1975 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1976 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1977 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1978 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1979 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1980 | if (!state) { |
| 1981 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1982 | if (!state) { |
| 1983 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1984 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1985 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1986 | state->filter_wiphy = -1; |
| 1987 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1988 | if (ret) { |
| 1989 | kfree(state); |
| 1990 | rtnl_unlock(); |
| 1991 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1992 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1993 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1994 | } |
| 1995 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1996 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1997 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1998 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1999 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2000 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2001 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2002 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2003 | continue; |
| 2004 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 2005 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2006 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 2007 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2008 | NETLINK_CB(cb->skb).portid, |
| 2009 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2010 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2011 | if (ret < 0) { |
| 2012 | /* |
| 2013 | * If sending the wiphy data didn't fit (ENOBUFS |
| 2014 | * or EMSGSIZE returned), this SKB is still |
| 2015 | * empty (so it's not too big because another |
| 2016 | * wiphy dataset is already in the skb) and |
| 2017 | * we've not tried to adjust the dump allocation |
| 2018 | * yet ... then adjust the alloc size to be |
| 2019 | * bigger, and return 1 but with the empty skb. |
| 2020 | * This results in an empty message being RX'ed |
| 2021 | * in userspace, but that is ignored. |
| 2022 | * |
| 2023 | * We can then retry with the larger buffer. |
| 2024 | */ |
| 2025 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2026 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2027 | cb->min_dump_alloc < 4096) { |
| 2028 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2029 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 2030 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2031 | return 1; |
| 2032 | } |
| 2033 | idx--; |
| 2034 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2035 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2036 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2037 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2038 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2039 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2040 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2041 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2042 | |
| 2043 | return skb->len; |
| 2044 | } |
| 2045 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2046 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2047 | { |
| 2048 | kfree((void *)cb->args[0]); |
| 2049 | return 0; |
| 2050 | } |
| 2051 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2052 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2053 | { |
| 2054 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2055 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2056 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2057 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2058 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2059 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2060 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2061 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2062 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2063 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2064 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2065 | nlmsg_free(msg); |
| 2066 | return -ENOBUFS; |
| 2067 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2068 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2069 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2070 | } |
| 2071 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2072 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2073 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2074 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2075 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2076 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2077 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2078 | }; |
| 2079 | |
| 2080 | static int parse_txq_params(struct nlattr *tb[], |
| 2081 | struct ieee80211_txq_params *txq_params) |
| 2082 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2083 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2084 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2085 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2086 | return -EINVAL; |
| 2087 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2088 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2089 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2090 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2091 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2092 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2093 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2094 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 2095 | return -EINVAL; |
| 2096 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2097 | return 0; |
| 2098 | } |
| 2099 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2100 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2101 | { |
| 2102 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2103 | * You can only set the channel explicitly for WDS interfaces, |
| 2104 | * all others have their channel managed via their respective |
| 2105 | * "establish a connection" command (connect, join, ...) |
| 2106 | * |
| 2107 | * For AP/GO and mesh mode, the channel can be set with the |
| 2108 | * channel userspace API, but is only stored and passed to the |
| 2109 | * low-level driver when the AP starts or the mesh is joined. |
| 2110 | * This is for backward compatibility, userspace can also give |
| 2111 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2112 | * |
| 2113 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2114 | * whatever else is going on, so they have their own special |
| 2115 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2116 | */ |
| 2117 | return !wdev || |
| 2118 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2119 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2120 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2121 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2122 | } |
| 2123 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2124 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2125 | struct genl_info *info, |
| 2126 | struct cfg80211_chan_def *chandef) |
| 2127 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2128 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2129 | |
| 2130 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 2131 | return -EINVAL; |
| 2132 | |
| 2133 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 2134 | |
| 2135 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2136 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2137 | chandef->center_freq1 = control_freq; |
| 2138 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2139 | |
| 2140 | /* Primary channel not allowed */ |
| 2141 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 2142 | return -EINVAL; |
| 2143 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2144 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2145 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2146 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2147 | chantype = nla_get_u32( |
| 2148 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2149 | |
| 2150 | switch (chantype) { |
| 2151 | case NL80211_CHAN_NO_HT: |
| 2152 | case NL80211_CHAN_HT20: |
| 2153 | case NL80211_CHAN_HT40PLUS: |
| 2154 | case NL80211_CHAN_HT40MINUS: |
| 2155 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2156 | chantype); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2157 | /* user input for center_freq is incorrect */ |
| 2158 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1] && |
| 2159 | chandef->center_freq1 != nla_get_u32( |
| 2160 | info->attrs[NL80211_ATTR_CENTER_FREQ1])) |
| 2161 | return -EINVAL; |
| 2162 | /* center_freq2 must be zero */ |
| 2163 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2] && |
| 2164 | nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2])) |
| 2165 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2166 | break; |
| 2167 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2168 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2169 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2170 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2171 | chandef->width = |
| 2172 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2173 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2174 | chandef->center_freq1 = |
| 2175 | nla_get_u32( |
| 2176 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2177 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2178 | chandef->center_freq2 = |
| 2179 | nla_get_u32( |
| 2180 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2181 | } |
| 2182 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2183 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2184 | return -EINVAL; |
| 2185 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2186 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2187 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2188 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2189 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2190 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2191 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2192 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2193 | return -EINVAL; |
| 2194 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2195 | return 0; |
| 2196 | } |
| 2197 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2198 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2199 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2200 | struct genl_info *info) |
| 2201 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2202 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2203 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2204 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2205 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2206 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2207 | if (dev) |
| 2208 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2209 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2210 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2211 | if (wdev) |
| 2212 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2213 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2214 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2215 | if (result) |
| 2216 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2217 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2218 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2219 | case NL80211_IFTYPE_AP: |
| 2220 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2221 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2222 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2223 | result = -EINVAL; |
| 2224 | break; |
| 2225 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2226 | if (wdev->beacon_interval) { |
| 2227 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2228 | !(rdev->wiphy.features & |
| 2229 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2230 | result = -EBUSY; |
| 2231 | break; |
| 2232 | } |
| 2233 | |
| 2234 | /* Only allow dynamic channel width changes */ |
| 2235 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2236 | result = -EBUSY; |
| 2237 | break; |
| 2238 | } |
| 2239 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2240 | if (result) |
| 2241 | break; |
| 2242 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2243 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2244 | result = 0; |
| 2245 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2246 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2247 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2248 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2249 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2250 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2251 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2252 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2253 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2254 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2255 | |
| 2256 | return result; |
| 2257 | } |
| 2258 | |
| 2259 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2260 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2262 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2263 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2264 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2265 | } |
| 2266 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2267 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2268 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2270 | struct net_device *dev = info->user_ptr[1]; |
| 2271 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2272 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2273 | |
| 2274 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2275 | return -EINVAL; |
| 2276 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2277 | if (netif_running(dev)) |
| 2278 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2279 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2280 | if (!rdev->ops->set_wds_peer) |
| 2281 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2282 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2283 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2284 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2285 | |
| 2286 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2287 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2288 | } |
| 2289 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2290 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2291 | { |
| 2292 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2293 | struct net_device *netdev = NULL; |
| 2294 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2295 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2296 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2297 | u32 changed; |
| 2298 | u8 retry_short = 0, retry_long = 0; |
| 2299 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2300 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2301 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2302 | ASSERT_RTNL(); |
| 2303 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2304 | /* |
| 2305 | * Try to find the wiphy and netdev. Normally this |
| 2306 | * function shouldn't need the netdev, but this is |
| 2307 | * done for backward compatibility -- previously |
| 2308 | * setting the channel was done per wiphy, but now |
| 2309 | * it is per netdev. Previous userland like hostapd |
| 2310 | * also passed a netdev to set_wiphy, so that it is |
| 2311 | * possible to let that go to the right netdev! |
| 2312 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2313 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2314 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2315 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2316 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2317 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2318 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2319 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2320 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2321 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2322 | } |
| 2323 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2324 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2325 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2326 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2327 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2328 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2329 | wdev = NULL; |
| 2330 | netdev = NULL; |
| 2331 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2332 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2333 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2334 | |
| 2335 | /* |
| 2336 | * end workaround code, by now the rdev is available |
| 2337 | * and locked, and wdev may or may not be NULL. |
| 2338 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2339 | |
| 2340 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2341 | result = cfg80211_dev_rename( |
| 2342 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2343 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2344 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2345 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2346 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2347 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2348 | struct ieee80211_txq_params txq_params; |
| 2349 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2350 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2351 | if (!rdev->ops->set_txq_params) |
| 2352 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2353 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2354 | if (!netdev) |
| 2355 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2356 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2357 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2358 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2359 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2360 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2361 | if (!netif_running(netdev)) |
| 2362 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2363 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2364 | nla_for_each_nested(nl_txq_params, |
| 2365 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2366 | rem_txq_params) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 2367 | result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX, |
| 2368 | nl_txq_params, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 2369 | txq_params_policy, |
| 2370 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2371 | if (result) |
| 2372 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2373 | result = parse_txq_params(tb, &txq_params); |
| 2374 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2375 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2376 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2377 | result = rdev_set_txq_params(rdev, netdev, |
| 2378 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2379 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2380 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2381 | } |
| 2382 | } |
| 2383 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2384 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2385 | result = __nl80211_set_channel( |
| 2386 | rdev, |
| 2387 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2388 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2389 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2390 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2391 | } |
| 2392 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2393 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2394 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2395 | enum nl80211_tx_power_setting type; |
| 2396 | int idx, mbm = 0; |
| 2397 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2398 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2399 | txp_wdev = NULL; |
| 2400 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2401 | if (!rdev->ops->set_tx_power) |
| 2402 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2403 | |
| 2404 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2405 | type = nla_get_u32(info->attrs[idx]); |
| 2406 | |
| 2407 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2408 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2409 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2410 | |
| 2411 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2412 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2413 | mbm = nla_get_u32(info->attrs[idx]); |
| 2414 | } |
| 2415 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2416 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2417 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2418 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2419 | } |
| 2420 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2421 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2422 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2423 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2424 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2425 | if ((!rdev->wiphy.available_antennas_tx && |
| 2426 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2427 | !rdev->ops->set_antenna) |
| 2428 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2429 | |
| 2430 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2431 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2432 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2433 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2434 | * available antenna masks, except for the "all" mask */ |
| 2435 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2436 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2437 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2438 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2439 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2440 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2441 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2442 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2443 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2444 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2445 | } |
| 2446 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2447 | changed = 0; |
| 2448 | |
| 2449 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2450 | retry_short = nla_get_u8( |
| 2451 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2452 | if (retry_short == 0) |
| 2453 | return -EINVAL; |
| 2454 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2455 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2456 | } |
| 2457 | |
| 2458 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2459 | retry_long = nla_get_u8( |
| 2460 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2461 | if (retry_long == 0) |
| 2462 | return -EINVAL; |
| 2463 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2464 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2465 | } |
| 2466 | |
| 2467 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2468 | frag_threshold = nla_get_u32( |
| 2469 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2470 | if (frag_threshold < 256) |
| 2471 | return -EINVAL; |
| 2472 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2473 | if (frag_threshold != (u32) -1) { |
| 2474 | /* |
| 2475 | * Fragments (apart from the last one) are required to |
| 2476 | * have even length. Make the fragmentation code |
| 2477 | * simpler by stripping LSB should someone try to use |
| 2478 | * odd threshold value. |
| 2479 | */ |
| 2480 | frag_threshold &= ~0x1; |
| 2481 | } |
| 2482 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2483 | } |
| 2484 | |
| 2485 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2486 | rts_threshold = nla_get_u32( |
| 2487 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2488 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2489 | } |
| 2490 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2491 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2492 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2493 | return -EINVAL; |
| 2494 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2495 | coverage_class = nla_get_u8( |
| 2496 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2497 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2498 | } |
| 2499 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2500 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2501 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2502 | return -EOPNOTSUPP; |
| 2503 | |
| 2504 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2505 | } |
| 2506 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2507 | if (changed) { |
| 2508 | u8 old_retry_short, old_retry_long; |
| 2509 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2510 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2511 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2512 | if (!rdev->ops->set_wiphy_params) |
| 2513 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2514 | |
| 2515 | old_retry_short = rdev->wiphy.retry_short; |
| 2516 | old_retry_long = rdev->wiphy.retry_long; |
| 2517 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2518 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2519 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2520 | |
| 2521 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2522 | rdev->wiphy.retry_short = retry_short; |
| 2523 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2524 | rdev->wiphy.retry_long = retry_long; |
| 2525 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2526 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2527 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2528 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2529 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2530 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2531 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2532 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2533 | if (result) { |
| 2534 | rdev->wiphy.retry_short = old_retry_short; |
| 2535 | rdev->wiphy.retry_long = old_retry_long; |
| 2536 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2537 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2538 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2539 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2540 | } |
| 2541 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2542 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2543 | } |
| 2544 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2545 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2546 | { |
| 2547 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2548 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2549 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2550 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2551 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2552 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2553 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2554 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2555 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2556 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2557 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2558 | chandef->chan->center_freq)) |
| 2559 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2560 | switch (chandef->width) { |
| 2561 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2562 | case NL80211_CHAN_WIDTH_20: |
| 2563 | case NL80211_CHAN_WIDTH_40: |
| 2564 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2565 | cfg80211_get_chandef_type(chandef))) |
| 2566 | return -ENOBUFS; |
| 2567 | break; |
| 2568 | default: |
| 2569 | break; |
| 2570 | } |
| 2571 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2572 | return -ENOBUFS; |
| 2573 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2574 | return -ENOBUFS; |
| 2575 | if (chandef->center_freq2 && |
| 2576 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2577 | return -ENOBUFS; |
| 2578 | return 0; |
| 2579 | } |
| 2580 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2581 | 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] | 2582 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2583 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2584 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2585 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2586 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2587 | void *hdr; |
| 2588 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2589 | if (removal) |
| 2590 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2591 | |
| 2592 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2593 | if (!hdr) |
| 2594 | return -1; |
| 2595 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2596 | if (dev && |
| 2597 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2598 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2599 | goto nla_put_failure; |
| 2600 | |
| 2601 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2602 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2603 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2604 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2605 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2606 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2607 | rdev->devlist_generation ^ |
| 2608 | (cfg80211_rdev_list_generation << 2))) |
| 2609 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2610 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2611 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2612 | int ret; |
| 2613 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2614 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2615 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2616 | if (ret == 0) { |
| 2617 | if (nl80211_send_chandef(msg, &chandef)) |
| 2618 | goto nla_put_failure; |
| 2619 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2620 | } |
| 2621 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2622 | if (rdev->ops->get_tx_power) { |
| 2623 | int dbm, ret; |
| 2624 | |
| 2625 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2626 | if (ret == 0 && |
| 2627 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2628 | DBM_TO_MBM(dbm))) |
| 2629 | goto nla_put_failure; |
| 2630 | } |
| 2631 | |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 2632 | wdev_lock(wdev); |
| 2633 | switch (wdev->iftype) { |
| 2634 | case NL80211_IFTYPE_AP: |
| 2635 | if (wdev->ssid_len && |
| 2636 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2637 | goto nla_put_failure; |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 2638 | break; |
| 2639 | case NL80211_IFTYPE_STATION: |
| 2640 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2641 | case NL80211_IFTYPE_ADHOC: { |
| 2642 | const u8 *ssid_ie; |
| 2643 | if (!wdev->current_bss) |
| 2644 | break; |
| 2645 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 2646 | WLAN_EID_SSID); |
| 2647 | if (!ssid_ie) |
| 2648 | break; |
| 2649 | if (nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) |
| 2650 | goto nla_put_failure; |
| 2651 | break; |
| 2652 | } |
| 2653 | default: |
| 2654 | /* nothing */ |
| 2655 | break; |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2656 | } |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 2657 | wdev_unlock(wdev); |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2658 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2659 | genlmsg_end(msg, hdr); |
| 2660 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2661 | |
| 2662 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2663 | genlmsg_cancel(msg, hdr); |
| 2664 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2668 | { |
| 2669 | int wp_idx = 0; |
| 2670 | int if_idx = 0; |
| 2671 | int wp_start = cb->args[0]; |
| 2672 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2673 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2674 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2675 | struct wireless_dev *wdev; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2676 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2677 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2678 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2679 | if (!cb->args[2]) { |
| 2680 | struct nl80211_dump_wiphy_state state = { |
| 2681 | .filter_wiphy = -1, |
| 2682 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2683 | |
| 2684 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 2685 | if (ret) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2686 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2687 | |
| 2688 | filter_wiphy = state.filter_wiphy; |
| 2689 | |
| 2690 | /* |
| 2691 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 2692 | * value needed to determine that parsing is necessary. |
| 2693 | */ |
| 2694 | if (filter_wiphy >= 0) |
| 2695 | cb->args[2] = filter_wiphy + 1; |
| 2696 | else |
| 2697 | cb->args[2] = -1; |
| 2698 | } else if (cb->args[2] > 0) { |
| 2699 | filter_wiphy = cb->args[2] - 1; |
| 2700 | } |
| 2701 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2702 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2703 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2704 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2705 | if (wp_idx < wp_start) { |
| 2706 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2707 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2708 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2709 | |
| 2710 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 2711 | continue; |
| 2712 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2713 | if_idx = 0; |
| 2714 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2715 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2716 | if (if_idx < if_start) { |
| 2717 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2718 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2719 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2720 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2721 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2722 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2723 | goto out; |
| 2724 | } |
| 2725 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2726 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2727 | |
| 2728 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2729 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2730 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2731 | cb->args[0] = wp_idx; |
| 2732 | cb->args[1] = if_idx; |
| 2733 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2734 | ret = skb->len; |
| 2735 | out_unlock: |
| 2736 | rtnl_unlock(); |
| 2737 | |
| 2738 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2742 | { |
| 2743 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2745 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2746 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2747 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2748 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2749 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2750 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2751 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2752 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2753 | nlmsg_free(msg); |
| 2754 | return -ENOBUFS; |
| 2755 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2756 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2757 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2758 | } |
| 2759 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2760 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2761 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2762 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2763 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2764 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2765 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2766 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2767 | }; |
| 2768 | |
| 2769 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2770 | { |
| 2771 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2772 | int flag; |
| 2773 | |
| 2774 | *mntrflags = 0; |
| 2775 | |
| 2776 | if (!nla) |
| 2777 | return -EINVAL; |
| 2778 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 2779 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla, |
| 2780 | mntr_flags_policy, NULL)) |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2781 | return -EINVAL; |
| 2782 | |
| 2783 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2784 | if (flags[flag]) |
| 2785 | *mntrflags |= (1<<flag); |
| 2786 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2787 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 2788 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2789 | return 0; |
| 2790 | } |
| 2791 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2792 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 2793 | enum nl80211_iftype type, |
| 2794 | struct genl_info *info, |
| 2795 | struct vif_params *params) |
| 2796 | { |
| 2797 | bool change = false; |
| 2798 | int err; |
| 2799 | |
| 2800 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 2801 | if (type != NL80211_IFTYPE_MONITOR) |
| 2802 | return -EINVAL; |
| 2803 | |
| 2804 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2805 | ¶ms->flags); |
| 2806 | if (err) |
| 2807 | return err; |
| 2808 | |
| 2809 | change = true; |
| 2810 | } |
| 2811 | |
| 2812 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 2813 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2814 | return -EOPNOTSUPP; |
| 2815 | |
| 2816 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 2817 | const u8 *mumimo_groups; |
| 2818 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2819 | |
| 2820 | if (type != NL80211_IFTYPE_MONITOR) |
| 2821 | return -EINVAL; |
| 2822 | |
| 2823 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2824 | return -EOPNOTSUPP; |
| 2825 | |
| 2826 | mumimo_groups = |
| 2827 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 2828 | |
| 2829 | /* bits 0 and 63 are reserved and must be zero */ |
Johannes Berg | 4954601 | 2017-04-27 09:13:38 +0200 | [diff] [blame] | 2830 | if ((mumimo_groups[0] & BIT(0)) || |
| 2831 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2832 | return -EINVAL; |
| 2833 | |
| 2834 | params->vht_mumimo_groups = mumimo_groups; |
| 2835 | change = true; |
| 2836 | } |
| 2837 | |
| 2838 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 2839 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2840 | |
| 2841 | if (type != NL80211_IFTYPE_MONITOR) |
| 2842 | return -EINVAL; |
| 2843 | |
| 2844 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2845 | return -EOPNOTSUPP; |
| 2846 | |
| 2847 | params->vht_mumimo_follow_addr = |
| 2848 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 2849 | change = true; |
| 2850 | } |
| 2851 | |
| 2852 | return change ? 1 : 0; |
| 2853 | } |
| 2854 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2855 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2856 | struct net_device *netdev, u8 use_4addr, |
| 2857 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2858 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2859 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2860 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2861 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2862 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2863 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2864 | |
| 2865 | switch (iftype) { |
| 2866 | case NL80211_IFTYPE_AP_VLAN: |
| 2867 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2868 | return 0; |
| 2869 | break; |
| 2870 | case NL80211_IFTYPE_STATION: |
| 2871 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2872 | return 0; |
| 2873 | break; |
| 2874 | default: |
| 2875 | break; |
| 2876 | } |
| 2877 | |
| 2878 | return -EOPNOTSUPP; |
| 2879 | } |
| 2880 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2881 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2882 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2883 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2884 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2885 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2886 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2887 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2888 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2889 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2890 | memset(¶ms, 0, sizeof(params)); |
| 2891 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2892 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2893 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2894 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2895 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2896 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2897 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2898 | if (ntype > NL80211_IFTYPE_MAX) |
| 2899 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2900 | } |
| 2901 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2902 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2903 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2904 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2905 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2906 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2907 | if (netif_running(dev)) |
| 2908 | return -EBUSY; |
| 2909 | |
| 2910 | wdev_lock(wdev); |
| 2911 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2912 | IEEE80211_MAX_MESH_ID_LEN); |
| 2913 | wdev->mesh_id_up_len = |
| 2914 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2915 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2916 | wdev->mesh_id_up_len); |
| 2917 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2918 | } |
| 2919 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2920 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2921 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2922 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2923 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2924 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2925 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2926 | } else { |
| 2927 | params.use_4addr = -1; |
| 2928 | } |
| 2929 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2930 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 2931 | if (err < 0) |
| 2932 | return err; |
| 2933 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2934 | change = true; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2935 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2936 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2937 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2938 | else |
| 2939 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2940 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2941 | if (!err && params.use_4addr != -1) |
| 2942 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2943 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2944 | return err; |
| 2945 | } |
| 2946 | |
| 2947 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2948 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2949 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2950 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2951 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2952 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2953 | int err; |
| 2954 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 2955 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2956 | /* to avoid failing a new interface creation due to pending removal */ |
| 2957 | cfg80211_destroy_ifaces(rdev); |
| 2958 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2959 | memset(¶ms, 0, sizeof(params)); |
| 2960 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2961 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2962 | return -EINVAL; |
| 2963 | |
| 2964 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2965 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2966 | if (type > NL80211_IFTYPE_MAX) |
| 2967 | return -EINVAL; |
| 2968 | } |
| 2969 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2970 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2971 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2972 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2973 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2974 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2975 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2976 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2977 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2978 | ETH_ALEN); |
| 2979 | if (!is_valid_ether_addr(params.macaddr)) |
| 2980 | return -EADDRNOTAVAIL; |
| 2981 | } |
| 2982 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2983 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2984 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2985 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2986 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2987 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2988 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2989 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2990 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 2991 | if (err < 0) |
| 2992 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2993 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2994 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2995 | if (!msg) |
| 2996 | return -ENOMEM; |
| 2997 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2998 | wdev = rdev_add_virtual_intf(rdev, |
| 2999 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3000 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 3001 | if (WARN_ON(!wdev)) { |
| 3002 | nlmsg_free(msg); |
| 3003 | return -EPROTO; |
| 3004 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3005 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3006 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3007 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3008 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 3009 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3010 | wdev->owner_nlportid = info->snd_portid; |
| 3011 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3012 | switch (type) { |
| 3013 | case NL80211_IFTYPE_MESH_POINT: |
| 3014 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 3015 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3016 | wdev_lock(wdev); |
| 3017 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3018 | IEEE80211_MAX_MESH_ID_LEN); |
| 3019 | wdev->mesh_id_up_len = |
| 3020 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3021 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3022 | wdev->mesh_id_up_len); |
| 3023 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3024 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3025 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3026 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3027 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3028 | * 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] | 3029 | * through the netdev notifier and must be added here |
| 3030 | */ |
| 3031 | mutex_init(&wdev->mtx); |
| 3032 | INIT_LIST_HEAD(&wdev->event_list); |
| 3033 | spin_lock_init(&wdev->event_lock); |
| 3034 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 3035 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 3036 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3037 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3038 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3039 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3040 | break; |
| 3041 | default: |
| 3042 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3043 | } |
| 3044 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3045 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3046 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3047 | nlmsg_free(msg); |
| 3048 | return -ENOBUFS; |
| 3049 | } |
| 3050 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 3051 | /* |
| 3052 | * For wdevs which have no associated netdev object (e.g. of type |
| 3053 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. |
| 3054 | * For all other types, the event will be generated from the |
| 3055 | * netdev notifier |
| 3056 | */ |
| 3057 | if (!wdev->netdev) |
| 3058 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3059 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3060 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3064 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3066 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3067 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3068 | if (!rdev->ops->del_virtual_intf) |
| 3069 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3070 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3071 | /* |
| 3072 | * If we remove a wireless device without a netdev then clear |
| 3073 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3074 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3075 | * since the wdev has been freed, unlike with a netdev where |
| 3076 | * we need the dev_put() for the netdev to really be freed. |
| 3077 | */ |
| 3078 | if (!wdev->netdev) |
| 3079 | info->user_ptr[1] = NULL; |
| 3080 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 3081 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3082 | } |
| 3083 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3084 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3085 | { |
| 3086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3087 | struct net_device *dev = info->user_ptr[1]; |
| 3088 | u16 noack_map; |
| 3089 | |
| 3090 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3091 | return -EINVAL; |
| 3092 | |
| 3093 | if (!rdev->ops->set_noack_map) |
| 3094 | return -EOPNOTSUPP; |
| 3095 | |
| 3096 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3097 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3098 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3099 | } |
| 3100 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3101 | struct get_key_cookie { |
| 3102 | struct sk_buff *msg; |
| 3103 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3104 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3105 | }; |
| 3106 | |
| 3107 | static void get_key_callback(void *c, struct key_params *params) |
| 3108 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3109 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3110 | struct get_key_cookie *cookie = c; |
| 3111 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3112 | if ((params->key && |
| 3113 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3114 | params->key_len, params->key)) || |
| 3115 | (params->seq && |
| 3116 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3117 | params->seq_len, params->seq)) || |
| 3118 | (params->cipher && |
| 3119 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3120 | params->cipher))) |
| 3121 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3122 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3123 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 3124 | if (!key) |
| 3125 | goto nla_put_failure; |
| 3126 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3127 | if ((params->key && |
| 3128 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3129 | params->key_len, params->key)) || |
| 3130 | (params->seq && |
| 3131 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3132 | params->seq_len, params->seq)) || |
| 3133 | (params->cipher && |
| 3134 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3135 | params->cipher))) |
| 3136 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3137 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3138 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 3139 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3140 | |
| 3141 | nla_nest_end(cookie->msg, key); |
| 3142 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3143 | return; |
| 3144 | nla_put_failure: |
| 3145 | cookie->error = 1; |
| 3146 | } |
| 3147 | |
| 3148 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3149 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3151 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3152 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3153 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3154 | const u8 *mac_addr = NULL; |
| 3155 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3156 | struct get_key_cookie cookie = { |
| 3157 | .error = 0, |
| 3158 | }; |
| 3159 | void *hdr; |
| 3160 | struct sk_buff *msg; |
| 3161 | |
| 3162 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 3163 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 3164 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 3165 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3166 | return -EINVAL; |
| 3167 | |
| 3168 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3169 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3170 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3171 | pairwise = !!mac_addr; |
| 3172 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3173 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3174 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3175 | if (kt >= NUM_NL80211_KEYTYPES) |
| 3176 | return -EINVAL; |
| 3177 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3178 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3179 | return -EINVAL; |
| 3180 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3181 | } |
| 3182 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3183 | if (!rdev->ops->get_key) |
| 3184 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3185 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3186 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3187 | return -ENOENT; |
| 3188 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3189 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3190 | if (!msg) |
| 3191 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3192 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3193 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3194 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3195 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3196 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3197 | |
| 3198 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3199 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3200 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3201 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3202 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3203 | goto nla_put_failure; |
| 3204 | if (mac_addr && |
| 3205 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3206 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3207 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3208 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3209 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3210 | |
| 3211 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3212 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3213 | |
| 3214 | if (cookie.error) |
| 3215 | goto nla_put_failure; |
| 3216 | |
| 3217 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3218 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3219 | |
| 3220 | nla_put_failure: |
| 3221 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3222 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3223 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3224 | return err; |
| 3225 | } |
| 3226 | |
| 3227 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3228 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3230 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3231 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3232 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3233 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3234 | err = nl80211_parse_key(info, &key); |
| 3235 | if (err) |
| 3236 | return err; |
| 3237 | |
| 3238 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3239 | return -EINVAL; |
| 3240 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3241 | /* only support setting default key */ |
| 3242 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3243 | return -EINVAL; |
| 3244 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3245 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3246 | |
| 3247 | if (key.def) { |
| 3248 | if (!rdev->ops->set_default_key) { |
| 3249 | err = -EOPNOTSUPP; |
| 3250 | goto out; |
| 3251 | } |
| 3252 | |
| 3253 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3254 | if (err) |
| 3255 | goto out; |
| 3256 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3257 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3258 | key.def_uni, key.def_multi); |
| 3259 | |
| 3260 | if (err) |
| 3261 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3262 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3263 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3264 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3265 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3266 | } else { |
| 3267 | if (key.def_uni || !key.def_multi) { |
| 3268 | err = -EINVAL; |
| 3269 | goto out; |
| 3270 | } |
| 3271 | |
| 3272 | if (!rdev->ops->set_default_mgmt_key) { |
| 3273 | err = -EOPNOTSUPP; |
| 3274 | goto out; |
| 3275 | } |
| 3276 | |
| 3277 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3278 | if (err) |
| 3279 | goto out; |
| 3280 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3281 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3282 | if (err) |
| 3283 | goto out; |
| 3284 | |
| 3285 | #ifdef CONFIG_CFG80211_WEXT |
| 3286 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3287 | #endif |
| 3288 | } |
| 3289 | |
| 3290 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3291 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3292 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3293 | return err; |
| 3294 | } |
| 3295 | |
| 3296 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3297 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3298 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3299 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3300 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3301 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3302 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3303 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3304 | err = nl80211_parse_key(info, &key); |
| 3305 | if (err) |
| 3306 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3307 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3308 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3309 | return -EINVAL; |
| 3310 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3311 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3312 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3313 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3314 | if (key.type == -1) { |
| 3315 | if (mac_addr) |
| 3316 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3317 | else |
| 3318 | key.type = NL80211_KEYTYPE_GROUP; |
| 3319 | } |
| 3320 | |
| 3321 | /* for now */ |
| 3322 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3323 | key.type != NL80211_KEYTYPE_GROUP) |
| 3324 | return -EINVAL; |
| 3325 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3326 | if (!rdev->ops->add_key) |
| 3327 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3328 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3329 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3330 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3331 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3332 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3333 | |
| 3334 | wdev_lock(dev->ieee80211_ptr); |
| 3335 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3336 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3337 | err = rdev_add_key(rdev, dev, key.idx, |
| 3338 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3339 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3340 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3341 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3342 | return err; |
| 3343 | } |
| 3344 | |
| 3345 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3346 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3347 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3348 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3349 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3350 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3351 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3352 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3353 | err = nl80211_parse_key(info, &key); |
| 3354 | if (err) |
| 3355 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3356 | |
| 3357 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3358 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3359 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3360 | if (key.type == -1) { |
| 3361 | if (mac_addr) |
| 3362 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3363 | else |
| 3364 | key.type = NL80211_KEYTYPE_GROUP; |
| 3365 | } |
| 3366 | |
| 3367 | /* for now */ |
| 3368 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3369 | key.type != NL80211_KEYTYPE_GROUP) |
| 3370 | return -EINVAL; |
| 3371 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3372 | if (!rdev->ops->del_key) |
| 3373 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3374 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3375 | wdev_lock(dev->ieee80211_ptr); |
| 3376 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3377 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3378 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3379 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3380 | err = -ENOENT; |
| 3381 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3382 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3383 | err = rdev_del_key(rdev, dev, key.idx, |
| 3384 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3385 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3386 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3387 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3388 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3389 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3390 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3391 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3392 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3393 | } |
| 3394 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3395 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3396 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3397 | return err; |
| 3398 | } |
| 3399 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3400 | /* This function returns an error or the number of nested attributes */ |
| 3401 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3402 | { |
| 3403 | struct nlattr *attr; |
| 3404 | int n_entries = 0, tmp; |
| 3405 | |
| 3406 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3407 | if (nla_len(attr) != ETH_ALEN) |
| 3408 | return -EINVAL; |
| 3409 | |
| 3410 | n_entries++; |
| 3411 | } |
| 3412 | |
| 3413 | return n_entries; |
| 3414 | } |
| 3415 | |
| 3416 | /* |
| 3417 | * This function parses ACL information and allocates memory for ACL data. |
| 3418 | * On successful return, the calling function is responsible to free the |
| 3419 | * ACL buffer returned by this function. |
| 3420 | */ |
| 3421 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3422 | struct genl_info *info) |
| 3423 | { |
| 3424 | enum nl80211_acl_policy acl_policy; |
| 3425 | struct nlattr *attr; |
| 3426 | struct cfg80211_acl_data *acl; |
| 3427 | int i = 0, n_entries, tmp; |
| 3428 | |
| 3429 | if (!wiphy->max_acl_mac_addrs) |
| 3430 | return ERR_PTR(-EOPNOTSUPP); |
| 3431 | |
| 3432 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3433 | return ERR_PTR(-EINVAL); |
| 3434 | |
| 3435 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3436 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3437 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3438 | return ERR_PTR(-EINVAL); |
| 3439 | |
| 3440 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3441 | return ERR_PTR(-EINVAL); |
| 3442 | |
| 3443 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3444 | if (n_entries < 0) |
| 3445 | return ERR_PTR(n_entries); |
| 3446 | |
| 3447 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3448 | return ERR_PTR(-ENOTSUPP); |
| 3449 | |
| 3450 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3451 | GFP_KERNEL); |
| 3452 | if (!acl) |
| 3453 | return ERR_PTR(-ENOMEM); |
| 3454 | |
| 3455 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3456 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3457 | i++; |
| 3458 | } |
| 3459 | |
| 3460 | acl->n_acl_entries = n_entries; |
| 3461 | acl->acl_policy = acl_policy; |
| 3462 | |
| 3463 | return acl; |
| 3464 | } |
| 3465 | |
| 3466 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3467 | { |
| 3468 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3469 | struct net_device *dev = info->user_ptr[1]; |
| 3470 | struct cfg80211_acl_data *acl; |
| 3471 | int err; |
| 3472 | |
| 3473 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3474 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3475 | return -EOPNOTSUPP; |
| 3476 | |
| 3477 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3478 | return -EINVAL; |
| 3479 | |
| 3480 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3481 | if (IS_ERR(acl)) |
| 3482 | return PTR_ERR(acl); |
| 3483 | |
| 3484 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3485 | |
| 3486 | kfree(acl); |
| 3487 | |
| 3488 | return err; |
| 3489 | } |
| 3490 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3491 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3492 | u8 *rates, u8 rates_len) |
| 3493 | { |
| 3494 | u8 i; |
| 3495 | u32 mask = 0; |
| 3496 | |
| 3497 | for (i = 0; i < rates_len; i++) { |
| 3498 | int rate = (rates[i] & 0x7f) * 5; |
| 3499 | int ridx; |
| 3500 | |
| 3501 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 3502 | struct ieee80211_rate *srate = |
| 3503 | &sband->bitrates[ridx]; |
| 3504 | if (rate == srate->bitrate) { |
| 3505 | mask |= 1 << ridx; |
| 3506 | break; |
| 3507 | } |
| 3508 | } |
| 3509 | if (ridx == sband->n_bitrates) |
| 3510 | return 0; /* rate not found */ |
| 3511 | } |
| 3512 | |
| 3513 | return mask; |
| 3514 | } |
| 3515 | |
| 3516 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3517 | u8 *rates, u8 rates_len, |
| 3518 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 3519 | { |
| 3520 | u8 i; |
| 3521 | |
| 3522 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 3523 | |
| 3524 | for (i = 0; i < rates_len; i++) { |
| 3525 | int ridx, rbit; |
| 3526 | |
| 3527 | ridx = rates[i] / 8; |
| 3528 | rbit = BIT(rates[i] % 8); |
| 3529 | |
| 3530 | /* check validity */ |
| 3531 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 3532 | return false; |
| 3533 | |
| 3534 | /* check availability */ |
| 3535 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 3536 | mcs[ridx] |= rbit; |
| 3537 | else |
| 3538 | return false; |
| 3539 | } |
| 3540 | |
| 3541 | return true; |
| 3542 | } |
| 3543 | |
| 3544 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 3545 | { |
| 3546 | u16 mcs_mask = 0; |
| 3547 | |
| 3548 | switch (vht_mcs_map) { |
| 3549 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 3550 | break; |
| 3551 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 3552 | mcs_mask = 0x00FF; |
| 3553 | break; |
| 3554 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 3555 | mcs_mask = 0x01FF; |
| 3556 | break; |
| 3557 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 3558 | mcs_mask = 0x03FF; |
| 3559 | break; |
| 3560 | default: |
| 3561 | break; |
| 3562 | } |
| 3563 | |
| 3564 | return mcs_mask; |
| 3565 | } |
| 3566 | |
| 3567 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 3568 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 3569 | { |
| 3570 | u8 nss; |
| 3571 | |
| 3572 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 3573 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 3574 | vht_mcs_map >>= 2; |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 3579 | struct nl80211_txrate_vht *txrate, |
| 3580 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 3581 | { |
| 3582 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3583 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 3584 | u8 i; |
| 3585 | |
| 3586 | if (!sband->vht_cap.vht_supported) |
| 3587 | return false; |
| 3588 | |
| 3589 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 3590 | |
| 3591 | /* Build vht_mcs_mask from VHT capabilities */ |
| 3592 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 3593 | |
| 3594 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 3595 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 3596 | mcs[i] = txrate->mcs[i]; |
| 3597 | else |
| 3598 | return false; |
| 3599 | } |
| 3600 | |
| 3601 | return true; |
| 3602 | } |
| 3603 | |
| 3604 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 3605 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 3606 | .len = NL80211_MAX_SUPP_RATES }, |
| 3607 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 3608 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 3609 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
| 3610 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 3611 | }; |
| 3612 | |
| 3613 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| 3614 | struct cfg80211_bitrate_mask *mask) |
| 3615 | { |
| 3616 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 3617 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3618 | int rem, i; |
| 3619 | struct nlattr *tx_rates; |
| 3620 | struct ieee80211_supported_band *sband; |
| 3621 | u16 vht_tx_mcs_map; |
| 3622 | |
| 3623 | memset(mask, 0, sizeof(*mask)); |
| 3624 | /* Default to all rates enabled */ |
| 3625 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 3626 | sband = rdev->wiphy.bands[i]; |
| 3627 | |
| 3628 | if (!sband) |
| 3629 | continue; |
| 3630 | |
| 3631 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 3632 | memcpy(mask->control[i].ht_mcs, |
| 3633 | sband->ht_cap.mcs.rx_mask, |
| 3634 | sizeof(mask->control[i].ht_mcs)); |
| 3635 | |
| 3636 | if (!sband->vht_cap.vht_supported) |
| 3637 | continue; |
| 3638 | |
| 3639 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3640 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 3641 | } |
| 3642 | |
| 3643 | /* if no rates are given set it back to the defaults */ |
| 3644 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 3645 | goto out; |
| 3646 | |
| 3647 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 3648 | * directly to the enum nl80211_band values used in cfg80211. |
| 3649 | */ |
| 3650 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| 3651 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
| 3652 | enum nl80211_band band = nla_type(tx_rates); |
| 3653 | int err; |
| 3654 | |
| 3655 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 3656 | return -EINVAL; |
| 3657 | sband = rdev->wiphy.bands[band]; |
| 3658 | if (sband == NULL) |
| 3659 | return -EINVAL; |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 3660 | err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 3661 | nl80211_txattr_policy, info->extack); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3662 | if (err) |
| 3663 | return err; |
| 3664 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 3665 | mask->control[band].legacy = rateset_to_mask( |
| 3666 | sband, |
| 3667 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 3668 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 3669 | if ((mask->control[band].legacy == 0) && |
| 3670 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 3671 | return -EINVAL; |
| 3672 | } |
| 3673 | if (tb[NL80211_TXRATE_HT]) { |
| 3674 | if (!ht_rateset_to_mask( |
| 3675 | sband, |
| 3676 | nla_data(tb[NL80211_TXRATE_HT]), |
| 3677 | nla_len(tb[NL80211_TXRATE_HT]), |
| 3678 | mask->control[band].ht_mcs)) |
| 3679 | return -EINVAL; |
| 3680 | } |
| 3681 | if (tb[NL80211_TXRATE_VHT]) { |
| 3682 | if (!vht_set_mcs_mask( |
| 3683 | sband, |
| 3684 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 3685 | mask->control[band].vht_mcs)) |
| 3686 | return -EINVAL; |
| 3687 | } |
| 3688 | if (tb[NL80211_TXRATE_GI]) { |
| 3689 | mask->control[band].gi = |
| 3690 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 3691 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 3692 | return -EINVAL; |
| 3693 | } |
| 3694 | |
| 3695 | if (mask->control[band].legacy == 0) { |
| 3696 | /* don't allow empty legacy rates if HT or VHT |
| 3697 | * are not even supported. |
| 3698 | */ |
| 3699 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 3700 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 3701 | return -EINVAL; |
| 3702 | |
| 3703 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 3704 | if (mask->control[band].ht_mcs[i]) |
| 3705 | goto out; |
| 3706 | |
| 3707 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 3708 | if (mask->control[band].vht_mcs[i]) |
| 3709 | goto out; |
| 3710 | |
| 3711 | /* legacy and mcs rates may not be both empty */ |
| 3712 | return -EINVAL; |
| 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | out: |
| 3717 | return 0; |
| 3718 | } |
| 3719 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3720 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 3721 | enum nl80211_band band, |
| 3722 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3723 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3724 | u32 count_ht, count_vht, i; |
| 3725 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3726 | |
| 3727 | /* Allow only one rate */ |
| 3728 | if (hweight32(rate) > 1) |
| 3729 | return -EINVAL; |
| 3730 | |
| 3731 | count_ht = 0; |
| 3732 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3733 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3734 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3735 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3736 | count_ht++; |
| 3737 | if (count_ht > 1) |
| 3738 | return -EINVAL; |
| 3739 | } |
| 3740 | if (count_ht && rate) |
| 3741 | return -EINVAL; |
| 3742 | } |
| 3743 | |
| 3744 | count_vht = 0; |
| 3745 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3746 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3747 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3748 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3749 | count_vht++; |
| 3750 | if (count_vht > 1) |
| 3751 | return -EINVAL; |
| 3752 | } |
| 3753 | if (count_vht && rate) |
| 3754 | return -EINVAL; |
| 3755 | } |
| 3756 | |
| 3757 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 3758 | return -EINVAL; |
| 3759 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3760 | if (rate && |
| 3761 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3762 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 3763 | return -EINVAL; |
| 3764 | if (count_ht && |
| 3765 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3766 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 3767 | return -EINVAL; |
| 3768 | if (count_vht && |
| 3769 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3770 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 3771 | return -EINVAL; |
| 3772 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3773 | return 0; |
| 3774 | } |
| 3775 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3776 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3777 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3778 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3779 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3780 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3781 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3782 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3783 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3784 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3785 | return -EINVAL; |
| 3786 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3787 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3788 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3789 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3790 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3791 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3792 | if (!bcn->head_len) |
| 3793 | return -EINVAL; |
| 3794 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3795 | } |
| 3796 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3797 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3798 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3799 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3800 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3801 | } |
| 3802 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3803 | if (!haveinfo) |
| 3804 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3805 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3806 | if (attrs[NL80211_ATTR_IE]) { |
| 3807 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3808 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3809 | } |
| 3810 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3811 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3812 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3813 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3814 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3815 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3816 | } |
| 3817 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3818 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3819 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3820 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3821 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3822 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3823 | } |
| 3824 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3825 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3826 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3827 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3828 | } |
| 3829 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3830 | return 0; |
| 3831 | } |
| 3832 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 3833 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 3834 | const u8 *rates) |
| 3835 | { |
| 3836 | int i; |
| 3837 | |
| 3838 | if (!rates) |
| 3839 | return; |
| 3840 | |
| 3841 | for (i = 0; i < rates[1]; i++) { |
| 3842 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 3843 | params->ht_required = true; |
| 3844 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 3845 | params->vht_required = true; |
| 3846 | } |
| 3847 | } |
| 3848 | |
| 3849 | /* |
| 3850 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 3851 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 3852 | * benefit of drivers that rebuild IEs in the firmware. |
| 3853 | */ |
| 3854 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 3855 | { |
| 3856 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
Igor Mitsyanko | ba83bfb | 2017-08-30 13:52:25 -0700 | [diff] [blame] | 3857 | size_t ies_len = bcn->tail_len; |
| 3858 | const u8 *ies = bcn->tail; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 3859 | const u8 *rates; |
| 3860 | const u8 *cap; |
| 3861 | |
| 3862 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 3863 | nl80211_check_ap_rate_selectors(params, rates); |
| 3864 | |
| 3865 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 3866 | nl80211_check_ap_rate_selectors(params, rates); |
| 3867 | |
| 3868 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 3869 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 3870 | params->ht_cap = (void *)(cap + 2); |
| 3871 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 3872 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 3873 | params->vht_cap = (void *)(cap + 2); |
| 3874 | } |
| 3875 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3876 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3877 | struct cfg80211_ap_settings *params) |
| 3878 | { |
| 3879 | struct wireless_dev *wdev; |
| 3880 | bool ret = false; |
| 3881 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3882 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3883 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3884 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3885 | continue; |
| 3886 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3887 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3888 | continue; |
| 3889 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3890 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3891 | ret = true; |
| 3892 | break; |
| 3893 | } |
| 3894 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3895 | return ret; |
| 3896 | } |
| 3897 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3898 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3899 | enum nl80211_auth_type auth_type, |
| 3900 | enum nl80211_commands cmd) |
| 3901 | { |
| 3902 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3903 | return false; |
| 3904 | |
| 3905 | switch (cmd) { |
| 3906 | case NL80211_CMD_AUTHENTICATE: |
| 3907 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3908 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3909 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3910 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3911 | NL80211_EXT_FEATURE_FILS_STA) && |
| 3912 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3913 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3914 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 3915 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3916 | return true; |
| 3917 | case NL80211_CMD_CONNECT: |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 3918 | /* SAE not supported yet */ |
| 3919 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3920 | return false; |
| 3921 | /* FILS with SK PFS or PK not supported yet */ |
| 3922 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3923 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3924 | return false; |
| 3925 | if (!wiphy_ext_feature_isset( |
| 3926 | &rdev->wiphy, |
| 3927 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 3928 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 3929 | return false; |
| 3930 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3931 | case NL80211_CMD_START_AP: |
| 3932 | /* SAE not supported yet */ |
| 3933 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3934 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3935 | /* FILS not supported yet */ |
| 3936 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3937 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3938 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3939 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3940 | return true; |
| 3941 | default: |
| 3942 | return false; |
| 3943 | } |
| 3944 | } |
| 3945 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3946 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3947 | { |
| 3948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3949 | struct net_device *dev = info->user_ptr[1]; |
| 3950 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3951 | struct cfg80211_ap_settings params; |
| 3952 | int err; |
| 3953 | |
| 3954 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3955 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3956 | return -EOPNOTSUPP; |
| 3957 | |
| 3958 | if (!rdev->ops->start_ap) |
| 3959 | return -EOPNOTSUPP; |
| 3960 | |
| 3961 | if (wdev->beacon_interval) |
| 3962 | return -EALREADY; |
| 3963 | |
| 3964 | memset(¶ms, 0, sizeof(params)); |
| 3965 | |
| 3966 | /* these are required for START_AP */ |
| 3967 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3968 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3969 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3970 | return -EINVAL; |
| 3971 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3972 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3973 | if (err) |
| 3974 | return err; |
| 3975 | |
| 3976 | params.beacon_interval = |
| 3977 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3978 | params.dtim_period = |
| 3979 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3980 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 3981 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 3982 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3983 | if (err) |
| 3984 | return err; |
| 3985 | |
| 3986 | /* |
| 3987 | * In theory, some of these attributes should be required here |
| 3988 | * but since they were not used when the command was originally |
| 3989 | * added, keep them optional for old user space programs to let |
| 3990 | * them continue to work with drivers that do not need the |
| 3991 | * additional information -- drivers must check! |
| 3992 | */ |
| 3993 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3994 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3995 | params.ssid_len = |
| 3996 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3997 | if (params.ssid_len == 0 || |
| 3998 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3999 | return -EINVAL; |
| 4000 | } |
| 4001 | |
| 4002 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 4003 | params.hidden_ssid = nla_get_u32( |
| 4004 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 4005 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 4006 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 4007 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 4008 | return -EINVAL; |
| 4009 | } |
| 4010 | |
| 4011 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 4012 | |
| 4013 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4014 | params.auth_type = nla_get_u32( |
| 4015 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4016 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 4017 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4018 | return -EINVAL; |
| 4019 | } else |
| 4020 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4021 | |
| 4022 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 4023 | NL80211_MAX_NR_CIPHER_SUITES); |
| 4024 | if (err) |
| 4025 | return err; |
| 4026 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 4027 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 4028 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 4029 | return -EOPNOTSUPP; |
| 4030 | params.inactivity_timeout = nla_get_u16( |
| 4031 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 4032 | } |
| 4033 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4034 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4035 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4036 | return -EINVAL; |
| 4037 | params.p2p_ctwindow = |
| 4038 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4039 | if (params.p2p_ctwindow > 127) |
| 4040 | return -EINVAL; |
| 4041 | if (params.p2p_ctwindow != 0 && |
| 4042 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4043 | return -EINVAL; |
| 4044 | } |
| 4045 | |
| 4046 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4047 | u8 tmp; |
| 4048 | |
| 4049 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4050 | return -EINVAL; |
| 4051 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4052 | if (tmp > 1) |
| 4053 | return -EINVAL; |
| 4054 | params.p2p_opp_ps = tmp; |
| 4055 | if (params.p2p_opp_ps != 0 && |
| 4056 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4057 | return -EINVAL; |
| 4058 | } |
| 4059 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4060 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4061 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 4062 | if (err) |
| 4063 | return err; |
| 4064 | } else if (wdev->preset_chandef.chan) { |
| 4065 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4066 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4067 | return -EINVAL; |
| 4068 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 4069 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 4070 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4071 | return -EINVAL; |
| 4072 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4073 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 4074 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); |
| 4075 | if (err) |
| 4076 | return err; |
| 4077 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4078 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 4079 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4080 | if (err) |
| 4081 | return err; |
| 4082 | } |
| 4083 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 4084 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 4085 | params.smps_mode = |
| 4086 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 4087 | switch (params.smps_mode) { |
| 4088 | case NL80211_SMPS_OFF: |
| 4089 | break; |
| 4090 | case NL80211_SMPS_STATIC: |
| 4091 | if (!(rdev->wiphy.features & |
| 4092 | NL80211_FEATURE_STATIC_SMPS)) |
| 4093 | return -EINVAL; |
| 4094 | break; |
| 4095 | case NL80211_SMPS_DYNAMIC: |
| 4096 | if (!(rdev->wiphy.features & |
| 4097 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 4098 | return -EINVAL; |
| 4099 | break; |
| 4100 | default: |
| 4101 | return -EINVAL; |
| 4102 | } |
| 4103 | } else { |
| 4104 | params.smps_mode = NL80211_SMPS_OFF; |
| 4105 | } |
| 4106 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 4107 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 4108 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 4109 | return -EOPNOTSUPP; |
| 4110 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 4111 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 4112 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 4113 | if (IS_ERR(params.acl)) |
| 4114 | return PTR_ERR(params.acl); |
| 4115 | } |
| 4116 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4117 | nl80211_calculate_ap_params(¶ms); |
| 4118 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4119 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4120 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4121 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4122 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4123 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 4124 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 4125 | wdev->ssid_len = params.ssid_len; |
| 4126 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4127 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4128 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4129 | |
| 4130 | kfree(params.acl); |
| 4131 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 4132 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4133 | } |
| 4134 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4135 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 4136 | { |
| 4137 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4138 | struct net_device *dev = info->user_ptr[1]; |
| 4139 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4140 | struct cfg80211_beacon_data params; |
| 4141 | int err; |
| 4142 | |
| 4143 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4144 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4145 | return -EOPNOTSUPP; |
| 4146 | |
| 4147 | if (!rdev->ops->change_beacon) |
| 4148 | return -EOPNOTSUPP; |
| 4149 | |
| 4150 | if (!wdev->beacon_interval) |
| 4151 | return -EINVAL; |
| 4152 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4153 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4154 | if (err) |
| 4155 | return err; |
| 4156 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4157 | wdev_lock(wdev); |
| 4158 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 4159 | wdev_unlock(wdev); |
| 4160 | |
| 4161 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | 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] | 4165 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4167 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4168 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 4169 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4170 | } |
| 4171 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4172 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 4173 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 4174 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 4175 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 4176 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 4177 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 4178 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4179 | }; |
| 4180 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4181 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4182 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4183 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4184 | { |
| 4185 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4186 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4187 | int flag; |
| 4188 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4189 | /* |
| 4190 | * Try parsing the new attribute first so userspace |
| 4191 | * can specify both for older kernels. |
| 4192 | */ |
| 4193 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 4194 | if (nla) { |
| 4195 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4196 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4197 | sta_flags = nla_data(nla); |
| 4198 | params->sta_flags_mask = sta_flags->mask; |
| 4199 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4200 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4201 | if ((params->sta_flags_mask | |
| 4202 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 4203 | return -EINVAL; |
| 4204 | return 0; |
| 4205 | } |
| 4206 | |
| 4207 | /* if present, parse the old attribute */ |
| 4208 | |
| 4209 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4210 | if (!nla) |
| 4211 | return 0; |
| 4212 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 4213 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 4214 | sta_flags_policy, info->extack)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4215 | return -EINVAL; |
| 4216 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4217 | /* |
| 4218 | * Only allow certain flags for interface types so that |
| 4219 | * other attributes are silently ignored. Remember that |
| 4220 | * this is backward compatibility code with old userspace |
| 4221 | * and shouldn't be hit in other cases anyway. |
| 4222 | */ |
| 4223 | switch (iftype) { |
| 4224 | case NL80211_IFTYPE_AP: |
| 4225 | case NL80211_IFTYPE_AP_VLAN: |
| 4226 | case NL80211_IFTYPE_P2P_GO: |
| 4227 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4228 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4229 | BIT(NL80211_STA_FLAG_WME) | |
| 4230 | BIT(NL80211_STA_FLAG_MFP); |
| 4231 | break; |
| 4232 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4233 | case NL80211_IFTYPE_STATION: |
| 4234 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4235 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4236 | break; |
| 4237 | case NL80211_IFTYPE_MESH_POINT: |
| 4238 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4239 | BIT(NL80211_STA_FLAG_MFP) | |
| 4240 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4241 | default: |
| 4242 | return -EINVAL; |
| 4243 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4244 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4245 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 4246 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4247 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4248 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4249 | /* no longer support new API additions in old API */ |
| 4250 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 4251 | return -EINVAL; |
| 4252 | } |
| 4253 | } |
| 4254 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4255 | return 0; |
| 4256 | } |
| 4257 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4258 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 4259 | int attr) |
| 4260 | { |
| 4261 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4262 | u32 bitrate; |
| 4263 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 4264 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4265 | |
| 4266 | rate = nla_nest_start(msg, attr); |
| 4267 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4268 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4269 | |
| 4270 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 4271 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4272 | /* report 16-bit bitrate only if we can */ |
| 4273 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4274 | if (bitrate > 0 && |
| 4275 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 4276 | return false; |
| 4277 | if (bitrate_compat > 0 && |
| 4278 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 4279 | return false; |
| 4280 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4281 | switch (info->bw) { |
| 4282 | case RATE_INFO_BW_5: |
| 4283 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 4284 | break; |
| 4285 | case RATE_INFO_BW_10: |
| 4286 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 4287 | break; |
| 4288 | default: |
| 4289 | WARN_ON(1); |
| 4290 | /* fall through */ |
| 4291 | case RATE_INFO_BW_20: |
| 4292 | rate_flg = 0; |
| 4293 | break; |
| 4294 | case RATE_INFO_BW_40: |
| 4295 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 4296 | break; |
| 4297 | case RATE_INFO_BW_80: |
| 4298 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 4299 | break; |
| 4300 | case RATE_INFO_BW_160: |
| 4301 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 4302 | break; |
| 4303 | } |
| 4304 | |
| 4305 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 4306 | return false; |
| 4307 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4308 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 4309 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 4310 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4311 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4312 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4313 | return false; |
| 4314 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 4315 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 4316 | return false; |
| 4317 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 4318 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4319 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4320 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4321 | return false; |
| 4322 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4323 | |
| 4324 | nla_nest_end(msg, rate); |
| 4325 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4326 | } |
| 4327 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4328 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 4329 | int id) |
| 4330 | { |
| 4331 | void *attr; |
| 4332 | int i = 0; |
| 4333 | |
| 4334 | if (!mask) |
| 4335 | return true; |
| 4336 | |
| 4337 | attr = nla_nest_start(msg, id); |
| 4338 | if (!attr) |
| 4339 | return false; |
| 4340 | |
| 4341 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 4342 | if (!(mask & BIT(i))) |
| 4343 | continue; |
| 4344 | |
| 4345 | if (nla_put_u8(msg, i, signal[i])) |
| 4346 | return false; |
| 4347 | } |
| 4348 | |
| 4349 | nla_nest_end(msg, attr); |
| 4350 | |
| 4351 | return true; |
| 4352 | } |
| 4353 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4354 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 4355 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4356 | struct cfg80211_registered_device *rdev, |
| 4357 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 4358 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4359 | { |
| 4360 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4361 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4362 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4363 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4364 | if (!hdr) |
| 4365 | return -1; |
| 4366 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4367 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4368 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 4369 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 4370 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4371 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4372 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 4373 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4374 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4375 | |
| 4376 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4377 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Mohammed Shafi Shajakhan | 739960f | 2016-04-07 19:59:34 +0530 | [diff] [blame] | 4378 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4379 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 4380 | sinfo->memb)) \ |
| 4381 | goto nla_put_failure; \ |
| 4382 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4383 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 4384 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
| 4385 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 4386 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 4387 | goto nla_put_failure; \ |
| 4388 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4389 | |
| 4390 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 4391 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 4392 | |
| 4393 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 4394 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4395 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4396 | (u32)sinfo->rx_bytes)) |
| 4397 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4398 | |
| 4399 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 4400 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4401 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 4402 | (u32)sinfo->tx_bytes)) |
| 4403 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4404 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4405 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 4406 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4407 | PUT_SINFO(LLID, llid, u16); |
| 4408 | PUT_SINFO(PLID, plid, u16); |
| 4409 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4410 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4411 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4412 | switch (rdev->wiphy.signal_type) { |
| 4413 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4414 | PUT_SINFO(SIGNAL, signal, u8); |
| 4415 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4416 | break; |
| 4417 | default: |
| 4418 | break; |
| 4419 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4420 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4421 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4422 | sinfo->chain_signal, |
| 4423 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 4424 | goto nla_put_failure; |
| 4425 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4426 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4427 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4428 | sinfo->chain_signal_avg, |
| 4429 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 4430 | goto nla_put_failure; |
| 4431 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4432 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4433 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 4434 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4435 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4436 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4437 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4438 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 4439 | NL80211_STA_INFO_RX_BITRATE)) |
| 4440 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4441 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4442 | |
| 4443 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 4444 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 4445 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 4446 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 4447 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 4448 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 4449 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 4450 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 4451 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 4452 | |
| 4453 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4454 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 4455 | if (!bss_param) |
| 4456 | goto nla_put_failure; |
| 4457 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4458 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 4459 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 4460 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 4461 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 4462 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 4463 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 4464 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 4465 | sinfo->bss_param.dtim_period) || |
| 4466 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 4467 | sinfo->bss_param.beacon_interval)) |
| 4468 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4469 | |
| 4470 | nla_nest_end(msg, bss_param); |
| 4471 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4472 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4473 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 4474 | sizeof(struct nl80211_sta_flag_update), |
| 4475 | &sinfo->sta_flags)) |
| 4476 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4477 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4478 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 4479 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 4480 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 4481 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4482 | |
| 4483 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4484 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4485 | |
| 4486 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 4487 | struct nlattr *tidsattr; |
| 4488 | int tid; |
| 4489 | |
| 4490 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 4491 | if (!tidsattr) |
| 4492 | goto nla_put_failure; |
| 4493 | |
| 4494 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 4495 | struct cfg80211_tid_stats *tidstats; |
| 4496 | struct nlattr *tidattr; |
| 4497 | |
| 4498 | tidstats = &sinfo->pertid[tid]; |
| 4499 | |
| 4500 | if (!tidstats->filled) |
| 4501 | continue; |
| 4502 | |
| 4503 | tidattr = nla_nest_start(msg, tid + 1); |
| 4504 | if (!tidattr) |
| 4505 | goto nla_put_failure; |
| 4506 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4507 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4508 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4509 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 4510 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4511 | goto nla_put_failure; \ |
| 4512 | } while (0) |
| 4513 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4514 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 4515 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 4516 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 4517 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4518 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4519 | #undef PUT_TIDVAL_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4520 | nla_nest_end(msg, tidattr); |
| 4521 | } |
| 4522 | |
| 4523 | nla_nest_end(msg, tidsattr); |
| 4524 | } |
| 4525 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4526 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4527 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4528 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4529 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 4530 | sinfo->assoc_req_ies)) |
| 4531 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 4532 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4533 | genlmsg_end(msg, hdr); |
| 4534 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4535 | |
| 4536 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4537 | genlmsg_cancel(msg, hdr); |
| 4538 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4539 | } |
| 4540 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4541 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4542 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4543 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4544 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4545 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4546 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4547 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4548 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4549 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4550 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4551 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4552 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4553 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4554 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4555 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4556 | if (!wdev->netdev) { |
| 4557 | err = -EINVAL; |
| 4558 | goto out_err; |
| 4559 | } |
| 4560 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4561 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4562 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4563 | goto out_err; |
| 4564 | } |
| 4565 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4566 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 4567 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4568 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4569 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4570 | if (err == -ENOENT) |
| 4571 | break; |
| 4572 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4573 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4574 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4575 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4576 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4577 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4578 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4579 | &sinfo) < 0) |
| 4580 | goto out; |
| 4581 | |
| 4582 | sta_idx++; |
| 4583 | } |
| 4584 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4585 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4586 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4587 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4588 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4589 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4590 | |
| 4591 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4592 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4593 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4594 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4595 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4596 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4597 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4598 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4599 | struct sk_buff *msg; |
| 4600 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4601 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4602 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4603 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4604 | |
| 4605 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4606 | return -EINVAL; |
| 4607 | |
| 4608 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4609 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4610 | if (!rdev->ops->get_station) |
| 4611 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4612 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4613 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4614 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4615 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4616 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4617 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4618 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4619 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4620 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4621 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4622 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4623 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4624 | nlmsg_free(msg); |
| 4625 | return -ENOBUFS; |
| 4626 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4627 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4628 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4629 | } |
| 4630 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4631 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4632 | struct station_parameters *params, |
| 4633 | enum cfg80211_station_type statype) |
| 4634 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4635 | if (params->listen_interval != -1 && |
| 4636 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4637 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4638 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4639 | if (params->support_p2p_ps != -1 && |
| 4640 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4641 | return -EINVAL; |
| 4642 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4643 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4644 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4645 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4646 | return -EINVAL; |
| 4647 | |
| 4648 | /* When you run into this, adjust the code below for the new flag */ |
| 4649 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4650 | |
| 4651 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4652 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4653 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4654 | /* |
| 4655 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4656 | * code doesn't have the bug of including TDLS in the |
| 4657 | * mask everywhere. |
| 4658 | */ |
| 4659 | if (params->sta_flags_mask & |
| 4660 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4661 | BIT(NL80211_STA_FLAG_MFP) | |
| 4662 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4663 | return -EINVAL; |
| 4664 | break; |
| 4665 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4666 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4667 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4668 | return -EINVAL; |
| 4669 | /* ignore since it can't change */ |
| 4670 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4671 | break; |
| 4672 | default: |
| 4673 | /* disallow mesh-specific things */ |
| 4674 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4675 | return -EINVAL; |
| 4676 | if (params->local_pm) |
| 4677 | return -EINVAL; |
| 4678 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4679 | return -EINVAL; |
| 4680 | } |
| 4681 | |
| 4682 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4683 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4684 | /* TDLS can't be set, ... */ |
| 4685 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4686 | return -EINVAL; |
| 4687 | /* |
| 4688 | * ... but don't bother the driver with it. This works around |
| 4689 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4690 | * TLDS_PEER flag in the mask even for AP mode. |
| 4691 | */ |
| 4692 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4693 | } |
| 4694 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4695 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4696 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4697 | /* reject other things that can't change */ |
| 4698 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4699 | return -EINVAL; |
| 4700 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4701 | return -EINVAL; |
| 4702 | if (params->supported_rates) |
| 4703 | return -EINVAL; |
| 4704 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4705 | return -EINVAL; |
| 4706 | } |
| 4707 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4708 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4709 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4710 | if (params->vlan) |
| 4711 | return -EINVAL; |
| 4712 | } |
| 4713 | |
| 4714 | switch (statype) { |
| 4715 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4716 | /* Use this only for authorizing/unauthorizing a station */ |
| 4717 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4718 | return -EOPNOTSUPP; |
| 4719 | break; |
| 4720 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4721 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4722 | /* accept only the listed bits */ |
| 4723 | if (params->sta_flags_mask & |
| 4724 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4725 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4726 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4727 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4728 | BIT(NL80211_STA_FLAG_WME) | |
| 4729 | BIT(NL80211_STA_FLAG_MFP))) |
| 4730 | return -EINVAL; |
| 4731 | |
| 4732 | /* but authenticated/associated only if driver handles it */ |
| 4733 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4734 | params->sta_flags_mask & |
| 4735 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4736 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4737 | return -EINVAL; |
| 4738 | break; |
| 4739 | case CFG80211_STA_IBSS: |
| 4740 | case CFG80211_STA_AP_STA: |
| 4741 | /* reject any changes other than AUTHORIZED */ |
| 4742 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4743 | return -EINVAL; |
| 4744 | break; |
| 4745 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4746 | /* reject any changes other than AUTHORIZED or WME */ |
| 4747 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4748 | BIT(NL80211_STA_FLAG_WME))) |
| 4749 | return -EINVAL; |
| 4750 | /* force (at least) rates when authorizing */ |
| 4751 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4752 | !params->supported_rates) |
| 4753 | return -EINVAL; |
| 4754 | break; |
| 4755 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4756 | /* reject any changes */ |
| 4757 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4758 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4759 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4760 | return -EINVAL; |
| 4761 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4762 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4763 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4764 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4765 | return -EINVAL; |
| 4766 | break; |
| 4767 | } |
| 4768 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 4769 | /* |
| 4770 | * Older kernel versions ignored this attribute entirely, so don't |
| 4771 | * reject attempts to update it but mark it as unused instead so the |
| 4772 | * driver won't look at the data. |
| 4773 | */ |
| 4774 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 4775 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 4776 | params->opmode_notif_used = false; |
| 4777 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4778 | return 0; |
| 4779 | } |
| 4780 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4781 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4782 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4783 | * 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] | 4784 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4785 | static struct net_device *get_vlan(struct genl_info *info, |
| 4786 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4787 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4788 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4789 | struct net_device *v; |
| 4790 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4791 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4792 | if (!vlanattr) |
| 4793 | return NULL; |
| 4794 | |
| 4795 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4796 | if (!v) |
| 4797 | return ERR_PTR(-ENODEV); |
| 4798 | |
| 4799 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4800 | ret = -EINVAL; |
| 4801 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4802 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4803 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4804 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4805 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4806 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4807 | ret = -EINVAL; |
| 4808 | goto error; |
| 4809 | } |
| 4810 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4811 | if (!netif_running(v)) { |
| 4812 | ret = -ENETDOWN; |
| 4813 | goto error; |
| 4814 | } |
| 4815 | |
| 4816 | return v; |
| 4817 | error: |
| 4818 | dev_put(v); |
| 4819 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4820 | } |
| 4821 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4822 | static const struct nla_policy |
| 4823 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4824 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4825 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4826 | }; |
| 4827 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4828 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4829 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4830 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4831 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4832 | struct nlattr *nla; |
| 4833 | int err; |
| 4834 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4835 | /* parse WME attributes if present */ |
| 4836 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4837 | return 0; |
| 4838 | |
| 4839 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4840 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 4841 | nl80211_sta_wme_policy, info->extack); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4842 | if (err) |
| 4843 | return err; |
| 4844 | |
| 4845 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4846 | params->uapsd_queues = nla_get_u8( |
| 4847 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4848 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4849 | return -EINVAL; |
| 4850 | |
| 4851 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4852 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4853 | |
| 4854 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4855 | return -EINVAL; |
| 4856 | |
| 4857 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4858 | |
| 4859 | return 0; |
| 4860 | } |
| 4861 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4862 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4863 | struct station_parameters *params) |
| 4864 | { |
| 4865 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4866 | params->supported_channels = |
| 4867 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4868 | params->supported_channels_len = |
| 4869 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4870 | /* |
| 4871 | * Need to include at least one (first channel, number of |
| 4872 | * channels) tuple for each subband, and must have proper |
| 4873 | * tuples for the rest of the data as well. |
| 4874 | */ |
| 4875 | if (params->supported_channels_len < 2) |
| 4876 | return -EINVAL; |
| 4877 | if (params->supported_channels_len % 2) |
| 4878 | return -EINVAL; |
| 4879 | } |
| 4880 | |
| 4881 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4882 | params->supported_oper_classes = |
| 4883 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4884 | params->supported_oper_classes_len = |
| 4885 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4886 | /* |
| 4887 | * The value of the Length field of the Supported Operating |
| 4888 | * Classes element is between 2 and 253. |
| 4889 | */ |
| 4890 | if (params->supported_oper_classes_len < 2 || |
| 4891 | params->supported_oper_classes_len > 253) |
| 4892 | return -EINVAL; |
| 4893 | } |
| 4894 | return 0; |
| 4895 | } |
| 4896 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4897 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4898 | struct station_parameters *params) |
| 4899 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4900 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4901 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4902 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4903 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4904 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4905 | params->ht_capa = |
| 4906 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4907 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4908 | params->vht_capa = |
| 4909 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4910 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4911 | err = nl80211_parse_sta_channel_info(info, params); |
| 4912 | if (err) |
| 4913 | return err; |
| 4914 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4915 | return nl80211_parse_sta_wme(info, params); |
| 4916 | } |
| 4917 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4918 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4919 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4920 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4921 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4922 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4923 | u8 *mac_addr; |
| 4924 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4925 | |
| 4926 | memset(¶ms, 0, sizeof(params)); |
| 4927 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4928 | if (!rdev->ops->change_station) |
| 4929 | return -EOPNOTSUPP; |
| 4930 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4931 | /* |
| 4932 | * AID and listen_interval properties can be set only for unassociated |
| 4933 | * station. Include these parameters here and will check them in |
| 4934 | * cfg80211_check_station_change(). |
| 4935 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4936 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4937 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4938 | |
| 4939 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4940 | params.listen_interval = |
| 4941 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4942 | else |
| 4943 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4944 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4945 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4946 | u8 tmp; |
| 4947 | |
| 4948 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4949 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4950 | return -EINVAL; |
| 4951 | |
| 4952 | params.support_p2p_ps = tmp; |
| 4953 | } else { |
| 4954 | params.support_p2p_ps = -1; |
| 4955 | } |
| 4956 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4957 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4958 | return -EINVAL; |
| 4959 | |
| 4960 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4961 | |
| 4962 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4963 | params.supported_rates = |
| 4964 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4965 | params.supported_rates_len = |
| 4966 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4967 | } |
| 4968 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4969 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4970 | params.capability = |
| 4971 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4972 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4973 | } |
| 4974 | |
| 4975 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4976 | params.ext_capab = |
| 4977 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4978 | params.ext_capab_len = |
| 4979 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4980 | } |
| 4981 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4982 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4983 | return -EINVAL; |
| 4984 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4985 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4986 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4987 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4988 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4989 | return -EINVAL; |
| 4990 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4991 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4992 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4993 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4994 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4995 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4996 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 4997 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 4998 | params.peer_aid = nla_get_u16( |
| 4999 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 5000 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 5001 | return -EINVAL; |
| 5002 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5003 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 5004 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 5005 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5006 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 5007 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 5008 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 5009 | |
| 5010 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 5011 | pm > NL80211_MESH_POWER_MAX) |
| 5012 | return -EINVAL; |
| 5013 | |
| 5014 | params.local_pm = pm; |
| 5015 | } |
| 5016 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 5017 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 5018 | params.opmode_notif_used = true; |
| 5019 | params.opmode_notif = |
| 5020 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 5021 | } |
| 5022 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5023 | /* Include parameters for TDLS peer (will check later) */ |
| 5024 | err = nl80211_set_station_tdls(info, ¶ms); |
| 5025 | if (err) |
| 5026 | return err; |
| 5027 | |
| 5028 | params.vlan = get_vlan(info, rdev); |
| 5029 | if (IS_ERR(params.vlan)) |
| 5030 | return PTR_ERR(params.vlan); |
| 5031 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5032 | switch (dev->ieee80211_ptr->iftype) { |
| 5033 | case NL80211_IFTYPE_AP: |
| 5034 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5035 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5036 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5037 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5038 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5039 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 5040 | break; |
| 5041 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5042 | err = -EOPNOTSUPP; |
| 5043 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 5044 | } |
| 5045 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5046 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5047 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5048 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5049 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5050 | if (params.vlan) |
| 5051 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5052 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5053 | return err; |
| 5054 | } |
| 5055 | |
| 5056 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 5057 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5058 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5059 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5060 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5061 | struct station_parameters params; |
| 5062 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5063 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5064 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5065 | |
| 5066 | memset(¶ms, 0, sizeof(params)); |
| 5067 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5068 | if (!rdev->ops->add_station) |
| 5069 | return -EOPNOTSUPP; |
| 5070 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5071 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5072 | return -EINVAL; |
| 5073 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5074 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 5075 | return -EINVAL; |
| 5076 | |
| 5077 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 5078 | return -EINVAL; |
| 5079 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5080 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 5081 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 5082 | return -EINVAL; |
| 5083 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5084 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5085 | params.supported_rates = |
| 5086 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5087 | params.supported_rates_len = |
| 5088 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5089 | params.listen_interval = |
| 5090 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5091 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5092 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 5093 | u8 tmp; |
| 5094 | |
| 5095 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 5096 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 5097 | return -EINVAL; |
| 5098 | |
| 5099 | params.support_p2p_ps = tmp; |
| 5100 | } else { |
| 5101 | /* |
| 5102 | * if not specified, assume it's supported for P2P GO interface, |
| 5103 | * and is NOT supported for AP interface |
| 5104 | */ |
| 5105 | params.support_p2p_ps = |
| 5106 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 5107 | } |
| 5108 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5109 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5110 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5111 | else |
| 5112 | 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] | 5113 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 5114 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5115 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 5116 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 5117 | params.capability = |
| 5118 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 5119 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 5120 | } |
| 5121 | |
| 5122 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 5123 | params.ext_capab = |
| 5124 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5125 | params.ext_capab_len = |
| 5126 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5127 | } |
| 5128 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 5129 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 5130 | params.ht_capa = |
| 5131 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5132 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 5133 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 5134 | params.vht_capa = |
| 5135 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 5136 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 5137 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 5138 | params.opmode_notif_used = true; |
| 5139 | params.opmode_notif = |
| 5140 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 5141 | } |
| 5142 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5143 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5144 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5145 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 5146 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 5147 | return -EINVAL; |
| 5148 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5149 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5150 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 5151 | if (err) |
| 5152 | return err; |
| 5153 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5154 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 5155 | if (err) |
| 5156 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5157 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5158 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5159 | return -EINVAL; |
| 5160 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 5161 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 5162 | * as userspace might just pass through the capabilities from the IEs |
| 5163 | * directly, rather than enforcing this restriction and returning an |
| 5164 | * error in this case. |
| 5165 | */ |
| 5166 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 5167 | params.ht_capa = NULL; |
| 5168 | params.vht_capa = NULL; |
| 5169 | } |
| 5170 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5171 | /* When you run into this, adjust the code below for the new flag */ |
| 5172 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5173 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5174 | switch (dev->ieee80211_ptr->iftype) { |
| 5175 | case NL80211_IFTYPE_AP: |
| 5176 | case NL80211_IFTYPE_AP_VLAN: |
| 5177 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5178 | /* ignore WME attributes if iface/sta is not capable */ |
| 5179 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 5180 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 5181 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5182 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5183 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5184 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5185 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5186 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5187 | /* but don't bother the driver with it */ |
| 5188 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5189 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5190 | /* allow authenticated/associated only if driver handles it */ |
| 5191 | if (!(rdev->wiphy.features & |
| 5192 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5193 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5194 | return -EINVAL; |
| 5195 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5196 | /* Older userspace, or userspace wanting to be compatible with |
| 5197 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 5198 | * and assoc flags in the mask, but assumes the station will be |
| 5199 | * added as associated anyway since this was the required driver |
| 5200 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 5201 | * introduced. |
| 5202 | * In order to not bother drivers with this quirk in the API |
| 5203 | * set the flags in both the mask and set for new stations in |
| 5204 | * this case. |
| 5205 | */ |
| 5206 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 5207 | params.sta_flags_mask |= auth_assoc; |
| 5208 | params.sta_flags_set |= auth_assoc; |
| 5209 | } |
| 5210 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5211 | /* must be last in here for error handling */ |
| 5212 | params.vlan = get_vlan(info, rdev); |
| 5213 | if (IS_ERR(params.vlan)) |
| 5214 | return PTR_ERR(params.vlan); |
| 5215 | break; |
| 5216 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5217 | /* ignore uAPSD data */ |
| 5218 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5219 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5220 | /* associated is disallowed */ |
| 5221 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 5222 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5223 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5224 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5225 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5226 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5227 | break; |
| 5228 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 5229 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5230 | /* ignore uAPSD data */ |
| 5231 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5232 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5233 | /* these are disallowed */ |
| 5234 | if (params.sta_flags_mask & |
| 5235 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5236 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5237 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5238 | /* Only TDLS peers can be added */ |
| 5239 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5240 | return -EINVAL; |
| 5241 | /* Can only add if TDLS ... */ |
| 5242 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 5243 | return -EOPNOTSUPP; |
| 5244 | /* ... with external setup is supported */ |
| 5245 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 5246 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5247 | /* |
| 5248 | * Older wpa_supplicant versions always mark the TDLS peer |
| 5249 | * as authorized, but it shouldn't yet be. |
| 5250 | */ |
| 5251 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5252 | break; |
| 5253 | default: |
| 5254 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5255 | } |
| 5256 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5257 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5258 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5259 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5260 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5261 | if (params.vlan) |
| 5262 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5263 | return err; |
| 5264 | } |
| 5265 | |
| 5266 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 5267 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5268 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5269 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5270 | struct station_del_parameters params; |
| 5271 | |
| 5272 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5273 | |
| 5274 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5275 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5276 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5277 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 5278 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5279 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5280 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5281 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5282 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5283 | if (!rdev->ops->del_station) |
| 5284 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5285 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 5286 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 5287 | params.subtype = |
| 5288 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 5289 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 5290 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 5291 | return -EINVAL; |
| 5292 | } else { |
| 5293 | /* Default to Deauthentication frame */ |
| 5294 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 5295 | } |
| 5296 | |
| 5297 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 5298 | params.reason_code = |
| 5299 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5300 | if (params.reason_code == 0) |
| 5301 | return -EINVAL; /* 0 is reserved */ |
| 5302 | } else { |
| 5303 | /* Default to reason code 2 */ |
| 5304 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 5305 | } |
| 5306 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5307 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5308 | } |
| 5309 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5310 | 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] | 5311 | int flags, struct net_device *dev, |
| 5312 | u8 *dst, u8 *next_hop, |
| 5313 | struct mpath_info *pinfo) |
| 5314 | { |
| 5315 | void *hdr; |
| 5316 | struct nlattr *pinfoattr; |
| 5317 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 5318 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5319 | if (!hdr) |
| 5320 | return -1; |
| 5321 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5322 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5323 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 5324 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 5325 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 5326 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5327 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5328 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 5329 | if (!pinfoattr) |
| 5330 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5331 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 5332 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 5333 | pinfo->frame_qlen)) |
| 5334 | goto nla_put_failure; |
| 5335 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 5336 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 5337 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 5338 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 5339 | pinfo->metric)) || |
| 5340 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 5341 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 5342 | pinfo->exptime)) || |
| 5343 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 5344 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 5345 | pinfo->flags)) || |
| 5346 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 5347 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 5348 | pinfo->discovery_timeout)) || |
| 5349 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 5350 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 5351 | pinfo->discovery_retries))) |
| 5352 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5353 | |
| 5354 | nla_nest_end(msg, pinfoattr); |
| 5355 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5356 | genlmsg_end(msg, hdr); |
| 5357 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5358 | |
| 5359 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5360 | genlmsg_cancel(msg, hdr); |
| 5361 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5362 | } |
| 5363 | |
| 5364 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5365 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5366 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5367 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5368 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5369 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5370 | u8 dst[ETH_ALEN]; |
| 5371 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5372 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5373 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5374 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5375 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5376 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5377 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5378 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5379 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5380 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5381 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5382 | goto out_err; |
| 5383 | } |
| 5384 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5385 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5386 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 5387 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5388 | } |
| 5389 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5390 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5391 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5392 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5393 | if (err == -ENOENT) |
| 5394 | break; |
| 5395 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5396 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5397 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5398 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5399 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5400 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5401 | &pinfo) < 0) |
| 5402 | goto out; |
| 5403 | |
| 5404 | path_idx++; |
| 5405 | } |
| 5406 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5407 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5408 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5409 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5410 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5411 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5412 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5416 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5417 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5418 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5419 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5420 | struct mpath_info pinfo; |
| 5421 | struct sk_buff *msg; |
| 5422 | u8 *dst = NULL; |
| 5423 | u8 next_hop[ETH_ALEN]; |
| 5424 | |
| 5425 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5426 | |
| 5427 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5428 | return -EINVAL; |
| 5429 | |
| 5430 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5431 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5432 | if (!rdev->ops->get_mpath) |
| 5433 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5434 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5435 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5436 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5437 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5438 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5439 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5440 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5441 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5442 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5443 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5444 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5445 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5446 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5447 | dev, dst, next_hop, &pinfo) < 0) { |
| 5448 | nlmsg_free(msg); |
| 5449 | return -ENOBUFS; |
| 5450 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5451 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5452 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5453 | } |
| 5454 | |
| 5455 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5456 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5458 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5459 | u8 *dst = NULL; |
| 5460 | u8 *next_hop = NULL; |
| 5461 | |
| 5462 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5463 | return -EINVAL; |
| 5464 | |
| 5465 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5466 | return -EINVAL; |
| 5467 | |
| 5468 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5469 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5470 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5471 | if (!rdev->ops->change_mpath) |
| 5472 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5473 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5474 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5475 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5476 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5477 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5478 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5479 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5480 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5481 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5483 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5484 | u8 *dst = NULL; |
| 5485 | u8 *next_hop = NULL; |
| 5486 | |
| 5487 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5488 | return -EINVAL; |
| 5489 | |
| 5490 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5491 | return -EINVAL; |
| 5492 | |
| 5493 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5494 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5495 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5496 | if (!rdev->ops->add_mpath) |
| 5497 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5498 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5499 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5500 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5501 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5502 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5503 | } |
| 5504 | |
| 5505 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5506 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5507 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5508 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5509 | u8 *dst = NULL; |
| 5510 | |
| 5511 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5512 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5513 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5514 | if (!rdev->ops->del_mpath) |
| 5515 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5516 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5517 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5518 | } |
| 5519 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5520 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 5521 | { |
| 5522 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5523 | int err; |
| 5524 | struct net_device *dev = info->user_ptr[1]; |
| 5525 | struct mpath_info pinfo; |
| 5526 | struct sk_buff *msg; |
| 5527 | u8 *dst = NULL; |
| 5528 | u8 mpp[ETH_ALEN]; |
| 5529 | |
| 5530 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5531 | |
| 5532 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5533 | return -EINVAL; |
| 5534 | |
| 5535 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5536 | |
| 5537 | if (!rdev->ops->get_mpp) |
| 5538 | return -EOPNOTSUPP; |
| 5539 | |
| 5540 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5541 | return -EOPNOTSUPP; |
| 5542 | |
| 5543 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 5544 | if (err) |
| 5545 | return err; |
| 5546 | |
| 5547 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5548 | if (!msg) |
| 5549 | return -ENOMEM; |
| 5550 | |
| 5551 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 5552 | dev, dst, mpp, &pinfo) < 0) { |
| 5553 | nlmsg_free(msg); |
| 5554 | return -ENOBUFS; |
| 5555 | } |
| 5556 | |
| 5557 | return genlmsg_reply(msg, info); |
| 5558 | } |
| 5559 | |
| 5560 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 5561 | struct netlink_callback *cb) |
| 5562 | { |
| 5563 | struct mpath_info pinfo; |
| 5564 | struct cfg80211_registered_device *rdev; |
| 5565 | struct wireless_dev *wdev; |
| 5566 | u8 dst[ETH_ALEN]; |
| 5567 | u8 mpp[ETH_ALEN]; |
| 5568 | int path_idx = cb->args[2]; |
| 5569 | int err; |
| 5570 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5571 | rtnl_lock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5572 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 5573 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5574 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5575 | |
| 5576 | if (!rdev->ops->dump_mpp) { |
| 5577 | err = -EOPNOTSUPP; |
| 5578 | goto out_err; |
| 5579 | } |
| 5580 | |
| 5581 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5582 | err = -EOPNOTSUPP; |
| 5583 | goto out_err; |
| 5584 | } |
| 5585 | |
| 5586 | while (1) { |
| 5587 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5588 | mpp, &pinfo); |
| 5589 | if (err == -ENOENT) |
| 5590 | break; |
| 5591 | if (err) |
| 5592 | goto out_err; |
| 5593 | |
| 5594 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5595 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5596 | wdev->netdev, dst, mpp, |
| 5597 | &pinfo) < 0) |
| 5598 | goto out; |
| 5599 | |
| 5600 | path_idx++; |
| 5601 | } |
| 5602 | |
| 5603 | out: |
| 5604 | cb->args[2] = path_idx; |
| 5605 | err = skb->len; |
| 5606 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5607 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5608 | return err; |
| 5609 | } |
| 5610 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5611 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5612 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5614 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5615 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5616 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5617 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5618 | |
| 5619 | memset(¶ms, 0, sizeof(params)); |
| 5620 | /* default to not changing parameters */ |
| 5621 | params.use_cts_prot = -1; |
| 5622 | params.use_short_preamble = -1; |
| 5623 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5624 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5625 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5626 | params.p2p_ctwindow = -1; |
| 5627 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5628 | |
| 5629 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5630 | params.use_cts_prot = |
| 5631 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5632 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5633 | params.use_short_preamble = |
| 5634 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5635 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5636 | params.use_short_slot_time = |
| 5637 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5638 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5639 | params.basic_rates = |
| 5640 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5641 | params.basic_rates_len = |
| 5642 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5643 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5644 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5645 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5646 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5647 | params.ht_opmode = |
| 5648 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5649 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5650 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5651 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5652 | return -EINVAL; |
| 5653 | params.p2p_ctwindow = |
| 5654 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5655 | if (params.p2p_ctwindow < 0) |
| 5656 | return -EINVAL; |
| 5657 | if (params.p2p_ctwindow != 0 && |
| 5658 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5659 | return -EINVAL; |
| 5660 | } |
| 5661 | |
| 5662 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5663 | u8 tmp; |
| 5664 | |
| 5665 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5666 | return -EINVAL; |
| 5667 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5668 | if (tmp > 1) |
| 5669 | return -EINVAL; |
| 5670 | params.p2p_opp_ps = tmp; |
| 5671 | if (params.p2p_opp_ps && |
| 5672 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5673 | return -EINVAL; |
| 5674 | } |
| 5675 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5676 | if (!rdev->ops->change_bss) |
| 5677 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5678 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5679 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5680 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5681 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5682 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5683 | wdev_lock(wdev); |
| 5684 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5685 | wdev_unlock(wdev); |
| 5686 | |
| 5687 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5688 | } |
| 5689 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5690 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5691 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5692 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5693 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5694 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5695 | u32 owner_nlportid; |
| 5696 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5697 | /* |
| 5698 | * You should only get this when cfg80211 hasn't yet initialized |
| 5699 | * completely when built-in to the kernel right between the time |
| 5700 | * window between nl80211_init() and regulatory_init(), if that is |
| 5701 | * even possible. |
| 5702 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5703 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5704 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5705 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5706 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5707 | user_reg_hint_type = |
| 5708 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5709 | else |
| 5710 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5711 | |
| 5712 | switch (user_reg_hint_type) { |
| 5713 | case NL80211_USER_REG_HINT_USER: |
| 5714 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5715 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5716 | return -EINVAL; |
| 5717 | |
| 5718 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5719 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5720 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5721 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5722 | owner_nlportid = info->snd_portid; |
| 5723 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5724 | } else { |
| 5725 | owner_nlportid = 0; |
| 5726 | is_indoor = true; |
| 5727 | } |
| 5728 | |
| 5729 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5730 | default: |
| 5731 | return -EINVAL; |
| 5732 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5733 | } |
| 5734 | |
Johannes Berg | 1ea4ff3 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 5735 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
| 5736 | { |
| 5737 | return reg_reload_regdb(); |
| 5738 | } |
| 5739 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5740 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5741 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5742 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5743 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5744 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5745 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5746 | struct mesh_config cur_params; |
| 5747 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5748 | void *hdr; |
| 5749 | struct nlattr *pinfoattr; |
| 5750 | struct sk_buff *msg; |
| 5751 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5752 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5753 | return -EOPNOTSUPP; |
| 5754 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5755 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5756 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5757 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5758 | wdev_lock(wdev); |
| 5759 | /* If not connected, get default parameters */ |
| 5760 | if (!wdev->mesh_id_len) |
| 5761 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5762 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5763 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5764 | wdev_unlock(wdev); |
| 5765 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5766 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5767 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5768 | |
| 5769 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5771 | if (!msg) |
| 5772 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5773 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5774 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5775 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5776 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5777 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5778 | if (!pinfoattr) |
| 5779 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5780 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5781 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5782 | cur_params.dot11MeshRetryTimeout) || |
| 5783 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5784 | cur_params.dot11MeshConfirmTimeout) || |
| 5785 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5786 | cur_params.dot11MeshHoldingTimeout) || |
| 5787 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5788 | cur_params.dot11MeshMaxPeerLinks) || |
| 5789 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5790 | cur_params.dot11MeshMaxRetries) || |
| 5791 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5792 | cur_params.dot11MeshTTL) || |
| 5793 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5794 | cur_params.element_ttl) || |
| 5795 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5796 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5797 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5798 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5799 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5800 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5801 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5802 | cur_params.path_refresh_time) || |
| 5803 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5804 | cur_params.min_discovery_timeout) || |
| 5805 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5806 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5807 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5808 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5809 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5810 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5811 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5812 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5813 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5814 | cur_params.dot11MeshHWMPRootMode) || |
| 5815 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5816 | cur_params.dot11MeshHWMPRannInterval) || |
| 5817 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5818 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5819 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5820 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 5821 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5822 | cur_params.rssi_threshold) || |
| 5823 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5824 | cur_params.ht_opmode) || |
| 5825 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5826 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5827 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5828 | cur_params.dot11MeshHWMProotInterval) || |
| 5829 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5830 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5831 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5832 | cur_params.power_mode) || |
| 5833 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5834 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5835 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5836 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5837 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5838 | nla_nest_end(msg, pinfoattr); |
| 5839 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5840 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5841 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5842 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5843 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5844 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5845 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5846 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5847 | } |
| 5848 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5849 | 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] | 5850 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5851 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5852 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5853 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5854 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5855 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5856 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5857 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5858 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5859 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5860 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5861 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5862 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5863 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5864 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5865 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5866 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5867 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5868 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5869 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5870 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5871 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5872 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5873 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5874 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5875 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5876 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5877 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5878 | }; |
| 5879 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5880 | static const struct nla_policy |
| 5881 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5882 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5883 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5884 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5885 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5886 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5887 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5888 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5889 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5890 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5891 | }; |
| 5892 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5893 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
| 5894 | { |
| 5895 | u8 val = nla_get_u8(nla); |
| 5896 | if (val < min || val > max) |
| 5897 | return -EINVAL; |
| 5898 | *out = val; |
| 5899 | return 0; |
| 5900 | } |
| 5901 | |
| 5902 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 5903 | { |
| 5904 | u8 val = nla_get_u8(nla); |
| 5905 | if (val < min || val > max) |
| 5906 | return -EINVAL; |
| 5907 | *out = val; |
| 5908 | return 0; |
| 5909 | } |
| 5910 | |
| 5911 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 5912 | { |
| 5913 | u16 val = nla_get_u16(nla); |
| 5914 | if (val < min || val > max) |
| 5915 | return -EINVAL; |
| 5916 | *out = val; |
| 5917 | return 0; |
| 5918 | } |
| 5919 | |
| 5920 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 5921 | { |
| 5922 | u32 val = nla_get_u32(nla); |
| 5923 | if (val < min || val > max) |
| 5924 | return -EINVAL; |
| 5925 | *out = val; |
| 5926 | return 0; |
| 5927 | } |
| 5928 | |
| 5929 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 5930 | { |
| 5931 | s32 val = nla_get_s32(nla); |
| 5932 | if (val < min || val > max) |
| 5933 | return -EINVAL; |
| 5934 | *out = val; |
| 5935 | return 0; |
| 5936 | } |
| 5937 | |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5938 | static int nl80211_check_power_mode(const struct nlattr *nla, |
| 5939 | enum nl80211_mesh_power_mode min, |
| 5940 | enum nl80211_mesh_power_mode max, |
| 5941 | enum nl80211_mesh_power_mode *out) |
| 5942 | { |
| 5943 | u32 val = nla_get_u32(nla); |
| 5944 | if (val < min || val > max) |
| 5945 | return -EINVAL; |
| 5946 | *out = val; |
| 5947 | return 0; |
| 5948 | } |
| 5949 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5950 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5951 | struct mesh_config *cfg, |
| 5952 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5953 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5954 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5955 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5956 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5957 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5958 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5959 | do { \ |
| 5960 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5961 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5962 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5963 | mask |= (1 << (attr - 1)); \ |
| 5964 | } \ |
| 5965 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5966 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5967 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5968 | return -EINVAL; |
| 5969 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5970 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 5971 | nl80211_meshconf_params_policy, info->extack)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5972 | return -EINVAL; |
| 5973 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5974 | /* This makes sure that there aren't more than 32 mesh config |
| 5975 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5976 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5977 | |
| 5978 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5979 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5980 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5981 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5982 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5983 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5984 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5985 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5986 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5987 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5988 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5989 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5990 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5991 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5992 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5993 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5994 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5995 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5996 | 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] | 5997 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5998 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5999 | 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] | 6000 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6001 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6002 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 6003 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6004 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6005 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6006 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6007 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6008 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6009 | 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] | 6010 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6011 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6012 | 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] | 6013 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6014 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6015 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 6016 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6017 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6018 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6019 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6020 | 1, 65535, mask, |
| 6021 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6022 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 6023 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6024 | 1, 65535, mask, |
| 6025 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6026 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6027 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6028 | dot11MeshHWMPnetDiameterTraversalTime, |
| 6029 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6030 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6031 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6032 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 6033 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6034 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6035 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 6036 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6037 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 6038 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6039 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 6040 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6041 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6042 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6043 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6044 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 6045 | 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] | 6046 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6047 | nl80211_check_s32); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6048 | /* |
| 6049 | * Check HT operation mode based on |
| 6050 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. |
| 6051 | */ |
| 6052 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 6053 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 6054 | |
| 6055 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 6056 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 6057 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6058 | return -EINVAL; |
| 6059 | |
| 6060 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && |
| 6061 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6062 | return -EINVAL; |
| 6063 | |
| 6064 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { |
| 6065 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 6066 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 6067 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) |
| 6068 | return -EINVAL; |
| 6069 | break; |
| 6070 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 6071 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 6072 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6073 | return -EINVAL; |
| 6074 | break; |
| 6075 | } |
| 6076 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 6077 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6078 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6079 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6080 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6081 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6082 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6083 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6084 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6085 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6086 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6087 | dot11MeshHWMPconfirmationInterval, |
| 6088 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6089 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6090 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6091 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 6092 | NL80211_MESH_POWER_ACTIVE, |
| 6093 | NL80211_MESH_POWER_MAX, |
| 6094 | mask, NL80211_MESHCONF_POWER_MODE, |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 6095 | nl80211_check_power_mode); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6096 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 6097 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6098 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 6099 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6100 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6101 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6102 | if (mask_out) |
| 6103 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6104 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6105 | return 0; |
| 6106 | |
| 6107 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 6108 | } |
| 6109 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6110 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 6111 | struct mesh_setup *setup) |
| 6112 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6114 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 6115 | |
| 6116 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 6117 | return -EINVAL; |
| 6118 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 6119 | info->attrs[NL80211_ATTR_MESH_SETUP], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6120 | nl80211_mesh_setup_params_policy, info->extack)) |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6121 | return -EINVAL; |
| 6122 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6123 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 6124 | setup->sync_method = |
| 6125 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 6126 | IEEE80211_SYNC_METHOD_VENDOR : |
| 6127 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 6128 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6129 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 6130 | setup->path_sel_proto = |
| 6131 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 6132 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 6133 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 6134 | |
| 6135 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 6136 | setup->path_metric = |
| 6137 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 6138 | IEEE80211_PATH_METRIC_VENDOR : |
| 6139 | IEEE80211_PATH_METRIC_AIRTIME; |
| 6140 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6141 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6142 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6143 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6144 | if (!is_valid_ie_attr(ieattr)) |
| 6145 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6146 | setup->ie = nla_data(ieattr); |
| 6147 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6148 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6149 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 6150 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 6151 | return -EINVAL; |
| 6152 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6153 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 6154 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6155 | if (setup->is_secure) |
| 6156 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6157 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6158 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 6159 | if (!setup->user_mpm) |
| 6160 | return -EINVAL; |
| 6161 | setup->auth_id = |
| 6162 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 6163 | } |
| 6164 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6165 | return 0; |
| 6166 | } |
| 6167 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6168 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6169 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6170 | { |
| 6171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6172 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6173 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6174 | struct mesh_config cfg; |
| 6175 | u32 mask; |
| 6176 | int err; |
| 6177 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6178 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6179 | return -EOPNOTSUPP; |
| 6180 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6181 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6182 | return -EOPNOTSUPP; |
| 6183 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6184 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6185 | if (err) |
| 6186 | return err; |
| 6187 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6188 | wdev_lock(wdev); |
| 6189 | if (!wdev->mesh_id_len) |
| 6190 | err = -ENOLINK; |
| 6191 | |
| 6192 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6193 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6194 | |
| 6195 | wdev_unlock(wdev); |
| 6196 | |
| 6197 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6198 | } |
| 6199 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6200 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 6201 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6202 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6203 | struct nlattr *nl_reg_rules; |
| 6204 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6205 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6206 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 6207 | (regdom->dfs_region && |
| 6208 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6209 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6210 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6211 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 6212 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6213 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6214 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6215 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6216 | struct nlattr *nl_reg_rule; |
| 6217 | const struct ieee80211_reg_rule *reg_rule; |
| 6218 | const struct ieee80211_freq_range *freq_range; |
| 6219 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6220 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6221 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6222 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6223 | freq_range = ®_rule->freq_range; |
| 6224 | power_rule = ®_rule->power_rule; |
| 6225 | |
| 6226 | nl_reg_rule = nla_nest_start(msg, i); |
| 6227 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6228 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6229 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6230 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 6231 | if (!max_bandwidth_khz) |
| 6232 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 6233 | reg_rule); |
| 6234 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6235 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 6236 | reg_rule->flags) || |
| 6237 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 6238 | freq_range->start_freq_khz) || |
| 6239 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 6240 | freq_range->end_freq_khz) || |
| 6241 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6242 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6243 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 6244 | power_rule->max_antenna_gain) || |
| 6245 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 6246 | power_rule->max_eirp) || |
| 6247 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 6248 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6249 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6250 | |
| 6251 | nla_nest_end(msg, nl_reg_rule); |
| 6252 | } |
| 6253 | |
| 6254 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6255 | return 0; |
| 6256 | |
| 6257 | nla_put_failure: |
| 6258 | return -EMSGSIZE; |
| 6259 | } |
| 6260 | |
| 6261 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 6262 | { |
| 6263 | const struct ieee80211_regdomain *regdom = NULL; |
| 6264 | struct cfg80211_registered_device *rdev; |
| 6265 | struct wiphy *wiphy = NULL; |
| 6266 | struct sk_buff *msg; |
| 6267 | void *hdr; |
| 6268 | |
| 6269 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6270 | if (!msg) |
| 6271 | return -ENOBUFS; |
| 6272 | |
| 6273 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 6274 | NL80211_CMD_GET_REG); |
| 6275 | if (!hdr) |
| 6276 | goto put_failure; |
| 6277 | |
| 6278 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6279 | bool self_managed; |
| 6280 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6281 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 6282 | if (IS_ERR(rdev)) { |
| 6283 | nlmsg_free(msg); |
| 6284 | return PTR_ERR(rdev); |
| 6285 | } |
| 6286 | |
| 6287 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6288 | self_managed = wiphy->regulatory_flags & |
| 6289 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6290 | regdom = get_wiphy_regdom(wiphy); |
| 6291 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6292 | /* a self-managed-reg device must have a private regdom */ |
| 6293 | if (WARN_ON(!regdom && self_managed)) { |
| 6294 | nlmsg_free(msg); |
| 6295 | return -EINVAL; |
| 6296 | } |
| 6297 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6298 | if (regdom && |
| 6299 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6300 | goto nla_put_failure; |
| 6301 | } |
| 6302 | |
| 6303 | if (!wiphy && reg_last_request_cell_base() && |
| 6304 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6305 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6306 | goto nla_put_failure; |
| 6307 | |
| 6308 | rcu_read_lock(); |
| 6309 | |
| 6310 | if (!regdom) |
| 6311 | regdom = rcu_dereference(cfg80211_regdomain); |
| 6312 | |
| 6313 | if (nl80211_put_regdom(regdom, msg)) |
| 6314 | goto nla_put_failure_rcu; |
| 6315 | |
| 6316 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6317 | |
| 6318 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6319 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6320 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6321 | nla_put_failure_rcu: |
| 6322 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6323 | nla_put_failure: |
| 6324 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6325 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6326 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6327 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6328 | } |
| 6329 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6330 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 6331 | u32 seq, int flags, struct wiphy *wiphy, |
| 6332 | const struct ieee80211_regdomain *regdom) |
| 6333 | { |
| 6334 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 6335 | NL80211_CMD_GET_REG); |
| 6336 | |
| 6337 | if (!hdr) |
| 6338 | return -1; |
| 6339 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 6340 | genl_dump_check_consistent(cb, hdr); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6341 | |
| 6342 | if (nl80211_put_regdom(regdom, msg)) |
| 6343 | goto nla_put_failure; |
| 6344 | |
| 6345 | if (!wiphy && reg_last_request_cell_base() && |
| 6346 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6347 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6348 | goto nla_put_failure; |
| 6349 | |
| 6350 | if (wiphy && |
| 6351 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6352 | goto nla_put_failure; |
| 6353 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6354 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 6355 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 6356 | goto nla_put_failure; |
| 6357 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6358 | genlmsg_end(msg, hdr); |
| 6359 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6360 | |
| 6361 | nla_put_failure: |
| 6362 | genlmsg_cancel(msg, hdr); |
| 6363 | return -EMSGSIZE; |
| 6364 | } |
| 6365 | |
| 6366 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 6367 | struct netlink_callback *cb) |
| 6368 | { |
| 6369 | const struct ieee80211_regdomain *regdom = NULL; |
| 6370 | struct cfg80211_registered_device *rdev; |
| 6371 | int err, reg_idx, start = cb->args[2]; |
| 6372 | |
| 6373 | rtnl_lock(); |
| 6374 | |
| 6375 | if (cfg80211_regdomain && start == 0) { |
| 6376 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6377 | NLM_F_MULTI, NULL, |
| 6378 | rtnl_dereference(cfg80211_regdomain)); |
| 6379 | if (err < 0) |
| 6380 | goto out_err; |
| 6381 | } |
| 6382 | |
| 6383 | /* the global regdom is idx 0 */ |
| 6384 | reg_idx = 1; |
| 6385 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 6386 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 6387 | if (!regdom) |
| 6388 | continue; |
| 6389 | |
| 6390 | if (++reg_idx <= start) |
| 6391 | continue; |
| 6392 | |
| 6393 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6394 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 6395 | if (err < 0) { |
| 6396 | reg_idx--; |
| 6397 | break; |
| 6398 | } |
| 6399 | } |
| 6400 | |
| 6401 | cb->args[2] = reg_idx; |
| 6402 | err = skb->len; |
| 6403 | out_err: |
| 6404 | rtnl_unlock(); |
| 6405 | return err; |
| 6406 | } |
| 6407 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6408 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 6409 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 6410 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6411 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6412 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6413 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6414 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6415 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6416 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 6417 | }; |
| 6418 | |
| 6419 | static int parse_reg_rule(struct nlattr *tb[], |
| 6420 | struct ieee80211_reg_rule *reg_rule) |
| 6421 | { |
| 6422 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 6423 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 6424 | |
| 6425 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6426 | return -EINVAL; |
| 6427 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 6428 | return -EINVAL; |
| 6429 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 6430 | return -EINVAL; |
| 6431 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6432 | return -EINVAL; |
| 6433 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6434 | return -EINVAL; |
| 6435 | |
| 6436 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 6437 | |
| 6438 | freq_range->start_freq_khz = |
| 6439 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 6440 | freq_range->end_freq_khz = |
| 6441 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 6442 | freq_range->max_bandwidth_khz = |
| 6443 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 6444 | |
| 6445 | power_rule->max_eirp = |
| 6446 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 6447 | |
| 6448 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 6449 | power_rule->max_antenna_gain = |
| 6450 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 6451 | |
| 6452 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 6453 | reg_rule->dfs_cac_ms = |
| 6454 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 6455 | |
| 6456 | return 0; |
| 6457 | } |
| 6458 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6459 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6460 | { |
| 6461 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 6462 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6463 | char *alpha2; |
| 6464 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6465 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 6466 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6467 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6468 | |
| 6469 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6470 | return -EINVAL; |
| 6471 | |
| 6472 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 6473 | return -EINVAL; |
| 6474 | |
| 6475 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6476 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6477 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 6478 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 6479 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6480 | 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] | 6481 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6482 | num_rules++; |
| 6483 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 6484 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6485 | } |
| 6486 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 6487 | if (!reg_is_valid_request(alpha2)) |
| 6488 | return -EINVAL; |
| 6489 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6490 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6491 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6492 | |
| 6493 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 6494 | if (!rd) |
| 6495 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6496 | |
| 6497 | rd->n_reg_rules = num_rules; |
| 6498 | rd->alpha2[0] = alpha2[0]; |
| 6499 | rd->alpha2[1] = alpha2[1]; |
| 6500 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6501 | /* |
| 6502 | * Disable DFS master mode if the DFS region was |
| 6503 | * not supported or known on this kernel. |
| 6504 | */ |
| 6505 | if (reg_supported_dfs_region(dfs_region)) |
| 6506 | rd->dfs_region = dfs_region; |
| 6507 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6508 | 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] | 6509 | rem_reg_rules) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6510 | r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6511 | nl_reg_rule, reg_rule_policy, |
| 6512 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6513 | if (r) |
| 6514 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6515 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 6516 | if (r) |
| 6517 | goto bad_reg; |
| 6518 | |
| 6519 | rule_idx++; |
| 6520 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6521 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 6522 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6523 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6524 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6525 | } |
| 6526 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 6527 | /* set_regdom takes ownership of rd */ |
| 6528 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 6529 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6530 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6531 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6532 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6533 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6534 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6535 | static int validate_scan_freqs(struct nlattr *freqs) |
| 6536 | { |
| 6537 | struct nlattr *attr1, *attr2; |
| 6538 | int n_channels = 0, tmp1, tmp2; |
| 6539 | |
Srinivas Dasari | d7f13f7 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 6540 | nla_for_each_nested(attr1, freqs, tmp1) |
| 6541 | if (nla_len(attr1) != sizeof(u32)) |
| 6542 | return 0; |
| 6543 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6544 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 6545 | n_channels++; |
| 6546 | /* |
| 6547 | * Some hardware has a limited channel list for |
| 6548 | * scanning, and it is pretty much nonsensical |
| 6549 | * to scan for a channel twice, so disallow that |
| 6550 | * and don't require drivers to check that the |
| 6551 | * channel list they get isn't longer than what |
| 6552 | * they can scan, as long as they can scan all |
| 6553 | * the channels they registered at once. |
| 6554 | */ |
| 6555 | nla_for_each_nested(attr2, freqs, tmp2) |
| 6556 | if (attr1 != attr2 && |
| 6557 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 6558 | return 0; |
| 6559 | } |
| 6560 | |
| 6561 | return n_channels; |
| 6562 | } |
| 6563 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6564 | 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] | 6565 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6566 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6567 | } |
| 6568 | |
| 6569 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 6570 | struct cfg80211_bss_selection *bss_select) |
| 6571 | { |
| 6572 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 6573 | struct nlattr *nest; |
| 6574 | int err; |
| 6575 | bool found = false; |
| 6576 | int i; |
| 6577 | |
| 6578 | /* only process one nested attribute */ |
| 6579 | nest = nla_data(nla); |
| 6580 | if (!nla_ok(nest, nla_len(nest))) |
| 6581 | return -EINVAL; |
| 6582 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6583 | err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 6584 | nl80211_bss_select_policy, NULL); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6585 | if (err) |
| 6586 | return err; |
| 6587 | |
| 6588 | /* only one attribute may be given */ |
| 6589 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 6590 | if (attr[i]) { |
| 6591 | if (found) |
| 6592 | return -EINVAL; |
| 6593 | found = true; |
| 6594 | } |
| 6595 | } |
| 6596 | |
| 6597 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 6598 | |
| 6599 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 6600 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 6601 | |
| 6602 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 6603 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 6604 | bss_select->param.band_pref = |
| 6605 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6606 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6607 | return -EINVAL; |
| 6608 | } |
| 6609 | |
| 6610 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6611 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6612 | |
| 6613 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6614 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6615 | bss_select->param.adjust.band = adj_param->band; |
| 6616 | bss_select->param.adjust.delta = adj_param->delta; |
| 6617 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6618 | return -EINVAL; |
| 6619 | } |
| 6620 | |
| 6621 | /* user-space did not provide behaviour attribute */ |
| 6622 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6623 | return -EINVAL; |
| 6624 | |
| 6625 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6626 | return -EINVAL; |
| 6627 | |
| 6628 | return 0; |
| 6629 | } |
| 6630 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6631 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6632 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6633 | { |
| 6634 | int i; |
| 6635 | |
| 6636 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6637 | eth_zero_addr(mac_addr); |
| 6638 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6639 | mac_addr[0] = 0x2; |
| 6640 | mac_addr_mask[0] = 0x3; |
| 6641 | |
| 6642 | return 0; |
| 6643 | } |
| 6644 | |
| 6645 | /* need both or none */ |
| 6646 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6647 | return -EINVAL; |
| 6648 | |
| 6649 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6650 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6651 | |
| 6652 | /* don't allow or configure an mcast address */ |
| 6653 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6654 | is_multicast_ether_addr(mac_addr)) |
| 6655 | return -EINVAL; |
| 6656 | |
| 6657 | /* |
| 6658 | * allow users to pass a MAC address that has bits set outside |
| 6659 | * of the mask, but don't bother drivers with having to deal |
| 6660 | * with such bits |
| 6661 | */ |
| 6662 | for (i = 0; i < ETH_ALEN; i++) |
| 6663 | mac_addr[i] &= mac_addr_mask[i]; |
| 6664 | |
| 6665 | return 0; |
| 6666 | } |
| 6667 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 6668 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 6669 | { |
| 6670 | ASSERT_WDEV_LOCK(wdev); |
| 6671 | |
| 6672 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 6673 | return true; |
| 6674 | |
| 6675 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 6676 | return true; |
| 6677 | |
| 6678 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 6679 | } |
| 6680 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 6681 | static int |
| 6682 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 6683 | void *request, struct nlattr **attrs, |
| 6684 | bool is_sched_scan) |
| 6685 | { |
| 6686 | u8 *mac_addr, *mac_addr_mask; |
| 6687 | u32 *flags; |
| 6688 | enum nl80211_feature_flags randomness_flag; |
| 6689 | |
| 6690 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) |
| 6691 | return 0; |
| 6692 | |
| 6693 | if (is_sched_scan) { |
| 6694 | struct cfg80211_sched_scan_request *req = request; |
| 6695 | |
| 6696 | randomness_flag = wdev ? |
| 6697 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : |
| 6698 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6699 | flags = &req->flags; |
| 6700 | mac_addr = req->mac_addr; |
| 6701 | mac_addr_mask = req->mac_addr_mask; |
| 6702 | } else { |
| 6703 | struct cfg80211_scan_request *req = request; |
| 6704 | |
| 6705 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 6706 | flags = &req->flags; |
| 6707 | mac_addr = req->mac_addr; |
| 6708 | mac_addr_mask = req->mac_addr_mask; |
| 6709 | } |
| 6710 | |
| 6711 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); |
| 6712 | |
| 6713 | if ((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6714 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) |
| 6715 | return -EOPNOTSUPP; |
| 6716 | |
| 6717 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6718 | int err; |
| 6719 | |
| 6720 | if (!(wiphy->features & randomness_flag) || |
| 6721 | (wdev && wdev->current_bss)) |
| 6722 | return -EOPNOTSUPP; |
| 6723 | |
| 6724 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); |
| 6725 | if (err) |
| 6726 | return err; |
| 6727 | } |
| 6728 | |
| 6729 | if ((*flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME) && |
| 6730 | !wiphy_ext_feature_isset(wiphy, |
| 6731 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME)) |
| 6732 | return -EOPNOTSUPP; |
| 6733 | |
| 6734 | if ((*flags & NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP) && |
| 6735 | !wiphy_ext_feature_isset(wiphy, |
| 6736 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP)) |
| 6737 | return -EOPNOTSUPP; |
| 6738 | |
| 6739 | if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) && |
| 6740 | !wiphy_ext_feature_isset(wiphy, |
| 6741 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION)) |
| 6742 | return -EOPNOTSUPP; |
| 6743 | |
| 6744 | if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE) && |
| 6745 | !wiphy_ext_feature_isset(wiphy, |
| 6746 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE)) |
| 6747 | return -EOPNOTSUPP; |
| 6748 | |
| 6749 | return 0; |
| 6750 | } |
| 6751 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6752 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 6753 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6755 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6756 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6757 | struct nlattr *attr; |
| 6758 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6759 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6760 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6761 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6762 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6763 | return -EINVAL; |
| 6764 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6765 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6766 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 6767 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 6768 | return -EOPNOTSUPP; |
| 6769 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6770 | if (!rdev->ops->scan) |
| 6771 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6772 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 6773 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6774 | err = -EBUSY; |
| 6775 | goto unlock; |
| 6776 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6777 | |
| 6778 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6779 | n_channels = validate_scan_freqs( |
| 6780 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6781 | if (!n_channels) { |
| 6782 | err = -EINVAL; |
| 6783 | goto unlock; |
| 6784 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6785 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6786 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6790 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 6791 | n_ssids++; |
| 6792 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6793 | if (n_ssids > wiphy->max_scan_ssids) { |
| 6794 | err = -EINVAL; |
| 6795 | goto unlock; |
| 6796 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6797 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6798 | if (info->attrs[NL80211_ATTR_IE]) |
| 6799 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6800 | else |
| 6801 | ie_len = 0; |
| 6802 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6803 | if (ie_len > wiphy->max_scan_ie_len) { |
| 6804 | err = -EINVAL; |
| 6805 | goto unlock; |
| 6806 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 6807 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6808 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6809 | + sizeof(*request->ssids) * n_ssids |
| 6810 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6811 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6812 | if (!request) { |
| 6813 | err = -ENOMEM; |
| 6814 | goto unlock; |
| 6815 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6816 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6817 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 6818 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6819 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6820 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6821 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6822 | request->ie = (void *)(request->ssids + n_ssids); |
| 6823 | else |
| 6824 | request->ie = (void *)(request->channels + n_channels); |
| 6825 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6826 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6827 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6828 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 6829 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6830 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6831 | struct ieee80211_channel *chan; |
| 6832 | |
| 6833 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6834 | |
| 6835 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6836 | err = -EINVAL; |
| 6837 | goto out_free; |
| 6838 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6839 | |
| 6840 | /* ignore disabled channels */ |
| 6841 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6842 | continue; |
| 6843 | |
| 6844 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6845 | i++; |
| 6846 | } |
| 6847 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6848 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6849 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6850 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6851 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6852 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6853 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6854 | if (!wiphy->bands[band]) |
| 6855 | continue; |
| 6856 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6857 | struct ieee80211_channel *chan; |
| 6858 | |
| 6859 | chan = &wiphy->bands[band]->channels[j]; |
| 6860 | |
| 6861 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6862 | continue; |
| 6863 | |
| 6864 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6865 | i++; |
| 6866 | } |
| 6867 | } |
| 6868 | } |
| 6869 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6870 | if (!i) { |
| 6871 | err = -EINVAL; |
| 6872 | goto out_free; |
| 6873 | } |
| 6874 | |
| 6875 | request->n_channels = i; |
| 6876 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 6877 | wdev_lock(wdev); |
| 6878 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 6879 | struct ieee80211_channel *chan; |
| 6880 | |
| 6881 | if (request->n_channels != 1) { |
| 6882 | wdev_unlock(wdev); |
| 6883 | err = -EBUSY; |
| 6884 | goto out_free; |
| 6885 | } |
| 6886 | |
| 6887 | chan = request->channels[0]; |
| 6888 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 6889 | wdev_unlock(wdev); |
| 6890 | err = -EBUSY; |
| 6891 | goto out_free; |
| 6892 | } |
| 6893 | } |
| 6894 | wdev_unlock(wdev); |
| 6895 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6896 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6897 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6898 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6899 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6900 | err = -EINVAL; |
| 6901 | goto out_free; |
| 6902 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6903 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6904 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6905 | i++; |
| 6906 | } |
| 6907 | } |
| 6908 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6909 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6910 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 6911 | memcpy((void *)request->ie, |
| 6912 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6913 | request->ie_len); |
| 6914 | } |
| 6915 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6916 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 6917 | if (wiphy->bands[i]) |
| 6918 | request->rates[i] = |
| 6919 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6920 | |
| 6921 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 6922 | nla_for_each_nested(attr, |
| 6923 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 6924 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6925 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6926 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6927 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6928 | err = -EINVAL; |
| 6929 | goto out_free; |
| 6930 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 6931 | |
| 6932 | if (!wiphy->bands[band]) |
| 6933 | continue; |
| 6934 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6935 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 6936 | nla_data(attr), |
| 6937 | nla_len(attr), |
| 6938 | &request->rates[band]); |
| 6939 | if (err) |
| 6940 | goto out_free; |
| 6941 | } |
| 6942 | } |
| 6943 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 6944 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 6945 | if (!wiphy_ext_feature_isset(wiphy, |
| 6946 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 6947 | err = -EOPNOTSUPP; |
| 6948 | goto out_free; |
| 6949 | } |
| 6950 | |
| 6951 | request->duration = |
| 6952 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 6953 | request->duration_mandatory = |
| 6954 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 6955 | } |
| 6956 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 6957 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
| 6958 | false); |
| 6959 | if (err) |
| 6960 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6961 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6962 | request->no_cck = |
| 6963 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6964 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 6965 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 6966 | * BSSID to scan for. This was problematic because that same attribute |
| 6967 | * was already used for another purpose (local random MAC address). The |
| 6968 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 6969 | * compatibility with older userspace components, also use the |
| 6970 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 6971 | * the specific BSSID use case instead of the random MAC address |
| 6972 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 6973 | */ |
| 6974 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 6975 | memcpy(request->bssid, |
| 6976 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 6977 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 6978 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 6979 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 6980 | ETH_ALEN); |
| 6981 | else |
| 6982 | eth_broadcast_addr(request->bssid); |
| 6983 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6984 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6985 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6986 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6987 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6988 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6989 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6990 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6991 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6992 | nl80211_send_scan_start(rdev, wdev); |
| 6993 | if (wdev->netdev) |
| 6994 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6995 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6996 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6997 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6998 | kfree(request); |
| 6999 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7000 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 7001 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7002 | return err; |
| 7003 | } |
| 7004 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 7005 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 7006 | { |
| 7007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7008 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7009 | |
| 7010 | if (!rdev->ops->abort_scan) |
| 7011 | return -EOPNOTSUPP; |
| 7012 | |
| 7013 | if (rdev->scan_msg) |
| 7014 | return 0; |
| 7015 | |
| 7016 | if (!rdev->scan_req) |
| 7017 | return -ENOENT; |
| 7018 | |
| 7019 | rdev_abort_scan(rdev, wdev); |
| 7020 | return 0; |
| 7021 | } |
| 7022 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7023 | static int |
| 7024 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 7025 | struct cfg80211_sched_scan_request *request, |
| 7026 | struct nlattr **attrs) |
| 7027 | { |
| 7028 | int tmp, err, i = 0; |
| 7029 | struct nlattr *attr; |
| 7030 | |
| 7031 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 7032 | u32 interval; |
| 7033 | |
| 7034 | /* |
| 7035 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 7036 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7037 | * case one scan plan will be set with the specified scan |
| 7038 | * interval and infinite number of iterations. |
| 7039 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7040 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 7041 | if (!interval) |
| 7042 | return -EINVAL; |
| 7043 | |
| 7044 | request->scan_plans[0].interval = |
| 7045 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 7046 | if (!request->scan_plans[0].interval) |
| 7047 | return -EINVAL; |
| 7048 | |
| 7049 | if (request->scan_plans[0].interval > |
| 7050 | wiphy->max_sched_scan_plan_interval) |
| 7051 | request->scan_plans[0].interval = |
| 7052 | wiphy->max_sched_scan_plan_interval; |
| 7053 | |
| 7054 | return 0; |
| 7055 | } |
| 7056 | |
| 7057 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 7058 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 7059 | |
| 7060 | if (WARN_ON(i >= n_plans)) |
| 7061 | return -EINVAL; |
| 7062 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7063 | err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7064 | attr, nl80211_plan_policy, NULL); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7065 | if (err) |
| 7066 | return err; |
| 7067 | |
| 7068 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 7069 | return -EINVAL; |
| 7070 | |
| 7071 | request->scan_plans[i].interval = |
| 7072 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 7073 | if (!request->scan_plans[i].interval || |
| 7074 | request->scan_plans[i].interval > |
| 7075 | wiphy->max_sched_scan_plan_interval) |
| 7076 | return -EINVAL; |
| 7077 | |
| 7078 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 7079 | request->scan_plans[i].iterations = |
| 7080 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 7081 | if (!request->scan_plans[i].iterations || |
| 7082 | (request->scan_plans[i].iterations > |
| 7083 | wiphy->max_sched_scan_plan_iterations)) |
| 7084 | return -EINVAL; |
| 7085 | } else if (i < n_plans - 1) { |
| 7086 | /* |
| 7087 | * All scan plans but the last one must specify |
| 7088 | * a finite number of iterations |
| 7089 | */ |
| 7090 | return -EINVAL; |
| 7091 | } |
| 7092 | |
| 7093 | i++; |
| 7094 | } |
| 7095 | |
| 7096 | /* |
| 7097 | * The last scan plan must not specify the number of |
| 7098 | * iterations, it is supposed to run infinitely |
| 7099 | */ |
| 7100 | if (request->scan_plans[n_plans - 1].iterations) |
| 7101 | return -EINVAL; |
| 7102 | |
| 7103 | return 0; |
| 7104 | } |
| 7105 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7106 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7107 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7108 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7109 | { |
| 7110 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7111 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7112 | 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] | 7113 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7114 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7115 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7116 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7117 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7118 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 7119 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7120 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7121 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7122 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7123 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7124 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7125 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7126 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7127 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7128 | } |
| 7129 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7130 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7131 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7132 | tmp) |
| 7133 | n_ssids++; |
| 7134 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 7135 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7136 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7137 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7138 | /* |
| 7139 | * First, count the number of 'real' matchsets. Due to an issue with |
| 7140 | * the old implementation, matchsets containing only the RSSI attribute |
| 7141 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 7142 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 7143 | * all APs with a strong RSSI. This is needed to be compatible with |
| 7144 | * older userspace that treated a matchset with only the RSSI as the |
| 7145 | * global RSSI for all other matchsets - if there are other matchsets. |
| 7146 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7147 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7148 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7149 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7150 | tmp) { |
| 7151 | struct nlattr *rssi; |
| 7152 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7153 | err = nla_parse_nested(tb, |
| 7154 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7155 | attr, nl80211_match_policy, |
| 7156 | NULL); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7157 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7158 | return ERR_PTR(err); |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7159 | |
| 7160 | /* SSID and BSSID are mutually exclusive */ |
| 7161 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 7162 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 7163 | return ERR_PTR(-EINVAL); |
| 7164 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7165 | /* add other standalone attributes here */ |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7166 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 7167 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7168 | n_match_sets++; |
| 7169 | continue; |
| 7170 | } |
| 7171 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7172 | if (rssi) |
| 7173 | default_match_rssi = nla_get_s32(rssi); |
| 7174 | } |
| 7175 | } |
| 7176 | |
| 7177 | /* However, if there's no other matchset, add the RSSI one */ |
| 7178 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 7179 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7180 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7181 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7182 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7183 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7184 | if (attrs[NL80211_ATTR_IE]) |
| 7185 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7186 | else |
| 7187 | ie_len = 0; |
| 7188 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 7189 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7190 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 7191 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7192 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 7193 | /* |
| 7194 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 7195 | * each scan plan already specifies its own interval |
| 7196 | */ |
| 7197 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7198 | return ERR_PTR(-EINVAL); |
| 7199 | |
| 7200 | nla_for_each_nested(attr, |
| 7201 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 7202 | n_plans++; |
| 7203 | } else { |
| 7204 | /* |
| 7205 | * The scan interval attribute is kept for backward |
| 7206 | * compatibility. If no scan plans are specified and sched scan |
| 7207 | * interval is specified, one scan plan will be set with this |
| 7208 | * scan interval and infinite number of iterations. |
| 7209 | */ |
| 7210 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7211 | return ERR_PTR(-EINVAL); |
| 7212 | |
| 7213 | n_plans = 1; |
| 7214 | } |
| 7215 | |
| 7216 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 7217 | return ERR_PTR(-EINVAL); |
| 7218 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7219 | if (!wiphy_ext_feature_isset( |
| 7220 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 7221 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 7222 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 7223 | return ERR_PTR(-EINVAL); |
| 7224 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7225 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7226 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7227 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7228 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7229 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7230 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7231 | if (!request) |
| 7232 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7233 | |
| 7234 | if (n_ssids) |
| 7235 | request->ssids = (void *)&request->channels[n_channels]; |
| 7236 | request->n_ssids = n_ssids; |
| 7237 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7238 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7239 | request->ie = (void *)(request->ssids + n_ssids); |
| 7240 | else |
| 7241 | request->ie = (void *)(request->channels + n_channels); |
| 7242 | } |
| 7243 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7244 | if (n_match_sets) { |
| 7245 | if (request->ie) |
| 7246 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7247 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7248 | request->match_sets = |
| 7249 | (void *)(request->ssids + n_ssids); |
| 7250 | else |
| 7251 | request->match_sets = |
| 7252 | (void *)(request->channels + n_channels); |
| 7253 | } |
| 7254 | request->n_match_sets = n_match_sets; |
| 7255 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7256 | if (n_match_sets) |
| 7257 | request->scan_plans = (void *)(request->match_sets + |
| 7258 | n_match_sets); |
| 7259 | else if (request->ie) |
| 7260 | request->scan_plans = (void *)(request->ie + ie_len); |
| 7261 | else if (n_ssids) |
| 7262 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 7263 | else |
| 7264 | request->scan_plans = (void *)(request->channels + n_channels); |
| 7265 | |
| 7266 | request->n_scan_plans = n_plans; |
| 7267 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7268 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7269 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7270 | /* user specified, bail out if channel not found */ |
| 7271 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7272 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7273 | tmp) { |
| 7274 | struct ieee80211_channel *chan; |
| 7275 | |
| 7276 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7277 | |
| 7278 | if (!chan) { |
| 7279 | err = -EINVAL; |
| 7280 | goto out_free; |
| 7281 | } |
| 7282 | |
| 7283 | /* ignore disabled channels */ |
| 7284 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7285 | continue; |
| 7286 | |
| 7287 | request->channels[i] = chan; |
| 7288 | i++; |
| 7289 | } |
| 7290 | } else { |
| 7291 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7292 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7293 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7294 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7295 | if (!wiphy->bands[band]) |
| 7296 | continue; |
| 7297 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 7298 | struct ieee80211_channel *chan; |
| 7299 | |
| 7300 | chan = &wiphy->bands[band]->channels[j]; |
| 7301 | |
| 7302 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7303 | continue; |
| 7304 | |
| 7305 | request->channels[i] = chan; |
| 7306 | i++; |
| 7307 | } |
| 7308 | } |
| 7309 | } |
| 7310 | |
| 7311 | if (!i) { |
| 7312 | err = -EINVAL; |
| 7313 | goto out_free; |
| 7314 | } |
| 7315 | |
| 7316 | request->n_channels = i; |
| 7317 | |
| 7318 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7319 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7320 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7321 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7322 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7323 | err = -EINVAL; |
| 7324 | goto out_free; |
| 7325 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7326 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7327 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 7328 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7329 | i++; |
| 7330 | } |
| 7331 | } |
| 7332 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7333 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7334 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7335 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7336 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7337 | tmp) { |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7338 | struct nlattr *ssid, *bssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7339 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7340 | err = nla_parse_nested(tb, |
| 7341 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7342 | attr, nl80211_match_policy, |
| 7343 | NULL); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7344 | if (err) |
| 7345 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 7346 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7347 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
| 7348 | if (ssid || bssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7349 | if (WARN_ON(i >= n_match_sets)) { |
| 7350 | /* this indicates a programming error, |
| 7351 | * the loop above should have verified |
| 7352 | * things properly |
| 7353 | */ |
| 7354 | err = -EINVAL; |
| 7355 | goto out_free; |
| 7356 | } |
| 7357 | |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7358 | if (ssid) { |
| 7359 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 7360 | err = -EINVAL; |
| 7361 | goto out_free; |
| 7362 | } |
| 7363 | memcpy(request->match_sets[i].ssid.ssid, |
| 7364 | nla_data(ssid), nla_len(ssid)); |
| 7365 | request->match_sets[i].ssid.ssid_len = |
| 7366 | nla_len(ssid); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7367 | } |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7368 | if (bssid) { |
| 7369 | if (nla_len(bssid) != ETH_ALEN) { |
| 7370 | err = -EINVAL; |
| 7371 | goto out_free; |
| 7372 | } |
| 7373 | memcpy(request->match_sets[i].bssid, |
| 7374 | nla_data(bssid), ETH_ALEN); |
| 7375 | } |
| 7376 | |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 7377 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7378 | request->match_sets[i].rssi_thold = |
| 7379 | default_match_rssi; |
| 7380 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7381 | if (rssi) |
| 7382 | request->match_sets[i].rssi_thold = |
| 7383 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7384 | } |
| 7385 | i++; |
| 7386 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7387 | |
| 7388 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 7389 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7390 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 7391 | |
| 7392 | request->min_rssi_thold = INT_MAX; |
| 7393 | for (i = 0; i < n_match_sets; i++) |
| 7394 | request->min_rssi_thold = |
| 7395 | min(request->match_sets[i].rssi_thold, |
| 7396 | request->min_rssi_thold); |
| 7397 | } else { |
| 7398 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7399 | } |
| 7400 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 7401 | if (ie_len) { |
| 7402 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7403 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7404 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7405 | request->ie_len); |
| 7406 | } |
| 7407 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7408 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
| 7409 | if (err) |
| 7410 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7411 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 7412 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 7413 | request->delay = |
| 7414 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 7415 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7416 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 7417 | request->relative_rssi = nla_get_s8( |
| 7418 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 7419 | request->relative_rssi_set = true; |
| 7420 | } |
| 7421 | |
| 7422 | if (request->relative_rssi_set && |
| 7423 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 7424 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 7425 | |
| 7426 | rssi_adjust = nla_data( |
| 7427 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 7428 | request->rssi_adjust.band = rssi_adjust->band; |
| 7429 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 7430 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 7431 | err = -EINVAL; |
| 7432 | goto out_free; |
| 7433 | } |
| 7434 | } |
| 7435 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7436 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 7437 | if (err) |
| 7438 | goto out_free; |
| 7439 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7440 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7441 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7442 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7443 | |
| 7444 | out_free: |
| 7445 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7446 | return ERR_PTR(err); |
| 7447 | } |
| 7448 | |
| 7449 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 7450 | struct genl_info *info) |
| 7451 | { |
| 7452 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7453 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7454 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7455 | struct cfg80211_sched_scan_request *sched_scan_req; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7456 | bool want_multi; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7457 | int err; |
| 7458 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7459 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7460 | return -EOPNOTSUPP; |
| 7461 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7462 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 7463 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 7464 | if (err) |
| 7465 | return err; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7466 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7467 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7468 | info->attrs, |
| 7469 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7470 | |
| 7471 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7472 | if (err) |
| 7473 | goto out_err; |
| 7474 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7475 | /* leave request id zero for legacy request |
| 7476 | * or if driver does not support multi-scheduled scan |
| 7477 | */ |
| 7478 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) { |
| 7479 | while (!sched_scan_req->reqid) |
| 7480 | sched_scan_req->reqid = rdev->wiphy.cookie_counter++; |
| 7481 | } |
| 7482 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7483 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7484 | if (err) |
| 7485 | goto out_free; |
| 7486 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7487 | sched_scan_req->dev = dev; |
| 7488 | sched_scan_req->wiphy = &rdev->wiphy; |
| 7489 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 7490 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 7491 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 7492 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7493 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7494 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 7495 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7496 | return 0; |
| 7497 | |
| 7498 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7499 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7500 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7501 | return err; |
| 7502 | } |
| 7503 | |
| 7504 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 7505 | struct genl_info *info) |
| 7506 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7507 | struct cfg80211_sched_scan_request *req; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7508 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7509 | u64 cookie; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7510 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7511 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7512 | return -EOPNOTSUPP; |
| 7513 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7514 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 7515 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7516 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 7517 | } |
| 7518 | |
| 7519 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 7520 | struct cfg80211_sched_scan_request, |
| 7521 | list); |
| 7522 | if (!req || req->reqid || |
| 7523 | (req->owner_nlportid && |
| 7524 | req->owner_nlportid != info->snd_portid)) |
| 7525 | return -ENOENT; |
| 7526 | |
| 7527 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7528 | } |
| 7529 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7530 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 7531 | struct genl_info *info) |
| 7532 | { |
| 7533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7534 | struct net_device *dev = info->user_ptr[1]; |
| 7535 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7536 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7537 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7538 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7539 | int err; |
| 7540 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7541 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 7542 | if (dfs_region == NL80211_DFS_UNSET) |
| 7543 | return -EINVAL; |
| 7544 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7545 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7546 | if (err) |
| 7547 | return err; |
| 7548 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 7549 | if (netif_carrier_ok(dev)) |
| 7550 | return -EBUSY; |
| 7551 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7552 | if (wdev->cac_started) |
| 7553 | return -EBUSY; |
| 7554 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7555 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 7556 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7557 | if (err < 0) |
| 7558 | return err; |
| 7559 | |
| 7560 | if (err == 0) |
| 7561 | return -EINVAL; |
| 7562 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 7563 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7564 | return -EINVAL; |
| 7565 | |
| 7566 | if (!rdev->ops->start_radar_detection) |
| 7567 | return -EOPNOTSUPP; |
| 7568 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7569 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 7570 | if (WARN_ON(!cac_time_ms)) |
| 7571 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 7572 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7573 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7574 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 7575 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7576 | wdev->cac_started = true; |
| 7577 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7578 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7579 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7580 | return err; |
| 7581 | } |
| 7582 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7583 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 7584 | { |
| 7585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7586 | struct net_device *dev = info->user_ptr[1]; |
| 7587 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7588 | struct cfg80211_csa_settings params; |
| 7589 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 7590 | * function is called under RTNL lock, so this should not be a problem. |
| 7591 | */ |
| 7592 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7593 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7594 | bool need_new_beacon = false; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7595 | bool need_handle_dfs_flag = true; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7596 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7597 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7598 | |
| 7599 | if (!rdev->ops->channel_switch || |
| 7600 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 7601 | return -EOPNOTSUPP; |
| 7602 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7603 | switch (dev->ieee80211_ptr->iftype) { |
| 7604 | case NL80211_IFTYPE_AP: |
| 7605 | case NL80211_IFTYPE_P2P_GO: |
| 7606 | need_new_beacon = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7607 | /* For all modes except AP the handle_dfs flag needs to be |
| 7608 | * supplied to tell the kernel that userspace will handle radar |
| 7609 | * events when they happen. Otherwise a switch to a channel |
| 7610 | * requiring DFS will be rejected. |
| 7611 | */ |
| 7612 | need_handle_dfs_flag = false; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7613 | |
| 7614 | /* useless if AP is not running */ |
| 7615 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7616 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7617 | break; |
| 7618 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7619 | if (!wdev->ssid_len) |
| 7620 | return -ENOTCONN; |
| 7621 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 7622 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7623 | if (!wdev->mesh_id_len) |
| 7624 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7625 | break; |
| 7626 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7627 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7628 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7629 | |
| 7630 | memset(¶ms, 0, sizeof(params)); |
| 7631 | |
| 7632 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7633 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 7634 | return -EINVAL; |
| 7635 | |
| 7636 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 7637 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7638 | return -EINVAL; |
| 7639 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7640 | /* Even though the attribute is u32, the specification says |
| 7641 | * u8, so let's make sure we don't overflow. |
| 7642 | */ |
| 7643 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 7644 | if (cs_count > 255) |
| 7645 | return -EINVAL; |
| 7646 | |
| 7647 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7648 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7649 | if (!need_new_beacon) |
| 7650 | goto skip_beacons; |
| 7651 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7652 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 7653 | if (err) |
| 7654 | return err; |
| 7655 | |
| 7656 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 7657 | info->attrs[NL80211_ATTR_CSA_IES], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 7658 | nl80211_policy, info->extack); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7659 | if (err) |
| 7660 | return err; |
| 7661 | |
| 7662 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 7663 | if (err) |
| 7664 | return err; |
| 7665 | |
| 7666 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 7667 | return -EINVAL; |
| 7668 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7669 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7670 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7671 | return -EINVAL; |
| 7672 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7673 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 7674 | if (rdev->wiphy.max_num_csa_counters && |
| 7675 | (params.n_counter_offsets_beacon > |
| 7676 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7677 | return -EINVAL; |
| 7678 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7679 | params.counter_offsets_beacon = |
| 7680 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7681 | |
| 7682 | /* sanity checks - counters should fit and be the same */ |
| 7683 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 7684 | u16 offset = params.counter_offsets_beacon[i]; |
| 7685 | |
| 7686 | if (offset >= params.beacon_csa.tail_len) |
| 7687 | return -EINVAL; |
| 7688 | |
| 7689 | if (params.beacon_csa.tail[offset] != params.count) |
| 7690 | return -EINVAL; |
| 7691 | } |
| 7692 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7693 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7694 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7695 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7696 | return -EINVAL; |
| 7697 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7698 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 7699 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 7700 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7701 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7702 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7703 | |
| 7704 | params.counter_offsets_presp = |
| 7705 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7706 | |
| 7707 | /* sanity checks - counters should fit and be the same */ |
| 7708 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 7709 | u16 offset = params.counter_offsets_presp[i]; |
| 7710 | |
| 7711 | if (offset >= params.beacon_csa.probe_resp_len) |
| 7712 | return -EINVAL; |
| 7713 | |
| 7714 | if (params.beacon_csa.probe_resp[offset] != |
| 7715 | params.count) |
| 7716 | return -EINVAL; |
| 7717 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7718 | } |
| 7719 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7720 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7721 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 7722 | if (err) |
| 7723 | return err; |
| 7724 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 7725 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 7726 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7727 | return -EINVAL; |
| 7728 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7729 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 7730 | ¶ms.chandef, |
| 7731 | wdev->iftype); |
| 7732 | if (err < 0) |
| 7733 | return err; |
| 7734 | |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7735 | if (err > 0) { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7736 | params.radar_required = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7737 | if (need_handle_dfs_flag && |
| 7738 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
| 7739 | return -EINVAL; |
| 7740 | } |
| 7741 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7742 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7743 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 7744 | params.block_tx = true; |
| 7745 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7746 | wdev_lock(wdev); |
| 7747 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 7748 | wdev_unlock(wdev); |
| 7749 | |
| 7750 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7751 | } |
| 7752 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7753 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 7754 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7755 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7756 | struct wireless_dev *wdev, |
| 7757 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7758 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7759 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7760 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7761 | void *hdr; |
| 7762 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7763 | |
| 7764 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7765 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7766 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7767 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 7768 | if (!hdr) |
| 7769 | return -1; |
| 7770 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 7771 | genl_dump_check_consistent(cb, hdr); |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7772 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7773 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 7774 | goto nla_put_failure; |
| 7775 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7776 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 7777 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7778 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 7779 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7780 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7781 | |
| 7782 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 7783 | if (!bss) |
| 7784 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7785 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7786 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7787 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7788 | |
| 7789 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7790 | /* indicate whether we have probe response data or not */ |
| 7791 | if (rcu_access_pointer(res->proberesp_ies) && |
| 7792 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 7793 | goto fail_unlock_rcu; |
| 7794 | |
| 7795 | /* this pointer prefers to be pointed to probe response data |
| 7796 | * but is always valid |
| 7797 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7798 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7799 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7800 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 7801 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7802 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7803 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 7804 | ies->len, ies->data)) |
| 7805 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7806 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7807 | |
| 7808 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7809 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7810 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7811 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 7812 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7813 | goto fail_unlock_rcu; |
| 7814 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 7815 | ies->len, ies->data)) |
| 7816 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7817 | } |
| 7818 | rcu_read_unlock(); |
| 7819 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7820 | if (res->beacon_interval && |
| 7821 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 7822 | goto nla_put_failure; |
| 7823 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 7824 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 7825 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7826 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 7827 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 7828 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7829 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7830 | if (intbss->parent_tsf && |
| 7831 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 7832 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 7833 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 7834 | intbss->parent_bssid))) |
| 7835 | goto nla_put_failure; |
| 7836 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7837 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7838 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 7839 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7840 | goto nla_put_failure; |
| 7841 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 7842 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7843 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7844 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 7845 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7846 | break; |
| 7847 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7848 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 7849 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7850 | break; |
| 7851 | default: |
| 7852 | break; |
| 7853 | } |
| 7854 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7855 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7856 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7857 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7858 | if (intbss == wdev->current_bss && |
| 7859 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7860 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 7861 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7862 | break; |
| 7863 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7864 | if (intbss == wdev->current_bss && |
| 7865 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7866 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 7867 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7868 | break; |
| 7869 | default: |
| 7870 | break; |
| 7871 | } |
| 7872 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7873 | nla_nest_end(msg, bss); |
| 7874 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7875 | genlmsg_end(msg, hdr); |
| 7876 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7877 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7878 | fail_unlock_rcu: |
| 7879 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7880 | nla_put_failure: |
| 7881 | genlmsg_cancel(msg, hdr); |
| 7882 | return -EMSGSIZE; |
| 7883 | } |
| 7884 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7885 | 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] | 7886 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7887 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7888 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7889 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7890 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7891 | int err; |
| 7892 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7893 | rtnl_lock(); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7894 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7895 | if (err) { |
| 7896 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7897 | return err; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7898 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7899 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7900 | wdev_lock(wdev); |
| 7901 | spin_lock_bh(&rdev->bss_lock); |
| 7902 | cfg80211_bss_expire(rdev); |
| 7903 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7904 | cb->seq = rdev->bss_generation; |
| 7905 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7906 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7907 | if (++idx <= start) |
| 7908 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7909 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7910 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7911 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7912 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7913 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7914 | } |
| 7915 | } |
| 7916 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7917 | spin_unlock_bh(&rdev->bss_lock); |
| 7918 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7919 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7920 | cb->args[2] = idx; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7921 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7922 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7923 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7924 | } |
| 7925 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7926 | 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] | 7927 | int flags, struct net_device *dev, |
| 7928 | bool allow_radio_stats, |
| 7929 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7930 | { |
| 7931 | void *hdr; |
| 7932 | struct nlattr *infoattr; |
| 7933 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7934 | /* skip radio stats if userspace didn't request them */ |
| 7935 | if (!survey->channel && !allow_radio_stats) |
| 7936 | return 0; |
| 7937 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7938 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7939 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 7940 | if (!hdr) |
| 7941 | return -ENOMEM; |
| 7942 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7943 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 7944 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7945 | |
| 7946 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 7947 | if (!infoattr) |
| 7948 | goto nla_put_failure; |
| 7949 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7950 | if (survey->channel && |
| 7951 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7952 | survey->channel->center_freq)) |
| 7953 | goto nla_put_failure; |
| 7954 | |
| 7955 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 7956 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 7957 | goto nla_put_failure; |
| 7958 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 7959 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 7960 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7961 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7962 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 7963 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7964 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7965 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7966 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 7967 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7968 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7969 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7970 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 7971 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7972 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7973 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7974 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 7975 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7976 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7977 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7978 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 7979 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7980 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7981 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7982 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 7983 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7984 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7985 | |
| 7986 | nla_nest_end(msg, infoattr); |
| 7987 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7988 | genlmsg_end(msg, hdr); |
| 7989 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7990 | |
| 7991 | nla_put_failure: |
| 7992 | genlmsg_cancel(msg, hdr); |
| 7993 | return -EMSGSIZE; |
| 7994 | } |
| 7995 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7996 | 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] | 7997 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 7998 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7999 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8000 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8001 | struct wireless_dev *wdev; |
| 8002 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8003 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8004 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8005 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8006 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8007 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 8008 | if (res) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8009 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8010 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8011 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8012 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8013 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8014 | if (!wdev->netdev) { |
| 8015 | res = -EINVAL; |
| 8016 | goto out_err; |
| 8017 | } |
| 8018 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8019 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8020 | res = -EOPNOTSUPP; |
| 8021 | goto out_err; |
| 8022 | } |
| 8023 | |
| 8024 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 8025 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8026 | if (res == -ENOENT) |
| 8027 | break; |
| 8028 | if (res) |
| 8029 | goto out_err; |
| 8030 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8031 | /* don't send disabled channels, but do send non-channel data */ |
| 8032 | if (survey.channel && |
| 8033 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 8034 | survey_idx++; |
| 8035 | continue; |
| 8036 | } |
| 8037 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8038 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8039 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8040 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 8041 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8042 | goto out; |
| 8043 | survey_idx++; |
| 8044 | } |
| 8045 | |
| 8046 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8047 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8048 | res = skb->len; |
| 8049 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 8050 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8051 | return res; |
| 8052 | } |
| 8053 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8054 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 8055 | { |
| 8056 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 8057 | NL80211_WPA_VERSION_2)); |
| 8058 | } |
| 8059 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8060 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 8061 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8062 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8063 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8064 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8065 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 8066 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8067 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8068 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8069 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8070 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8071 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8072 | return -EINVAL; |
| 8073 | |
| 8074 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8075 | return -EINVAL; |
| 8076 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 8077 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 8078 | return -EINVAL; |
| 8079 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8080 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 8081 | return -EINVAL; |
| 8082 | |
| 8083 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8084 | return -EINVAL; |
| 8085 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8086 | err = nl80211_parse_key(info, &key); |
| 8087 | if (err) |
| 8088 | return err; |
| 8089 | |
| 8090 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 8091 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 8092 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8093 | if (!key.p.key || !key.p.key_len) |
| 8094 | return -EINVAL; |
| 8095 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 8096 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 8097 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 8098 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 8099 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 8100 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8101 | return -EINVAL; |
| 8102 | } else { |
| 8103 | key.p.key_len = 0; |
| 8104 | key.p.key = NULL; |
| 8105 | } |
| 8106 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8107 | if (key.idx >= 0) { |
| 8108 | int i; |
| 8109 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8110 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8111 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 8112 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 8113 | ok = true; |
| 8114 | break; |
| 8115 | } |
| 8116 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8117 | if (!ok) |
| 8118 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8119 | } |
| 8120 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8121 | if (!rdev->ops->auth) |
| 8122 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8123 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8124 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8125 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8126 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8127 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8128 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8129 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8130 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8131 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8132 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8133 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8134 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8135 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8136 | |
| 8137 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8138 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8139 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8140 | } |
| 8141 | |
| 8142 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8143 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8144 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8145 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8146 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 8147 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 8148 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 8149 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8150 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8151 | return -EINVAL; |
| 8152 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8153 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8154 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 8155 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 8156 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 8157 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8158 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8159 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 8160 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8161 | /* need to include at least Auth Transaction and Status Code */ |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8162 | if (auth_data_len < 4) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8163 | return -EINVAL; |
| 8164 | } |
| 8165 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8166 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8167 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 8168 | /* |
| 8169 | * Since we no longer track auth state, ignore |
| 8170 | * requests to only change local state. |
| 8171 | */ |
| 8172 | if (local_state_change) |
| 8173 | return 0; |
| 8174 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8175 | wdev_lock(dev->ieee80211_ptr); |
| 8176 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 8177 | ssid, ssid_len, ie, ie_len, |
| 8178 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8179 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8180 | wdev_unlock(dev->ieee80211_ptr); |
| 8181 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8182 | } |
| 8183 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8184 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 8185 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8186 | struct cfg80211_crypto_settings *settings, |
| 8187 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8188 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 8189 | memset(settings, 0, sizeof(*settings)); |
| 8190 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8191 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 8192 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8193 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 8194 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8195 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8196 | proto = nla_get_u16( |
| 8197 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 8198 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 8199 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 8200 | proto != ETH_P_PAE) |
| 8201 | return -EINVAL; |
| 8202 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 8203 | settings->control_port_no_encrypt = true; |
| 8204 | } else |
| 8205 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 8206 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8207 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 8208 | void *data; |
| 8209 | int len, i; |
| 8210 | |
| 8211 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8212 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8213 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 8214 | |
| 8215 | if (len % sizeof(u32)) |
| 8216 | return -EINVAL; |
| 8217 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8218 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8219 | return -EINVAL; |
| 8220 | |
| 8221 | memcpy(settings->ciphers_pairwise, data, len); |
| 8222 | |
| 8223 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8224 | if (!cfg80211_supported_cipher_suite( |
| 8225 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8226 | settings->ciphers_pairwise[i])) |
| 8227 | return -EINVAL; |
| 8228 | } |
| 8229 | |
| 8230 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 8231 | settings->cipher_group = |
| 8232 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8233 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 8234 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8235 | return -EINVAL; |
| 8236 | } |
| 8237 | |
| 8238 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 8239 | settings->wpa_versions = |
| 8240 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 8241 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 8242 | return -EINVAL; |
| 8243 | } |
| 8244 | |
| 8245 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 8246 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 8247 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8248 | |
| 8249 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8250 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8251 | settings->n_akm_suites = len / sizeof(u32); |
| 8252 | |
| 8253 | if (len % sizeof(u32)) |
| 8254 | return -EINVAL; |
| 8255 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 8256 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 8257 | return -EINVAL; |
| 8258 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8259 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8260 | } |
| 8261 | |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 8262 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 8263 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 8264 | return -EINVAL; |
| 8265 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8266 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) |
| 8267 | return -EINVAL; |
| 8268 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 8269 | } |
| 8270 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8271 | return 0; |
| 8272 | } |
| 8273 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8274 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 8275 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8276 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8277 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8278 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8279 | struct cfg80211_assoc_request req = {}; |
| 8280 | const u8 *bssid, *ssid; |
| 8281 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8282 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8283 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8284 | return -EINVAL; |
| 8285 | |
| 8286 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8287 | !info->attrs[NL80211_ATTR_SSID] || |
| 8288 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8289 | return -EINVAL; |
| 8290 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8291 | if (!rdev->ops->assoc) |
| 8292 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8293 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8294 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8295 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8296 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8297 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8298 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8299 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8300 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8301 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8302 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8303 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8304 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8305 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8306 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8307 | |
| 8308 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8309 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8310 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8311 | } |
| 8312 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8313 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8314 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8315 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8316 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8317 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8318 | else if (mfp != NL80211_MFP_NO) |
| 8319 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8320 | } |
| 8321 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8322 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8323 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8324 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8325 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8326 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8327 | |
| 8328 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8329 | memcpy(&req.ht_capa_mask, |
| 8330 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8331 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8332 | |
| 8333 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8334 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8335 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8336 | memcpy(&req.ht_capa, |
| 8337 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8338 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8339 | } |
| 8340 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8341 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8342 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8343 | |
| 8344 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8345 | memcpy(&req.vht_capa_mask, |
| 8346 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8347 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8348 | |
| 8349 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8350 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8351 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8352 | memcpy(&req.vht_capa, |
| 8353 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8354 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8355 | } |
| 8356 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8357 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8358 | if (!((rdev->wiphy.features & |
| 8359 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8360 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8361 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8362 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8363 | return -EINVAL; |
| 8364 | req.flags |= ASSOC_REQ_USE_RRM; |
| 8365 | } |
| 8366 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 8367 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 8368 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8369 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8370 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 8371 | return -EINVAL; |
| 8372 | req.fils_nonces = |
| 8373 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 8374 | } |
| 8375 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8376 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8377 | if (!err) { |
| 8378 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8379 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8380 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 8381 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8382 | |
| 8383 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8384 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 8385 | info->snd_portid; |
| 8386 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 8387 | bssid, ETH_ALEN); |
| 8388 | } |
| 8389 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8390 | wdev_unlock(dev->ieee80211_ptr); |
| 8391 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8392 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8393 | return err; |
| 8394 | } |
| 8395 | |
| 8396 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 8397 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8398 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8399 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8400 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8401 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8402 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8403 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8404 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8405 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8406 | return -EINVAL; |
| 8407 | |
| 8408 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8409 | return -EINVAL; |
| 8410 | |
| 8411 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8412 | return -EINVAL; |
| 8413 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8414 | if (!rdev->ops->deauth) |
| 8415 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8416 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8417 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8418 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8419 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8420 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8421 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8422 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8423 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8424 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8425 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8426 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8427 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8428 | |
| 8429 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8430 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8431 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8432 | } |
| 8433 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8434 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8435 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8436 | wdev_lock(dev->ieee80211_ptr); |
| 8437 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8438 | local_state_change); |
| 8439 | wdev_unlock(dev->ieee80211_ptr); |
| 8440 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8441 | } |
| 8442 | |
| 8443 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 8444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8446 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8447 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8448 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8449 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8450 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8451 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8452 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8453 | return -EINVAL; |
| 8454 | |
| 8455 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8456 | return -EINVAL; |
| 8457 | |
| 8458 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8459 | return -EINVAL; |
| 8460 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8461 | if (!rdev->ops->disassoc) |
| 8462 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8463 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8464 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8465 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8466 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8467 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8468 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8469 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8470 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8471 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8472 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8473 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8474 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8475 | |
| 8476 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8477 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8478 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 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 | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8483 | wdev_lock(dev->ieee80211_ptr); |
| 8484 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8485 | local_state_change); |
| 8486 | wdev_unlock(dev->ieee80211_ptr); |
| 8487 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8488 | } |
| 8489 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8490 | static bool |
| 8491 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8492 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8493 | int rateval) |
| 8494 | { |
| 8495 | struct wiphy *wiphy = &rdev->wiphy; |
| 8496 | bool found = false; |
| 8497 | int band, i; |
| 8498 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8499 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8500 | struct ieee80211_supported_band *sband; |
| 8501 | |
| 8502 | sband = wiphy->bands[band]; |
| 8503 | if (!sband) |
| 8504 | continue; |
| 8505 | |
| 8506 | for (i = 0; i < sband->n_bitrates; i++) { |
| 8507 | if (sband->bitrates[i].bitrate == rateval) { |
| 8508 | mcast_rate[band] = i + 1; |
| 8509 | found = true; |
| 8510 | break; |
| 8511 | } |
| 8512 | } |
| 8513 | } |
| 8514 | |
| 8515 | return found; |
| 8516 | } |
| 8517 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8518 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8519 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8521 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8522 | struct cfg80211_ibss_params ibss; |
| 8523 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8524 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8525 | int err; |
| 8526 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8527 | memset(&ibss, 0, sizeof(ibss)); |
| 8528 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8529 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8530 | return -EINVAL; |
| 8531 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8532 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8533 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8534 | return -EINVAL; |
| 8535 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8536 | ibss.beacon_interval = 100; |
| 8537 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8538 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8539 | ibss.beacon_interval = |
| 8540 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8541 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 8542 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 8543 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8544 | if (err) |
| 8545 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8546 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8547 | if (!rdev->ops->join_ibss) |
| 8548 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8549 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8550 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8551 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8552 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8553 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8554 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8555 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8556 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8557 | |
| 8558 | if (!is_valid_ether_addr(ibss.bssid)) |
| 8559 | return -EINVAL; |
| 8560 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8561 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8562 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8563 | |
| 8564 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8565 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8566 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8567 | } |
| 8568 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8569 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 8570 | if (err) |
| 8571 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8572 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 8573 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 8574 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8575 | return -EINVAL; |
| 8576 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8577 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 8578 | case NL80211_CHAN_WIDTH_5: |
| 8579 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8580 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 8581 | break; |
| 8582 | case NL80211_CHAN_WIDTH_20: |
| 8583 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 8584 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8585 | return -EINVAL; |
| 8586 | break; |
| 8587 | case NL80211_CHAN_WIDTH_80: |
| 8588 | case NL80211_CHAN_WIDTH_80P80: |
| 8589 | case NL80211_CHAN_WIDTH_160: |
| 8590 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8591 | return -EINVAL; |
| 8592 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8593 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 8594 | return -EINVAL; |
| 8595 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8596 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8597 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8598 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8599 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8600 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8601 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8602 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8603 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8604 | u8 *rates = |
| 8605 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8606 | int n_rates = |
| 8607 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8608 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8609 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8610 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8611 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8612 | &ibss.basic_rates); |
| 8613 | if (err) |
| 8614 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8615 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8616 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 8617 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8618 | memcpy(&ibss.ht_capa_mask, |
| 8619 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8620 | sizeof(ibss.ht_capa_mask)); |
| 8621 | |
| 8622 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 8623 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8624 | return -EINVAL; |
| 8625 | memcpy(&ibss.ht_capa, |
| 8626 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8627 | sizeof(ibss.ht_capa)); |
| 8628 | } |
| 8629 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8630 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8631 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 8632 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8633 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8634 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8635 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8636 | bool no_ht = false; |
| 8637 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 8638 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8639 | if (IS_ERR(connkeys)) |
| 8640 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8641 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 8642 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 8643 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 8644 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8645 | return -EINVAL; |
| 8646 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8647 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8648 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 8649 | ibss.control_port = |
| 8650 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 8651 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 8652 | ibss.userspace_handles_dfs = |
| 8653 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 8654 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8655 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8656 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8657 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8658 | return err; |
| 8659 | } |
| 8660 | |
| 8661 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8662 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8663 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8664 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8665 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8666 | if (!rdev->ops->leave_ibss) |
| 8667 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8668 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8669 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8670 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8671 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8672 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8673 | } |
| 8674 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8675 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 8676 | { |
| 8677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8678 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8679 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8680 | u32 nla_rate; |
| 8681 | int err; |
| 8682 | |
| 8683 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 8684 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 8685 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8686 | return -EOPNOTSUPP; |
| 8687 | |
| 8688 | if (!rdev->ops->set_mcast_rate) |
| 8689 | return -EOPNOTSUPP; |
| 8690 | |
| 8691 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 8692 | |
| 8693 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 8694 | return -EINVAL; |
| 8695 | |
| 8696 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 8697 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 8698 | return -EINVAL; |
| 8699 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8700 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8701 | |
| 8702 | return err; |
| 8703 | } |
| 8704 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8705 | static struct sk_buff * |
| 8706 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8707 | struct wireless_dev *wdev, int approxlen, |
| 8708 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8709 | enum nl80211_attrs attr, |
| 8710 | const struct nl80211_vendor_cmd_info *info, |
| 8711 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8712 | { |
| 8713 | struct sk_buff *skb; |
| 8714 | void *hdr; |
| 8715 | struct nlattr *data; |
| 8716 | |
| 8717 | skb = nlmsg_new(approxlen + 100, gfp); |
| 8718 | if (!skb) |
| 8719 | return NULL; |
| 8720 | |
| 8721 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 8722 | if (!hdr) { |
| 8723 | kfree_skb(skb); |
| 8724 | return NULL; |
| 8725 | } |
| 8726 | |
| 8727 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 8728 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8729 | |
| 8730 | if (info) { |
| 8731 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 8732 | info->vendor_id)) |
| 8733 | goto nla_put_failure; |
| 8734 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 8735 | info->subcmd)) |
| 8736 | goto nla_put_failure; |
| 8737 | } |
| 8738 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8739 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8740 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 8741 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8742 | goto nla_put_failure; |
| 8743 | if (wdev->netdev && |
| 8744 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 8745 | wdev->netdev->ifindex)) |
| 8746 | goto nla_put_failure; |
| 8747 | } |
| 8748 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8749 | data = nla_nest_start(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 8750 | if (!data) |
| 8751 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8752 | |
| 8753 | ((void **)skb->cb)[0] = rdev; |
| 8754 | ((void **)skb->cb)[1] = hdr; |
| 8755 | ((void **)skb->cb)[2] = data; |
| 8756 | |
| 8757 | return skb; |
| 8758 | |
| 8759 | nla_put_failure: |
| 8760 | kfree_skb(skb); |
| 8761 | return NULL; |
| 8762 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8763 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8764 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8765 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8766 | enum nl80211_commands cmd, |
| 8767 | enum nl80211_attrs attr, |
| 8768 | int vendor_event_idx, |
| 8769 | int approxlen, gfp_t gfp) |
| 8770 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 8771 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8772 | const struct nl80211_vendor_cmd_info *info; |
| 8773 | |
| 8774 | switch (cmd) { |
| 8775 | case NL80211_CMD_TESTMODE: |
| 8776 | if (WARN_ON(vendor_event_idx != -1)) |
| 8777 | return NULL; |
| 8778 | info = NULL; |
| 8779 | break; |
| 8780 | case NL80211_CMD_VENDOR: |
| 8781 | if (WARN_ON(vendor_event_idx < 0 || |
| 8782 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 8783 | return NULL; |
| 8784 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 8785 | break; |
| 8786 | default: |
| 8787 | WARN_ON(1); |
| 8788 | return NULL; |
| 8789 | } |
| 8790 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8791 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8792 | cmd, attr, info, gfp); |
| 8793 | } |
| 8794 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 8795 | |
| 8796 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 8797 | { |
| 8798 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8799 | void *hdr = ((void **)skb->cb)[1]; |
| 8800 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8801 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 8802 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 8803 | /* clear CB data for netlink core to own from now on */ |
| 8804 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 8805 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8806 | nla_nest_end(skb, data); |
| 8807 | genlmsg_end(skb, hdr); |
| 8808 | |
| 8809 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 8810 | mcgrp = NL80211_MCGRP_VENDOR; |
| 8811 | |
| 8812 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 8813 | mcgrp, gfp); |
| 8814 | } |
| 8815 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 8816 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8817 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8818 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 8819 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8821 | struct wireless_dev *wdev = |
| 8822 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8823 | int err; |
| 8824 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8825 | if (!rdev->ops->testmode_cmd) |
| 8826 | return -EOPNOTSUPP; |
| 8827 | |
| 8828 | if (IS_ERR(wdev)) { |
| 8829 | err = PTR_ERR(wdev); |
| 8830 | if (err != -EINVAL) |
| 8831 | return err; |
| 8832 | wdev = NULL; |
| 8833 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8834 | return -EINVAL; |
| 8835 | } |
| 8836 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8837 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 8838 | return -EINVAL; |
| 8839 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8840 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8841 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8842 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 8843 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8844 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8845 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8846 | return err; |
| 8847 | } |
| 8848 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8849 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 8850 | struct netlink_callback *cb) |
| 8851 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8852 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8853 | int err; |
| 8854 | long phy_idx; |
| 8855 | void *data = NULL; |
| 8856 | int data_len = 0; |
| 8857 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8858 | rtnl_lock(); |
| 8859 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8860 | if (cb->args[0]) { |
| 8861 | /* |
| 8862 | * 0 is a valid index, but not valid for args[0], |
| 8863 | * so we need to offset by 1. |
| 8864 | */ |
| 8865 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 8866 | |
| 8867 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 8868 | if (!rdev) { |
| 8869 | err = -ENOENT; |
| 8870 | goto out_err; |
| 8871 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8872 | } else { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8873 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
| 8874 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8875 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 8876 | attrbuf, nl80211_fam.maxattr, |
| 8877 | nl80211_policy, NULL); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8878 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8879 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8880 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8881 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8882 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8883 | err = PTR_ERR(rdev); |
| 8884 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8885 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8886 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8887 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8888 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 8889 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8890 | } |
| 8891 | |
| 8892 | if (cb->args[1]) { |
| 8893 | data = nla_data((void *)cb->args[1]); |
| 8894 | data_len = nla_len((void *)cb->args[1]); |
| 8895 | } |
| 8896 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8897 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8898 | err = -EOPNOTSUPP; |
| 8899 | goto out_err; |
| 8900 | } |
| 8901 | |
| 8902 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8903 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8904 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 8905 | NL80211_CMD_TESTMODE); |
| 8906 | struct nlattr *tmdata; |
| 8907 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8908 | if (!hdr) |
| 8909 | break; |
| 8910 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8911 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8912 | genlmsg_cancel(skb, hdr); |
| 8913 | break; |
| 8914 | } |
| 8915 | |
| 8916 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 8917 | if (!tmdata) { |
| 8918 | genlmsg_cancel(skb, hdr); |
| 8919 | break; |
| 8920 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8921 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8922 | nla_nest_end(skb, tmdata); |
| 8923 | |
| 8924 | if (err == -ENOBUFS || err == -ENOENT) { |
| 8925 | genlmsg_cancel(skb, hdr); |
| 8926 | break; |
| 8927 | } else if (err) { |
| 8928 | genlmsg_cancel(skb, hdr); |
| 8929 | goto out_err; |
| 8930 | } |
| 8931 | |
| 8932 | genlmsg_end(skb, hdr); |
| 8933 | } |
| 8934 | |
| 8935 | err = skb->len; |
| 8936 | /* see above */ |
| 8937 | cb->args[0] = phy_idx + 1; |
| 8938 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8939 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8940 | return err; |
| 8941 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8942 | #endif |
| 8943 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8944 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 8945 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8947 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8948 | struct cfg80211_connect_params connect; |
| 8949 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8950 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8951 | int err; |
| 8952 | |
| 8953 | memset(&connect, 0, sizeof(connect)); |
| 8954 | |
| 8955 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8956 | return -EINVAL; |
| 8957 | |
| 8958 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 8959 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8960 | return -EINVAL; |
| 8961 | |
| 8962 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8963 | connect.auth_type = |
| 8964 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8965 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 8966 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8967 | return -EINVAL; |
| 8968 | } else |
| 8969 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 8970 | |
| 8971 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 8972 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 8973 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 8974 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8975 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 8976 | return -EINVAL; |
| 8977 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 8978 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8979 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8980 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8981 | if (err) |
| 8982 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8983 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8984 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8985 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8986 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8987 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8988 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8989 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 8990 | connect.bg_scan_period = -1; |
| 8991 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 8992 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 8993 | connect.bg_scan_period = |
| 8994 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 8995 | } |
| 8996 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8997 | if (info->attrs[NL80211_ATTR_MAC]) |
| 8998 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8999 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 9000 | connect.bssid_hint = |
| 9001 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9002 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9003 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9004 | |
| 9005 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9006 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9007 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9008 | } |
| 9009 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 9010 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 9011 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 9012 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
| 9013 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9014 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) |
| 9015 | return -EOPNOTSUPP; |
| 9016 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 9017 | if (connect.mfp != NL80211_MFP_REQUIRED && |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 9018 | connect.mfp != NL80211_MFP_NO && |
| 9019 | connect.mfp != NL80211_MFP_OPTIONAL) |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 9020 | return -EINVAL; |
| 9021 | } else { |
| 9022 | connect.mfp = NL80211_MFP_NO; |
| 9023 | } |
| 9024 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 9025 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 9026 | connect.prev_bssid = |
| 9027 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 9028 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9029 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9030 | connect.channel = nl80211_get_valid_chan( |
| 9031 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 9032 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9033 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 9034 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9035 | connect.channel_hint = nl80211_get_valid_chan( |
| 9036 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 9037 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 9038 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9039 | } |
| 9040 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9041 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 9042 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9043 | if (IS_ERR(connkeys)) |
| 9044 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9045 | } |
| 9046 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9047 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 9048 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 9049 | |
| 9050 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9051 | memcpy(&connect.ht_capa_mask, |
| 9052 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9053 | sizeof(connect.ht_capa_mask)); |
| 9054 | |
| 9055 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 9056 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9057 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9058 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 9059 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9060 | memcpy(&connect.ht_capa, |
| 9061 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9062 | sizeof(connect.ht_capa)); |
| 9063 | } |
| 9064 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9065 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 9066 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 9067 | |
| 9068 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 9069 | memcpy(&connect.vht_capa_mask, |
| 9070 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 9071 | sizeof(connect.vht_capa_mask)); |
| 9072 | |
| 9073 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 9074 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9075 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9076 | return -EINVAL; |
| 9077 | } |
| 9078 | memcpy(&connect.vht_capa, |
| 9079 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 9080 | sizeof(connect.vht_capa)); |
| 9081 | } |
| 9082 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9083 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 9084 | if (!((rdev->wiphy.features & |
| 9085 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 9086 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 9087 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9088 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 9089 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9090 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 9091 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9092 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 9093 | } |
| 9094 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 9095 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9096 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 9097 | kzfree(connkeys); |
| 9098 | return -EOPNOTSUPP; |
| 9099 | } |
| 9100 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 9101 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 9102 | /* bss selection makes no sense if bssid is set */ |
| 9103 | if (connect.bssid) { |
| 9104 | kzfree(connkeys); |
| 9105 | return -EINVAL; |
| 9106 | } |
| 9107 | |
| 9108 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 9109 | wiphy, &connect.bss_select); |
| 9110 | if (err) { |
| 9111 | kzfree(connkeys); |
| 9112 | return err; |
| 9113 | } |
| 9114 | } |
| 9115 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9116 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 9117 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 9118 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 9119 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 9120 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 9121 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9122 | connect.fils_erp_username = |
| 9123 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9124 | connect.fils_erp_username_len = |
| 9125 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9126 | connect.fils_erp_realm = |
| 9127 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9128 | connect.fils_erp_realm_len = |
| 9129 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9130 | connect.fils_erp_next_seq_num = |
| 9131 | nla_get_u16( |
| 9132 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 9133 | connect.fils_erp_rrk = |
| 9134 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9135 | connect.fils_erp_rrk_len = |
| 9136 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9137 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 9138 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 9139 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 9140 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9141 | kzfree(connkeys); |
| 9142 | return -EINVAL; |
| 9143 | } |
| 9144 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9145 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9146 | |
Jouni Malinen | 4ce2bd9c4 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 9147 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 9148 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9149 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9150 | kzfree(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9151 | |
| 9152 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9153 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 9154 | if (connect.bssid) |
| 9155 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 9156 | connect.bssid, ETH_ALEN); |
| 9157 | else |
| 9158 | memset(dev->ieee80211_ptr->disconnect_bssid, |
| 9159 | 0, ETH_ALEN); |
| 9160 | } |
| 9161 | |
| 9162 | wdev_unlock(dev->ieee80211_ptr); |
| 9163 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9164 | return err; |
| 9165 | } |
| 9166 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 9167 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 9168 | struct genl_info *info) |
| 9169 | { |
| 9170 | struct cfg80211_connect_params connect = {}; |
| 9171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9172 | struct net_device *dev = info->user_ptr[1]; |
| 9173 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9174 | u32 changed = 0; |
| 9175 | int ret; |
| 9176 | |
| 9177 | if (!rdev->ops->update_connect_params) |
| 9178 | return -EOPNOTSUPP; |
| 9179 | |
| 9180 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9181 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9182 | return -EINVAL; |
| 9183 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9184 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9185 | changed |= UPDATE_ASSOC_IES; |
| 9186 | } |
| 9187 | |
| 9188 | wdev_lock(dev->ieee80211_ptr); |
| 9189 | if (!wdev->current_bss) |
| 9190 | ret = -ENOLINK; |
| 9191 | else |
| 9192 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 9193 | wdev_unlock(dev->ieee80211_ptr); |
| 9194 | |
| 9195 | return ret; |
| 9196 | } |
| 9197 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9198 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 9199 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9201 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9202 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9203 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9204 | |
| 9205 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9206 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 9207 | else |
| 9208 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9209 | |
| 9210 | if (reason == 0) |
| 9211 | return -EINVAL; |
| 9212 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9213 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9214 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9215 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9216 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9217 | wdev_lock(dev->ieee80211_ptr); |
| 9218 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 9219 | wdev_unlock(dev->ieee80211_ptr); |
| 9220 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9221 | } |
| 9222 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9223 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 9224 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9225 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9226 | struct net *net; |
| 9227 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9228 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9229 | if (info->attrs[NL80211_ATTR_PID]) { |
| 9230 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 9231 | |
| 9232 | net = get_net_ns_by_pid(pid); |
| 9233 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 9234 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 9235 | |
| 9236 | net = get_net_ns_by_fd(fd); |
| 9237 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9238 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9239 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9240 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9241 | if (IS_ERR(net)) |
| 9242 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9243 | |
| 9244 | err = 0; |
| 9245 | |
| 9246 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9247 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 9248 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9249 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9250 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9251 | return err; |
| 9252 | } |
| 9253 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9254 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9255 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9257 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 9258 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9259 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9260 | struct cfg80211_pmksa pmksa; |
| 9261 | |
| 9262 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 9263 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9264 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 9265 | return -EINVAL; |
| 9266 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9267 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9268 | |
| 9269 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 9270 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9271 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 9272 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 9273 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 9274 | info->attrs[NL80211_ATTR_PMK])) { |
| 9275 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9276 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9277 | pmksa.cache_id = |
| 9278 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 9279 | } else { |
| 9280 | return -EINVAL; |
| 9281 | } |
| 9282 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9283 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9284 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 9285 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9286 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9287 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9288 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9289 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9290 | |
| 9291 | switch (info->genlhdr->cmd) { |
| 9292 | case NL80211_CMD_SET_PMKSA: |
| 9293 | rdev_ops = rdev->ops->set_pmksa; |
| 9294 | break; |
| 9295 | case NL80211_CMD_DEL_PMKSA: |
| 9296 | rdev_ops = rdev->ops->del_pmksa; |
| 9297 | break; |
| 9298 | default: |
| 9299 | WARN_ON(1); |
| 9300 | break; |
| 9301 | } |
| 9302 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9303 | if (!rdev_ops) |
| 9304 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9305 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9306 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9307 | } |
| 9308 | |
| 9309 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9310 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9312 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9313 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9314 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9315 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9316 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9317 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9318 | if (!rdev->ops->flush_pmksa) |
| 9319 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9320 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9321 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9322 | } |
| 9323 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9324 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 9325 | { |
| 9326 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9327 | struct net_device *dev = info->user_ptr[1]; |
| 9328 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9329 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9330 | u16 status_code; |
| 9331 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9332 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9333 | |
| 9334 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9335 | !rdev->ops->tdls_mgmt) |
| 9336 | return -EOPNOTSUPP; |
| 9337 | |
| 9338 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 9339 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 9340 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 9341 | !info->attrs[NL80211_ATTR_IE] || |
| 9342 | !info->attrs[NL80211_ATTR_MAC]) |
| 9343 | return -EINVAL; |
| 9344 | |
| 9345 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9346 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 9347 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 9348 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9349 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9350 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 9351 | peer_capability = |
| 9352 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9353 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9354 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9355 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9356 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9357 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 9358 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9359 | } |
| 9360 | |
| 9361 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 9362 | { |
| 9363 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9364 | struct net_device *dev = info->user_ptr[1]; |
| 9365 | enum nl80211_tdls_operation operation; |
| 9366 | u8 *peer; |
| 9367 | |
| 9368 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9369 | !rdev->ops->tdls_oper) |
| 9370 | return -EOPNOTSUPP; |
| 9371 | |
| 9372 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 9373 | !info->attrs[NL80211_ATTR_MAC]) |
| 9374 | return -EINVAL; |
| 9375 | |
| 9376 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 9377 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9378 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9379 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9380 | } |
| 9381 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9382 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 9383 | struct genl_info *info) |
| 9384 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9385 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9386 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9387 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9388 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9389 | struct sk_buff *msg; |
| 9390 | void *hdr; |
| 9391 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9392 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9393 | int err; |
| 9394 | |
| 9395 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 9396 | !info->attrs[NL80211_ATTR_DURATION]) |
| 9397 | return -EINVAL; |
| 9398 | |
| 9399 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 9400 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9401 | if (!rdev->ops->remain_on_channel || |
| 9402 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9403 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9404 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9405 | /* |
| 9406 | * We should be on that channel for at least a minimum amount of |
| 9407 | * time (10ms) but no longer than the driver supports. |
| 9408 | */ |
| 9409 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9410 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 9411 | return -EINVAL; |
| 9412 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9413 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9414 | if (err) |
| 9415 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9416 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9417 | wdev_lock(wdev); |
| 9418 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 9419 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 9420 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 9421 | &chandef); |
| 9422 | if (compat_chandef != &chandef) { |
| 9423 | wdev_unlock(wdev); |
| 9424 | return -EBUSY; |
| 9425 | } |
| 9426 | } |
| 9427 | wdev_unlock(wdev); |
| 9428 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9429 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9430 | if (!msg) |
| 9431 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9432 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9433 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9434 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9435 | if (!hdr) { |
| 9436 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9437 | goto free_msg; |
| 9438 | } |
| 9439 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9440 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 9441 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9442 | |
| 9443 | if (err) |
| 9444 | goto free_msg; |
| 9445 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9446 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9447 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9448 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9449 | |
| 9450 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9451 | |
| 9452 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9453 | |
| 9454 | nla_put_failure: |
| 9455 | err = -ENOBUFS; |
| 9456 | free_msg: |
| 9457 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9458 | return err; |
| 9459 | } |
| 9460 | |
| 9461 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 9462 | struct genl_info *info) |
| 9463 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9465 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9466 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9467 | |
| 9468 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9469 | return -EINVAL; |
| 9470 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9471 | if (!rdev->ops->cancel_remain_on_channel) |
| 9472 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9473 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9474 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9475 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9476 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9477 | } |
| 9478 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9479 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 9480 | struct genl_info *info) |
| 9481 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9482 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9484 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9485 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9486 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9487 | if (!rdev->ops->set_bitrate_mask) |
| 9488 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9489 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9490 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
| 9491 | if (err) |
| 9492 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 9493 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9494 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9495 | } |
| 9496 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9497 | 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] | 9498 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9500 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9501 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9502 | |
| 9503 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 9504 | return -EINVAL; |
| 9505 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9506 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 9507 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9508 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9509 | switch (wdev->iftype) { |
| 9510 | case NL80211_IFTYPE_STATION: |
| 9511 | case NL80211_IFTYPE_ADHOC: |
| 9512 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9513 | case NL80211_IFTYPE_AP: |
| 9514 | case NL80211_IFTYPE_AP_VLAN: |
| 9515 | case NL80211_IFTYPE_MESH_POINT: |
| 9516 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9517 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9518 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9519 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9520 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9521 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9522 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9523 | |
| 9524 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9525 | if (!rdev->ops->mgmt_tx) |
| 9526 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9527 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9528 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9529 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 9530 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9531 | } |
| 9532 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9533 | 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] | 9534 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9535 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9536 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9537 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9538 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 9539 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9540 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9541 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9542 | struct cfg80211_mgmt_tx_params params = { |
| 9543 | .dont_wait_for_ack = |
| 9544 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 9545 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9546 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9547 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9548 | return -EINVAL; |
| 9549 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9550 | if (!rdev->ops->mgmt_tx) |
| 9551 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9552 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9553 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9554 | case NL80211_IFTYPE_P2P_DEVICE: |
| 9555 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9556 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9557 | case NL80211_IFTYPE_STATION: |
| 9558 | case NL80211_IFTYPE_ADHOC: |
| 9559 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9560 | case NL80211_IFTYPE_AP: |
| 9561 | case NL80211_IFTYPE_AP_VLAN: |
| 9562 | case NL80211_IFTYPE_MESH_POINT: |
| 9563 | case NL80211_IFTYPE_P2P_GO: |
| 9564 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9565 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9566 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9567 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9568 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9569 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9570 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9571 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9572 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9573 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9574 | |
| 9575 | /* |
| 9576 | * We should wait on the channel for at least a minimum amount |
| 9577 | * of time (10ms) but no longer than the driver supports. |
| 9578 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9579 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9580 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9581 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9582 | } |
| 9583 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9584 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9585 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9586 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9587 | return -EINVAL; |
| 9588 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9589 | 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] | 9590 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9591 | /* get the channel if any has been specified, otherwise pass NULL to |
| 9592 | * the driver. The latter will use the current one |
| 9593 | */ |
| 9594 | chandef.chan = NULL; |
| 9595 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 9596 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9597 | if (err) |
| 9598 | return err; |
| 9599 | } |
| 9600 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9601 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9602 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9603 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9604 | wdev_lock(wdev); |
| 9605 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 9606 | wdev_unlock(wdev); |
| 9607 | return -EBUSY; |
| 9608 | } |
| 9609 | wdev_unlock(wdev); |
| 9610 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 9611 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 9612 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 9613 | |
| 9614 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 9615 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9616 | int i; |
| 9617 | |
| 9618 | if (len % sizeof(u16)) |
| 9619 | return -EINVAL; |
| 9620 | |
| 9621 | params.n_csa_offsets = len / sizeof(u16); |
| 9622 | params.csa_offsets = |
| 9623 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9624 | |
| 9625 | /* check that all the offsets fit the frame */ |
| 9626 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 9627 | if (params.csa_offsets[i] >= params.len) |
| 9628 | return -EINVAL; |
| 9629 | } |
| 9630 | } |
| 9631 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9632 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9633 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9634 | if (!msg) |
| 9635 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9636 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9637 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9638 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9639 | if (!hdr) { |
| 9640 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9641 | goto free_msg; |
| 9642 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9643 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9644 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9645 | params.chan = chandef.chan; |
| 9646 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9647 | if (err) |
| 9648 | goto free_msg; |
| 9649 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9650 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9651 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9652 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9653 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9654 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9655 | genlmsg_end(msg, hdr); |
| 9656 | return genlmsg_reply(msg, info); |
| 9657 | } |
| 9658 | |
| 9659 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9660 | |
| 9661 | nla_put_failure: |
| 9662 | err = -ENOBUFS; |
| 9663 | free_msg: |
| 9664 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9665 | return err; |
| 9666 | } |
| 9667 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9668 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 9669 | { |
| 9670 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9671 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9672 | u64 cookie; |
| 9673 | |
| 9674 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9675 | return -EINVAL; |
| 9676 | |
| 9677 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 9678 | return -EOPNOTSUPP; |
| 9679 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9680 | switch (wdev->iftype) { |
| 9681 | case NL80211_IFTYPE_STATION: |
| 9682 | case NL80211_IFTYPE_ADHOC: |
| 9683 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9684 | case NL80211_IFTYPE_AP: |
| 9685 | case NL80211_IFTYPE_AP_VLAN: |
| 9686 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9687 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9688 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9689 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9690 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9691 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9692 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9693 | |
| 9694 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9695 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9696 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9697 | } |
| 9698 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9699 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9700 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9702 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9703 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9704 | u8 ps_state; |
| 9705 | bool state; |
| 9706 | int err; |
| 9707 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9708 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 9709 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9710 | |
| 9711 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 9712 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9713 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 9714 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9715 | |
| 9716 | wdev = dev->ieee80211_ptr; |
| 9717 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9718 | if (!rdev->ops->set_power_mgmt) |
| 9719 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9720 | |
| 9721 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 9722 | |
| 9723 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9724 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9725 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9726 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9727 | if (!err) |
| 9728 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9729 | return err; |
| 9730 | } |
| 9731 | |
| 9732 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9733 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9734 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9735 | enum nl80211_ps_state ps_state; |
| 9736 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9737 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9738 | struct sk_buff *msg; |
| 9739 | void *hdr; |
| 9740 | int err; |
| 9741 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9742 | wdev = dev->ieee80211_ptr; |
| 9743 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9744 | if (!rdev->ops->set_power_mgmt) |
| 9745 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9746 | |
| 9747 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9748 | if (!msg) |
| 9749 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9750 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9751 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9752 | NL80211_CMD_GET_POWER_SAVE); |
| 9753 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9754 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9755 | goto free_msg; |
| 9756 | } |
| 9757 | |
| 9758 | if (wdev->ps) |
| 9759 | ps_state = NL80211_PS_ENABLED; |
| 9760 | else |
| 9761 | ps_state = NL80211_PS_DISABLED; |
| 9762 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9763 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 9764 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9765 | |
| 9766 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9767 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9768 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9769 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9770 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9771 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9772 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9773 | return err; |
| 9774 | } |
| 9775 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 9776 | static const struct nla_policy |
| 9777 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9778 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9779 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 9780 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9781 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 9782 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 9783 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 9784 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9785 | }; |
| 9786 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9787 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9788 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9789 | { |
| 9790 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9791 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9792 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9793 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9794 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9795 | return -EINVAL; |
| 9796 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9797 | if (!rdev->ops->set_cqm_txe_config) |
| 9798 | return -EOPNOTSUPP; |
| 9799 | |
| 9800 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 9801 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9802 | return -EOPNOTSUPP; |
| 9803 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9804 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9805 | } |
| 9806 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9807 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 9808 | struct net_device *dev) |
| 9809 | { |
| 9810 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9811 | s32 last, low, high; |
| 9812 | u32 hyst; |
| 9813 | int i, n; |
| 9814 | int err; |
| 9815 | |
| 9816 | /* RSSI reporting disabled? */ |
| 9817 | if (!wdev->cqm_config) |
| 9818 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 9819 | |
| 9820 | /* |
| 9821 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 9822 | * event has been received yet, we should receive an event after a |
| 9823 | * connection is established and enough beacons received to calculate |
| 9824 | * the average. |
| 9825 | */ |
| 9826 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 9827 | rdev->ops->get_station) { |
| 9828 | struct station_info sinfo; |
| 9829 | u8 *mac_addr; |
| 9830 | |
| 9831 | mac_addr = wdev->current_bss->pub.bssid; |
| 9832 | |
| 9833 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 9834 | if (err) |
| 9835 | return err; |
| 9836 | |
| 9837 | if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
| 9838 | wdev->cqm_config->last_rssi_event_value = |
| 9839 | (s8) sinfo.rx_beacon_signal_avg; |
| 9840 | } |
| 9841 | |
| 9842 | last = wdev->cqm_config->last_rssi_event_value; |
| 9843 | hyst = wdev->cqm_config->rssi_hyst; |
| 9844 | n = wdev->cqm_config->n_rssi_thresholds; |
| 9845 | |
| 9846 | for (i = 0; i < n; i++) |
| 9847 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 9848 | break; |
| 9849 | |
| 9850 | low = i > 0 ? |
| 9851 | (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN; |
| 9852 | high = i < n ? |
| 9853 | (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX; |
| 9854 | |
| 9855 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 9856 | } |
| 9857 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9858 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9859 | const s32 *thresholds, int n_thresholds, |
| 9860 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9861 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9863 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9864 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9865 | int i, err; |
| 9866 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9867 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9868 | /* Check all values negative and sorted */ |
| 9869 | for (i = 0; i < n_thresholds; i++) { |
| 9870 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 9871 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9872 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9873 | prev = thresholds[i]; |
| 9874 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9875 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9876 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9877 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9878 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9879 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9880 | wdev_lock(wdev); |
| 9881 | cfg80211_cqm_config_free(wdev); |
| 9882 | wdev_unlock(wdev); |
| 9883 | |
| 9884 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 9885 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 9886 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 9887 | |
| 9888 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 9889 | thresholds[0], hysteresis); |
| 9890 | } |
| 9891 | |
| 9892 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9893 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 9894 | return -EOPNOTSUPP; |
| 9895 | |
| 9896 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 9897 | n_thresholds = 0; |
| 9898 | |
| 9899 | wdev_lock(wdev); |
| 9900 | if (n_thresholds) { |
| 9901 | struct cfg80211_cqm_config *cqm_config; |
| 9902 | |
| 9903 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 9904 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 9905 | if (!cqm_config) { |
| 9906 | err = -ENOMEM; |
| 9907 | goto unlock; |
| 9908 | } |
| 9909 | |
| 9910 | cqm_config->rssi_hyst = hysteresis; |
| 9911 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 9912 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 9913 | n_thresholds * sizeof(s32)); |
| 9914 | |
| 9915 | wdev->cqm_config = cqm_config; |
| 9916 | } |
| 9917 | |
| 9918 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 9919 | |
| 9920 | unlock: |
| 9921 | wdev_unlock(wdev); |
| 9922 | |
| 9923 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9924 | } |
| 9925 | |
| 9926 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 9927 | { |
| 9928 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 9929 | struct nlattr *cqm; |
| 9930 | int err; |
| 9931 | |
| 9932 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9933 | if (!cqm) |
| 9934 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9935 | |
| 9936 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 9937 | nl80211_attr_cqm_policy, info->extack); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9938 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9939 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9940 | |
| 9941 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 9942 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9943 | const s32 *thresholds = |
| 9944 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 9945 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9946 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9947 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9948 | if (len % 4) |
| 9949 | return -EINVAL; |
| 9950 | |
| 9951 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 9952 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9953 | } |
| 9954 | |
| 9955 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 9956 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 9957 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 9958 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 9959 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 9960 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 9961 | |
| 9962 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 9963 | } |
| 9964 | |
| 9965 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9966 | } |
| 9967 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 9968 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9969 | { |
| 9970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9971 | struct net_device *dev = info->user_ptr[1]; |
| 9972 | struct ocb_setup setup = {}; |
| 9973 | int err; |
| 9974 | |
| 9975 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9976 | if (err) |
| 9977 | return err; |
| 9978 | |
| 9979 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 9980 | } |
| 9981 | |
| 9982 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9983 | { |
| 9984 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9985 | struct net_device *dev = info->user_ptr[1]; |
| 9986 | |
| 9987 | return cfg80211_leave_ocb(rdev, dev); |
| 9988 | } |
| 9989 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9990 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9991 | { |
| 9992 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9993 | struct net_device *dev = info->user_ptr[1]; |
| 9994 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9995 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9996 | int err; |
| 9997 | |
| 9998 | /* start with default */ |
| 9999 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10000 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10001 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10002 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10003 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10004 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10005 | if (err) |
| 10006 | return err; |
| 10007 | } |
| 10008 | |
| 10009 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 10010 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 10011 | return -EINVAL; |
| 10012 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10013 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 10014 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 10015 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 10016 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 10017 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 10018 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 10019 | return -EINVAL; |
| 10020 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 10021 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 10022 | setup.beacon_interval = |
| 10023 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10024 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 10025 | err = cfg80211_validate_beacon_int(rdev, |
| 10026 | NL80211_IFTYPE_MESH_POINT, |
| 10027 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10028 | if (err) |
| 10029 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 10030 | } |
| 10031 | |
| 10032 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 10033 | setup.dtim_period = |
| 10034 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 10035 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 10036 | return -EINVAL; |
| 10037 | } |
| 10038 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10039 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 10040 | /* parse additional setup parameters if given */ |
| 10041 | err = nl80211_parse_mesh_setup(info, &setup); |
| 10042 | if (err) |
| 10043 | return err; |
| 10044 | } |
| 10045 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 10046 | if (setup.user_mpm) |
| 10047 | cfg.auto_open_plinks = false; |
| 10048 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 10049 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10050 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 10051 | if (err) |
| 10052 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 10053 | } else { |
| 10054 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10055 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 10056 | } |
| 10057 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 10058 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 10059 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10060 | int n_rates = |
| 10061 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10062 | struct ieee80211_supported_band *sband; |
| 10063 | |
| 10064 | if (!setup.chandef.chan) |
| 10065 | return -EINVAL; |
| 10066 | |
| 10067 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 10068 | |
| 10069 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 10070 | &setup.basic_rates); |
| 10071 | if (err) |
| 10072 | return err; |
| 10073 | } |
| 10074 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 10075 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 10076 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); |
| 10077 | if (err) |
| 10078 | return err; |
| 10079 | |
Johannes Berg | 265698d | 2017-09-18 22:46:36 +0200 | [diff] [blame] | 10080 | if (!setup.chandef.chan) |
| 10081 | return -EINVAL; |
| 10082 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 10083 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 10084 | &setup.beacon_rate); |
| 10085 | if (err) |
| 10086 | return err; |
| 10087 | } |
| 10088 | |
Benjamin Berg | d37d49c | 2017-05-16 11:23:11 +0200 | [diff] [blame] | 10089 | setup.userspace_handles_dfs = |
| 10090 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 10091 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10092 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10093 | } |
| 10094 | |
| 10095 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 10096 | { |
| 10097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10098 | struct net_device *dev = info->user_ptr[1]; |
| 10099 | |
| 10100 | return cfg80211_leave_mesh(rdev, dev); |
| 10101 | } |
| 10102 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10103 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10104 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 10105 | struct cfg80211_registered_device *rdev) |
| 10106 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10107 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10108 | struct nlattr *nl_pats, *nl_pat; |
| 10109 | int i, pat_len; |
| 10110 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10111 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10112 | return 0; |
| 10113 | |
| 10114 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 10115 | if (!nl_pats) |
| 10116 | return -ENOBUFS; |
| 10117 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10118 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10119 | nl_pat = nla_nest_start(msg, i + 1); |
| 10120 | if (!nl_pat) |
| 10121 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10122 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10123 | 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] | 10124 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10125 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10126 | wowlan->patterns[i].pattern) || |
| 10127 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10128 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10129 | return -ENOBUFS; |
| 10130 | nla_nest_end(msg, nl_pat); |
| 10131 | } |
| 10132 | nla_nest_end(msg, nl_pats); |
| 10133 | |
| 10134 | return 0; |
| 10135 | } |
| 10136 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10137 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 10138 | struct cfg80211_wowlan_tcp *tcp) |
| 10139 | { |
| 10140 | struct nlattr *nl_tcp; |
| 10141 | |
| 10142 | if (!tcp) |
| 10143 | return 0; |
| 10144 | |
| 10145 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 10146 | if (!nl_tcp) |
| 10147 | return -ENOBUFS; |
| 10148 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 10149 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 10150 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10151 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 10152 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 10153 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 10154 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 10155 | tcp->payload_len, tcp->payload) || |
| 10156 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 10157 | tcp->data_interval) || |
| 10158 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 10159 | tcp->wake_len, tcp->wake_data) || |
| 10160 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 10161 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 10162 | return -ENOBUFS; |
| 10163 | |
| 10164 | if (tcp->payload_seq.len && |
| 10165 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 10166 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 10167 | return -ENOBUFS; |
| 10168 | |
| 10169 | if (tcp->payload_tok.len && |
| 10170 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 10171 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 10172 | &tcp->payload_tok)) |
| 10173 | return -ENOBUFS; |
| 10174 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 10175 | nla_nest_end(msg, nl_tcp); |
| 10176 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10177 | return 0; |
| 10178 | } |
| 10179 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10180 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 10181 | struct cfg80211_sched_scan_request *req) |
| 10182 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10183 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10184 | int i; |
| 10185 | |
| 10186 | if (!req) |
| 10187 | return 0; |
| 10188 | |
| 10189 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 10190 | if (!nd) |
| 10191 | return -ENOBUFS; |
| 10192 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10193 | if (req->n_scan_plans == 1 && |
| 10194 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 10195 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10196 | return -ENOBUFS; |
| 10197 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 10198 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 10199 | return -ENOBUFS; |
| 10200 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 10201 | if (req->relative_rssi_set) { |
| 10202 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 10203 | |
| 10204 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 10205 | req->relative_rssi)) |
| 10206 | return -ENOBUFS; |
| 10207 | |
| 10208 | rssi_adjust.band = req->rssi_adjust.band; |
| 10209 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 10210 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 10211 | sizeof(rssi_adjust), &rssi_adjust)) |
| 10212 | return -ENOBUFS; |
| 10213 | } |
| 10214 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10215 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10216 | if (!freqs) |
| 10217 | return -ENOBUFS; |
| 10218 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10219 | for (i = 0; i < req->n_channels; i++) { |
| 10220 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10221 | return -ENOBUFS; |
| 10222 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10223 | |
| 10224 | nla_nest_end(msg, freqs); |
| 10225 | |
| 10226 | if (req->n_match_sets) { |
| 10227 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10228 | if (!matches) |
| 10229 | return -ENOBUFS; |
| 10230 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10231 | for (i = 0; i < req->n_match_sets; i++) { |
| 10232 | match = nla_nest_start(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10233 | if (!match) |
| 10234 | return -ENOBUFS; |
| 10235 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10236 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 10237 | req->match_sets[i].ssid.ssid_len, |
| 10238 | req->match_sets[i].ssid.ssid)) |
| 10239 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10240 | nla_nest_end(msg, match); |
| 10241 | } |
| 10242 | nla_nest_end(msg, matches); |
| 10243 | } |
| 10244 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10245 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 10246 | if (!scan_plans) |
| 10247 | return -ENOBUFS; |
| 10248 | |
| 10249 | for (i = 0; i < req->n_scan_plans; i++) { |
| 10250 | scan_plan = nla_nest_start(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10251 | if (!scan_plan) |
| 10252 | return -ENOBUFS; |
| 10253 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10254 | if (!scan_plan || |
| 10255 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 10256 | req->scan_plans[i].interval) || |
| 10257 | (req->scan_plans[i].iterations && |
| 10258 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 10259 | req->scan_plans[i].iterations))) |
| 10260 | return -ENOBUFS; |
| 10261 | nla_nest_end(msg, scan_plan); |
| 10262 | } |
| 10263 | nla_nest_end(msg, scan_plans); |
| 10264 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10265 | nla_nest_end(msg, nd); |
| 10266 | |
| 10267 | return 0; |
| 10268 | } |
| 10269 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10270 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10271 | { |
| 10272 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10273 | struct sk_buff *msg; |
| 10274 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10275 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10276 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10277 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10278 | return -EOPNOTSUPP; |
| 10279 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10280 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10281 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10282 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 10283 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 10284 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 10285 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10286 | } |
| 10287 | |
| 10288 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10289 | if (!msg) |
| 10290 | return -ENOMEM; |
| 10291 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10292 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10293 | NL80211_CMD_GET_WOWLAN); |
| 10294 | if (!hdr) |
| 10295 | goto nla_put_failure; |
| 10296 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10297 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10298 | struct nlattr *nl_wowlan; |
| 10299 | |
| 10300 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10301 | if (!nl_wowlan) |
| 10302 | goto nla_put_failure; |
| 10303 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10304 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10305 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10306 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10307 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10308 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10309 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10310 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10311 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10312 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10313 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10314 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10315 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10316 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10317 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 10318 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10319 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10320 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 10321 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10322 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10323 | if (nl80211_send_wowlan_tcp(msg, |
| 10324 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10325 | goto nla_put_failure; |
| 10326 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10327 | if (nl80211_send_wowlan_nd( |
| 10328 | msg, |
| 10329 | rdev->wiphy.wowlan_config->nd_config)) |
| 10330 | goto nla_put_failure; |
| 10331 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10332 | nla_nest_end(msg, nl_wowlan); |
| 10333 | } |
| 10334 | |
| 10335 | genlmsg_end(msg, hdr); |
| 10336 | return genlmsg_reply(msg, info); |
| 10337 | |
| 10338 | nla_put_failure: |
| 10339 | nlmsg_free(msg); |
| 10340 | return -ENOBUFS; |
| 10341 | } |
| 10342 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10343 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 10344 | struct nlattr *attr, |
| 10345 | struct cfg80211_wowlan *trig) |
| 10346 | { |
| 10347 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 10348 | struct cfg80211_wowlan_tcp *cfg; |
| 10349 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 10350 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 10351 | u32 size; |
| 10352 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 10353 | int err, port; |
| 10354 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10355 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10356 | return -EINVAL; |
| 10357 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10358 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10359 | nl80211_wowlan_tcp_policy, NULL); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10360 | if (err) |
| 10361 | return err; |
| 10362 | |
| 10363 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 10364 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 10365 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 10366 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 10367 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 10368 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 10369 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 10370 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 10371 | return -EINVAL; |
| 10372 | |
| 10373 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10374 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10375 | return -EINVAL; |
| 10376 | |
| 10377 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10378 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 10379 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10380 | return -EINVAL; |
| 10381 | |
| 10382 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10383 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10384 | return -EINVAL; |
| 10385 | |
| 10386 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 10387 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 10388 | return -EINVAL; |
| 10389 | |
| 10390 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 10391 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10392 | |
| 10393 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10394 | tokens_size = tokln - sizeof(*tok); |
| 10395 | |
| 10396 | if (!tok->len || tokens_size % tok->len) |
| 10397 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10398 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10399 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10400 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10401 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10402 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10403 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10404 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10405 | return -EINVAL; |
| 10406 | if (tok->offset + tok->len > data_size) |
| 10407 | return -EINVAL; |
| 10408 | } |
| 10409 | |
| 10410 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 10411 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10412 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10413 | return -EINVAL; |
| 10414 | if (seq->len == 0 || seq->len > 4) |
| 10415 | return -EINVAL; |
| 10416 | if (seq->len + seq->offset > data_size) |
| 10417 | return -EINVAL; |
| 10418 | } |
| 10419 | |
| 10420 | size = sizeof(*cfg); |
| 10421 | size += data_size; |
| 10422 | size += wake_size + wake_mask_size; |
| 10423 | size += tokens_size; |
| 10424 | |
| 10425 | cfg = kzalloc(size, GFP_KERNEL); |
| 10426 | if (!cfg) |
| 10427 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 10428 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 10429 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10430 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 10431 | ETH_ALEN); |
| 10432 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 10433 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 10434 | else |
| 10435 | port = 0; |
| 10436 | #ifdef CONFIG_INET |
| 10437 | /* allocate a socket and port for it and use it */ |
| 10438 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 10439 | IPPROTO_TCP, &cfg->sock, 1); |
| 10440 | if (err) { |
| 10441 | kfree(cfg); |
| 10442 | return err; |
| 10443 | } |
| 10444 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 10445 | sock_release(cfg->sock); |
| 10446 | kfree(cfg); |
| 10447 | return -EADDRINUSE; |
| 10448 | } |
| 10449 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 10450 | #else |
| 10451 | if (!port) { |
| 10452 | kfree(cfg); |
| 10453 | return -EINVAL; |
| 10454 | } |
| 10455 | cfg->src_port = port; |
| 10456 | #endif |
| 10457 | |
| 10458 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 10459 | cfg->payload_len = data_size; |
| 10460 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 10461 | memcpy((void *)cfg->payload, |
| 10462 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 10463 | data_size); |
| 10464 | if (seq) |
| 10465 | cfg->payload_seq = *seq; |
| 10466 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 10467 | cfg->wake_len = wake_size; |
| 10468 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 10469 | memcpy((void *)cfg->wake_data, |
| 10470 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 10471 | wake_size); |
| 10472 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 10473 | data_size + wake_size; |
| 10474 | memcpy((void *)cfg->wake_mask, |
| 10475 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 10476 | wake_mask_size); |
| 10477 | if (tok) { |
| 10478 | cfg->tokens_size = tokens_size; |
| 10479 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 10480 | } |
| 10481 | |
| 10482 | trig->tcp = cfg; |
| 10483 | |
| 10484 | return 0; |
| 10485 | } |
| 10486 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10487 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 10488 | const struct wiphy_wowlan_support *wowlan, |
| 10489 | struct nlattr *attr, |
| 10490 | struct cfg80211_wowlan *trig) |
| 10491 | { |
| 10492 | struct nlattr **tb; |
| 10493 | int err; |
| 10494 | |
| 10495 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 10496 | if (!tb) |
| 10497 | return -ENOMEM; |
| 10498 | |
| 10499 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 10500 | err = -EOPNOTSUPP; |
| 10501 | goto out; |
| 10502 | } |
| 10503 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10504 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy, |
| 10505 | NULL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10506 | if (err) |
| 10507 | goto out; |
| 10508 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 10509 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 10510 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10511 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 10512 | if (err) |
| 10513 | trig->nd_config = NULL; |
| 10514 | |
| 10515 | out: |
| 10516 | kfree(tb); |
| 10517 | return err; |
| 10518 | } |
| 10519 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10520 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10521 | { |
| 10522 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10523 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10524 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10525 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10526 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10527 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10528 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10529 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10530 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10531 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10532 | return -EOPNOTSUPP; |
| 10533 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10534 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 10535 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10536 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10537 | goto set_wakeup; |
| 10538 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10539 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10540 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG, |
| 10541 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10542 | nl80211_wowlan_policy, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10543 | if (err) |
| 10544 | return err; |
| 10545 | |
| 10546 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 10547 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 10548 | return -EINVAL; |
| 10549 | new_triggers.any = true; |
| 10550 | } |
| 10551 | |
| 10552 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 10553 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 10554 | return -EINVAL; |
| 10555 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10556 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10557 | } |
| 10558 | |
| 10559 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 10560 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 10561 | return -EINVAL; |
| 10562 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10563 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10564 | } |
| 10565 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10566 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 10567 | return -EINVAL; |
| 10568 | |
| 10569 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 10570 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 10571 | return -EINVAL; |
| 10572 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10573 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10574 | } |
| 10575 | |
| 10576 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 10577 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 10578 | return -EINVAL; |
| 10579 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10580 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10581 | } |
| 10582 | |
| 10583 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 10584 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 10585 | return -EINVAL; |
| 10586 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10587 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10588 | } |
| 10589 | |
| 10590 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 10591 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 10592 | return -EINVAL; |
| 10593 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10594 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10595 | } |
| 10596 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10597 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 10598 | struct nlattr *pat; |
| 10599 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10600 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10601 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10602 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10603 | regular = true; |
| 10604 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10605 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10606 | rem) |
| 10607 | n_patterns++; |
| 10608 | if (n_patterns > wowlan->n_patterns) |
| 10609 | return -EINVAL; |
| 10610 | |
| 10611 | new_triggers.patterns = kcalloc(n_patterns, |
| 10612 | sizeof(new_triggers.patterns[0]), |
| 10613 | GFP_KERNEL); |
| 10614 | if (!new_triggers.patterns) |
| 10615 | return -ENOMEM; |
| 10616 | |
| 10617 | new_triggers.n_patterns = n_patterns; |
| 10618 | i = 0; |
| 10619 | |
| 10620 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10621 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10622 | u8 *mask_pat; |
| 10623 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10624 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 10625 | nl80211_packet_pattern_policy, |
| 10626 | info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10627 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10628 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10629 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10630 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10631 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10632 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10633 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10634 | goto error; |
| 10635 | if (pat_len > wowlan->pattern_max_len || |
| 10636 | pat_len < wowlan->pattern_min_len) |
| 10637 | goto error; |
| 10638 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10639 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10640 | pkt_offset = 0; |
| 10641 | else |
| 10642 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10643 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10644 | if (pkt_offset > wowlan->max_pkt_offset) |
| 10645 | goto error; |
| 10646 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 10647 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10648 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10649 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10650 | err = -ENOMEM; |
| 10651 | goto error; |
| 10652 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10653 | new_triggers.patterns[i].mask = mask_pat; |
| 10654 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10655 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10656 | mask_pat += mask_len; |
| 10657 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10658 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10659 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10660 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10661 | pat_len); |
| 10662 | i++; |
| 10663 | } |
| 10664 | } |
| 10665 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10666 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10667 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10668 | err = nl80211_parse_wowlan_tcp( |
| 10669 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 10670 | &new_triggers); |
| 10671 | if (err) |
| 10672 | goto error; |
| 10673 | } |
| 10674 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10675 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10676 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10677 | err = nl80211_parse_wowlan_nd( |
| 10678 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 10679 | &new_triggers); |
| 10680 | if (err) |
| 10681 | goto error; |
| 10682 | } |
| 10683 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10684 | /* The 'any' trigger means the device continues operating more or less |
| 10685 | * as in its normal operation mode and wakes up the host on most of the |
| 10686 | * normal interrupts (like packet RX, ...) |
| 10687 | * It therefore makes little sense to combine with the more constrained |
| 10688 | * wakeup trigger modes. |
| 10689 | */ |
| 10690 | if (new_triggers.any && regular) { |
| 10691 | err = -EINVAL; |
| 10692 | goto error; |
| 10693 | } |
| 10694 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10695 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 10696 | if (!ntrig) { |
| 10697 | err = -ENOMEM; |
| 10698 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10699 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10700 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10701 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10702 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10703 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10704 | if (rdev->ops->set_wakeup && |
| 10705 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 10706 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 10707 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10708 | return 0; |
| 10709 | error: |
| 10710 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 10711 | kfree(new_triggers.patterns[i].mask); |
| 10712 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10713 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 10714 | sock_release(new_triggers.tcp->sock); |
| 10715 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 10716 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10717 | return err; |
| 10718 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10719 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10720 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10721 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 10722 | struct cfg80211_registered_device *rdev) |
| 10723 | { |
| 10724 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 10725 | int i, j, pat_len; |
| 10726 | struct cfg80211_coalesce_rules *rule; |
| 10727 | |
| 10728 | if (!rdev->coalesce->n_rules) |
| 10729 | return 0; |
| 10730 | |
| 10731 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 10732 | if (!nl_rules) |
| 10733 | return -ENOBUFS; |
| 10734 | |
| 10735 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 10736 | nl_rule = nla_nest_start(msg, i + 1); |
| 10737 | if (!nl_rule) |
| 10738 | return -ENOBUFS; |
| 10739 | |
| 10740 | rule = &rdev->coalesce->rules[i]; |
| 10741 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 10742 | rule->delay)) |
| 10743 | return -ENOBUFS; |
| 10744 | |
| 10745 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 10746 | rule->condition)) |
| 10747 | return -ENOBUFS; |
| 10748 | |
| 10749 | nl_pats = nla_nest_start(msg, |
| 10750 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 10751 | if (!nl_pats) |
| 10752 | return -ENOBUFS; |
| 10753 | |
| 10754 | for (j = 0; j < rule->n_patterns; j++) { |
| 10755 | nl_pat = nla_nest_start(msg, j + 1); |
| 10756 | if (!nl_pat) |
| 10757 | return -ENOBUFS; |
| 10758 | pat_len = rule->patterns[j].pattern_len; |
| 10759 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 10760 | DIV_ROUND_UP(pat_len, 8), |
| 10761 | rule->patterns[j].mask) || |
| 10762 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10763 | rule->patterns[j].pattern) || |
| 10764 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 10765 | rule->patterns[j].pkt_offset)) |
| 10766 | return -ENOBUFS; |
| 10767 | nla_nest_end(msg, nl_pat); |
| 10768 | } |
| 10769 | nla_nest_end(msg, nl_pats); |
| 10770 | nla_nest_end(msg, nl_rule); |
| 10771 | } |
| 10772 | nla_nest_end(msg, nl_rules); |
| 10773 | |
| 10774 | return 0; |
| 10775 | } |
| 10776 | |
| 10777 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10778 | { |
| 10779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10780 | struct sk_buff *msg; |
| 10781 | void *hdr; |
| 10782 | |
| 10783 | if (!rdev->wiphy.coalesce) |
| 10784 | return -EOPNOTSUPP; |
| 10785 | |
| 10786 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10787 | if (!msg) |
| 10788 | return -ENOMEM; |
| 10789 | |
| 10790 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10791 | NL80211_CMD_GET_COALESCE); |
| 10792 | if (!hdr) |
| 10793 | goto nla_put_failure; |
| 10794 | |
| 10795 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 10796 | goto nla_put_failure; |
| 10797 | |
| 10798 | genlmsg_end(msg, hdr); |
| 10799 | return genlmsg_reply(msg, info); |
| 10800 | |
| 10801 | nla_put_failure: |
| 10802 | nlmsg_free(msg); |
| 10803 | return -ENOBUFS; |
| 10804 | } |
| 10805 | |
| 10806 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 10807 | { |
| 10808 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 10809 | int i, j; |
| 10810 | struct cfg80211_coalesce_rules *rule; |
| 10811 | |
| 10812 | if (!coalesce) |
| 10813 | return; |
| 10814 | |
| 10815 | for (i = 0; i < coalesce->n_rules; i++) { |
| 10816 | rule = &coalesce->rules[i]; |
| 10817 | for (j = 0; j < rule->n_patterns; j++) |
| 10818 | kfree(rule->patterns[j].mask); |
| 10819 | kfree(rule->patterns); |
| 10820 | } |
| 10821 | kfree(coalesce->rules); |
| 10822 | kfree(coalesce); |
| 10823 | rdev->coalesce = NULL; |
| 10824 | } |
| 10825 | |
| 10826 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 10827 | struct nlattr *rule, |
| 10828 | struct cfg80211_coalesce_rules *new_rule) |
| 10829 | { |
| 10830 | int err, i; |
| 10831 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10832 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 10833 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 10834 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 10835 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10836 | err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10837 | nl80211_coalesce_policy, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10838 | if (err) |
| 10839 | return err; |
| 10840 | |
| 10841 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 10842 | new_rule->delay = |
| 10843 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 10844 | if (new_rule->delay > coalesce->max_delay) |
| 10845 | return -EINVAL; |
| 10846 | |
| 10847 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 10848 | new_rule->condition = |
| 10849 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 10850 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 10851 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 10852 | return -EINVAL; |
| 10853 | |
| 10854 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 10855 | return -EINVAL; |
| 10856 | |
| 10857 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10858 | rem) |
| 10859 | n_patterns++; |
| 10860 | if (n_patterns > coalesce->n_patterns) |
| 10861 | return -EINVAL; |
| 10862 | |
| 10863 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 10864 | GFP_KERNEL); |
| 10865 | if (!new_rule->patterns) |
| 10866 | return -ENOMEM; |
| 10867 | |
| 10868 | new_rule->n_patterns = n_patterns; |
| 10869 | i = 0; |
| 10870 | |
| 10871 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10872 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10873 | u8 *mask_pat; |
| 10874 | |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 10875 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
| 10876 | nl80211_packet_pattern_policy, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10877 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10878 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 10879 | return -EINVAL; |
| 10880 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 10881 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 10882 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 10883 | return -EINVAL; |
| 10884 | if (pat_len > coalesce->pattern_max_len || |
| 10885 | pat_len < coalesce->pattern_min_len) |
| 10886 | return -EINVAL; |
| 10887 | |
| 10888 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 10889 | pkt_offset = 0; |
| 10890 | else |
| 10891 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 10892 | if (pkt_offset > coalesce->max_pkt_offset) |
| 10893 | return -EINVAL; |
| 10894 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 10895 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10896 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10897 | if (!mask_pat) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10898 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10899 | |
| 10900 | new_rule->patterns[i].mask = mask_pat; |
| 10901 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 10902 | mask_len); |
| 10903 | |
| 10904 | mask_pat += mask_len; |
| 10905 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10906 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10907 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 10908 | pat_len); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10909 | i++; |
| 10910 | } |
| 10911 | |
| 10912 | return 0; |
| 10913 | } |
| 10914 | |
| 10915 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10916 | { |
| 10917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10918 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10919 | struct cfg80211_coalesce new_coalesce = {}; |
| 10920 | struct cfg80211_coalesce *n_coalesce; |
| 10921 | int err, rem_rule, n_rules = 0, i, j; |
| 10922 | struct nlattr *rule; |
| 10923 | struct cfg80211_coalesce_rules *tmp_rule; |
| 10924 | |
| 10925 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 10926 | return -EOPNOTSUPP; |
| 10927 | |
| 10928 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 10929 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10930 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10931 | return 0; |
| 10932 | } |
| 10933 | |
| 10934 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10935 | rem_rule) |
| 10936 | n_rules++; |
| 10937 | if (n_rules > coalesce->n_rules) |
| 10938 | return -EINVAL; |
| 10939 | |
| 10940 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 10941 | GFP_KERNEL); |
| 10942 | if (!new_coalesce.rules) |
| 10943 | return -ENOMEM; |
| 10944 | |
| 10945 | new_coalesce.n_rules = n_rules; |
| 10946 | i = 0; |
| 10947 | |
| 10948 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10949 | rem_rule) { |
| 10950 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 10951 | &new_coalesce.rules[i]); |
| 10952 | if (err) |
| 10953 | goto error; |
| 10954 | |
| 10955 | i++; |
| 10956 | } |
| 10957 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10958 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10959 | if (err) |
| 10960 | goto error; |
| 10961 | |
| 10962 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 10963 | if (!n_coalesce) { |
| 10964 | err = -ENOMEM; |
| 10965 | goto error; |
| 10966 | } |
| 10967 | cfg80211_rdev_free_coalesce(rdev); |
| 10968 | rdev->coalesce = n_coalesce; |
| 10969 | |
| 10970 | return 0; |
| 10971 | error: |
| 10972 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 10973 | tmp_rule = &new_coalesce.rules[i]; |
| 10974 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 10975 | kfree(tmp_rule->patterns[j].mask); |
| 10976 | kfree(tmp_rule->patterns); |
| 10977 | } |
| 10978 | kfree(new_coalesce.rules); |
| 10979 | |
| 10980 | return err; |
| 10981 | } |
| 10982 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10983 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 10984 | { |
| 10985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10986 | struct net_device *dev = info->user_ptr[1]; |
| 10987 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10988 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 10989 | struct cfg80211_gtk_rekey_data rekey_data; |
| 10990 | int err; |
| 10991 | |
| 10992 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 10993 | return -EINVAL; |
| 10994 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10995 | err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA, |
| 10996 | info->attrs[NL80211_ATTR_REKEY_DATA], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10997 | nl80211_rekey_policy, info->extack); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10998 | if (err) |
| 10999 | return err; |
| 11000 | |
Vladis Dronov | e785fa0 | 2017-09-13 00:21:21 +0200 | [diff] [blame] | 11001 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
| 11002 | !tb[NL80211_REKEY_DATA_KCK]) |
| 11003 | return -EINVAL; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11004 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 11005 | return -ERANGE; |
| 11006 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 11007 | return -ERANGE; |
| 11008 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 11009 | return -ERANGE; |
| 11010 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 11011 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 11012 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 11013 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11014 | |
| 11015 | wdev_lock(wdev); |
| 11016 | if (!wdev->current_bss) { |
| 11017 | err = -ENOTCONN; |
| 11018 | goto out; |
| 11019 | } |
| 11020 | |
| 11021 | if (!rdev->ops->set_rekey_data) { |
| 11022 | err = -EOPNOTSUPP; |
| 11023 | goto out; |
| 11024 | } |
| 11025 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11026 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11027 | out: |
| 11028 | wdev_unlock(wdev); |
| 11029 | return err; |
| 11030 | } |
| 11031 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11032 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 11033 | struct genl_info *info) |
| 11034 | { |
| 11035 | struct net_device *dev = info->user_ptr[1]; |
| 11036 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11037 | |
| 11038 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 11039 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 11040 | return -EINVAL; |
| 11041 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11042 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11043 | return -EBUSY; |
| 11044 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11045 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11046 | return 0; |
| 11047 | } |
| 11048 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11049 | static int nl80211_probe_client(struct sk_buff *skb, |
| 11050 | struct genl_info *info) |
| 11051 | { |
| 11052 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11053 | struct net_device *dev = info->user_ptr[1]; |
| 11054 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11055 | struct sk_buff *msg; |
| 11056 | void *hdr; |
| 11057 | const u8 *addr; |
| 11058 | u64 cookie; |
| 11059 | int err; |
| 11060 | |
| 11061 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 11062 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 11063 | return -EOPNOTSUPP; |
| 11064 | |
| 11065 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 11066 | return -EINVAL; |
| 11067 | |
| 11068 | if (!rdev->ops->probe_client) |
| 11069 | return -EOPNOTSUPP; |
| 11070 | |
| 11071 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11072 | if (!msg) |
| 11073 | return -ENOMEM; |
| 11074 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11075 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11076 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 11077 | if (!hdr) { |
| 11078 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11079 | goto free_msg; |
| 11080 | } |
| 11081 | |
| 11082 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11083 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11084 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11085 | if (err) |
| 11086 | goto free_msg; |
| 11087 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11088 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11089 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11090 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11091 | |
| 11092 | genlmsg_end(msg, hdr); |
| 11093 | |
| 11094 | return genlmsg_reply(msg, info); |
| 11095 | |
| 11096 | nla_put_failure: |
| 11097 | err = -ENOBUFS; |
| 11098 | free_msg: |
| 11099 | nlmsg_free(msg); |
| 11100 | return err; |
| 11101 | } |
| 11102 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11103 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 11104 | { |
| 11105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11106 | struct cfg80211_beacon_registration *reg, *nreg; |
| 11107 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11108 | |
| 11109 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 11110 | return -EOPNOTSUPP; |
| 11111 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11112 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 11113 | if (!nreg) |
| 11114 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11115 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11116 | /* First, check if already registered. */ |
| 11117 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11118 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11119 | if (reg->nlportid == info->snd_portid) { |
| 11120 | rv = -EALREADY; |
| 11121 | goto out_err; |
| 11122 | } |
| 11123 | } |
| 11124 | /* Add it to the list */ |
| 11125 | nreg->nlportid = info->snd_portid; |
| 11126 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 11127 | |
| 11128 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11129 | |
| 11130 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11131 | out_err: |
| 11132 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11133 | kfree(nreg); |
| 11134 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11135 | } |
| 11136 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11137 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 11138 | { |
| 11139 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11140 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11141 | int err; |
| 11142 | |
| 11143 | if (!rdev->ops->start_p2p_device) |
| 11144 | return -EOPNOTSUPP; |
| 11145 | |
| 11146 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 11147 | return -EOPNOTSUPP; |
| 11148 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11149 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11150 | return 0; |
| 11151 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 11152 | if (rfkill_blocked(rdev->rfkill)) |
| 11153 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11154 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 11155 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11156 | if (err) |
| 11157 | return err; |
| 11158 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11159 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11160 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11161 | |
| 11162 | return 0; |
| 11163 | } |
| 11164 | |
| 11165 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 11166 | { |
| 11167 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11168 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11169 | |
| 11170 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 11171 | return -EOPNOTSUPP; |
| 11172 | |
| 11173 | if (!rdev->ops->stop_p2p_device) |
| 11174 | return -EOPNOTSUPP; |
| 11175 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 11176 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11177 | |
| 11178 | return 0; |
| 11179 | } |
| 11180 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11181 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 11182 | { |
| 11183 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11184 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11185 | struct cfg80211_nan_conf conf = {}; |
| 11186 | int err; |
| 11187 | |
| 11188 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11189 | return -EOPNOTSUPP; |
| 11190 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 11191 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11192 | return -EEXIST; |
| 11193 | |
| 11194 | if (rfkill_blocked(rdev->rfkill)) |
| 11195 | return -ERFKILL; |
| 11196 | |
| 11197 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 11198 | return -EINVAL; |
| 11199 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11200 | conf.master_pref = |
| 11201 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11202 | if (!conf.master_pref) |
| 11203 | return -EINVAL; |
| 11204 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 11205 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 11206 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 11207 | |
| 11208 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 11209 | return -EOPNOTSUPP; |
| 11210 | |
| 11211 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 11212 | return -EINVAL; |
| 11213 | |
| 11214 | conf.bands = bands; |
| 11215 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11216 | |
| 11217 | err = rdev_start_nan(rdev, wdev, &conf); |
| 11218 | if (err) |
| 11219 | return err; |
| 11220 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11221 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11222 | rdev->opencount++; |
| 11223 | |
| 11224 | return 0; |
| 11225 | } |
| 11226 | |
| 11227 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 11228 | { |
| 11229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11230 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11231 | |
| 11232 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11233 | return -EOPNOTSUPP; |
| 11234 | |
| 11235 | cfg80211_stop_nan(rdev, wdev); |
| 11236 | |
| 11237 | return 0; |
| 11238 | } |
| 11239 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11240 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 11241 | { |
| 11242 | struct nlattr *attr; |
| 11243 | int len = 0, n_entries = 0, rem; |
| 11244 | |
| 11245 | nla_for_each_nested(attr, filter_attr, rem) { |
| 11246 | len += nla_len(attr); |
| 11247 | n_entries++; |
| 11248 | } |
| 11249 | |
| 11250 | if (len >= U8_MAX) |
| 11251 | return -EINVAL; |
| 11252 | |
| 11253 | return n_entries; |
| 11254 | } |
| 11255 | |
| 11256 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 11257 | struct cfg80211_nan_func *func, |
| 11258 | bool tx) |
| 11259 | { |
| 11260 | struct nlattr *attr; |
| 11261 | int n_entries, rem, i; |
| 11262 | struct cfg80211_nan_func_filter *filter; |
| 11263 | |
| 11264 | n_entries = validate_nan_filter(attr_filter); |
| 11265 | if (n_entries < 0) |
| 11266 | return n_entries; |
| 11267 | |
| 11268 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 11269 | |
| 11270 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 11271 | if (!filter) |
| 11272 | return -ENOMEM; |
| 11273 | |
| 11274 | i = 0; |
| 11275 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 11276 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11277 | filter[i].len = nla_len(attr); |
| 11278 | i++; |
| 11279 | } |
| 11280 | if (tx) { |
| 11281 | func->num_tx_filters = n_entries; |
| 11282 | func->tx_filters = filter; |
| 11283 | } else { |
| 11284 | func->num_rx_filters = n_entries; |
| 11285 | func->rx_filters = filter; |
| 11286 | } |
| 11287 | |
| 11288 | return 0; |
| 11289 | } |
| 11290 | |
| 11291 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 11292 | struct genl_info *info) |
| 11293 | { |
| 11294 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11295 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11296 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 11297 | struct cfg80211_nan_func *func; |
| 11298 | struct sk_buff *msg = NULL; |
| 11299 | void *hdr = NULL; |
| 11300 | int err = 0; |
| 11301 | |
| 11302 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11303 | return -EOPNOTSUPP; |
| 11304 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11305 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11306 | return -ENOTCONN; |
| 11307 | |
| 11308 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 11309 | return -EINVAL; |
| 11310 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11311 | err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 11312 | info->attrs[NL80211_ATTR_NAN_FUNC], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11313 | nl80211_nan_func_policy, info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11314 | if (err) |
| 11315 | return err; |
| 11316 | |
| 11317 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 11318 | if (!func) |
| 11319 | return -ENOMEM; |
| 11320 | |
| 11321 | func->cookie = wdev->wiphy->cookie_counter++; |
| 11322 | |
| 11323 | if (!tb[NL80211_NAN_FUNC_TYPE] || |
| 11324 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { |
| 11325 | err = -EINVAL; |
| 11326 | goto out; |
| 11327 | } |
| 11328 | |
| 11329 | |
| 11330 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 11331 | |
| 11332 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 11333 | err = -EINVAL; |
| 11334 | goto out; |
| 11335 | } |
| 11336 | |
| 11337 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 11338 | sizeof(func->service_id)); |
| 11339 | |
| 11340 | func->close_range = |
| 11341 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 11342 | |
| 11343 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 11344 | func->serv_spec_info_len = |
| 11345 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 11346 | func->serv_spec_info = |
| 11347 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 11348 | func->serv_spec_info_len, |
| 11349 | GFP_KERNEL); |
| 11350 | if (!func->serv_spec_info) { |
| 11351 | err = -ENOMEM; |
| 11352 | goto out; |
| 11353 | } |
| 11354 | } |
| 11355 | |
| 11356 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 11357 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 11358 | |
| 11359 | switch (func->type) { |
| 11360 | case NL80211_NAN_FUNC_PUBLISH: |
| 11361 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 11362 | err = -EINVAL; |
| 11363 | goto out; |
| 11364 | } |
| 11365 | |
| 11366 | func->publish_type = |
| 11367 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 11368 | func->publish_bcast = |
| 11369 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 11370 | |
| 11371 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 11372 | func->publish_bcast) { |
| 11373 | err = -EINVAL; |
| 11374 | goto out; |
| 11375 | } |
| 11376 | break; |
| 11377 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 11378 | func->subscribe_active = |
| 11379 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 11380 | break; |
| 11381 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 11382 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
| 11383 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) { |
| 11384 | err = -EINVAL; |
| 11385 | goto out; |
| 11386 | } |
| 11387 | |
| 11388 | func->followup_id = |
| 11389 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 11390 | func->followup_reqid = |
| 11391 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 11392 | memcpy(func->followup_dest.addr, |
| 11393 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 11394 | sizeof(func->followup_dest.addr)); |
| 11395 | if (func->ttl) { |
| 11396 | err = -EINVAL; |
| 11397 | goto out; |
| 11398 | } |
| 11399 | break; |
| 11400 | default: |
| 11401 | err = -EINVAL; |
| 11402 | goto out; |
| 11403 | } |
| 11404 | |
| 11405 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 11406 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 11407 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11408 | err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX, |
| 11409 | tb[NL80211_NAN_FUNC_SRF], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11410 | nl80211_nan_srf_policy, info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11411 | if (err) |
| 11412 | goto out; |
| 11413 | |
| 11414 | func->srf_include = |
| 11415 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 11416 | |
| 11417 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 11418 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 11419 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 11420 | err = -EINVAL; |
| 11421 | goto out; |
| 11422 | } |
| 11423 | |
| 11424 | func->srf_bf_len = |
| 11425 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 11426 | func->srf_bf = |
| 11427 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 11428 | func->srf_bf_len, GFP_KERNEL); |
| 11429 | if (!func->srf_bf) { |
| 11430 | err = -ENOMEM; |
| 11431 | goto out; |
| 11432 | } |
| 11433 | |
| 11434 | func->srf_bf_idx = |
| 11435 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 11436 | } else { |
| 11437 | struct nlattr *attr, *mac_attr = |
| 11438 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 11439 | int n_entries, rem, i = 0; |
| 11440 | |
| 11441 | if (!mac_attr) { |
| 11442 | err = -EINVAL; |
| 11443 | goto out; |
| 11444 | } |
| 11445 | |
| 11446 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 11447 | if (n_entries <= 0) { |
| 11448 | err = -EINVAL; |
| 11449 | goto out; |
| 11450 | } |
| 11451 | |
| 11452 | func->srf_num_macs = n_entries; |
| 11453 | func->srf_macs = |
| 11454 | kzalloc(sizeof(*func->srf_macs) * n_entries, |
| 11455 | GFP_KERNEL); |
| 11456 | if (!func->srf_macs) { |
| 11457 | err = -ENOMEM; |
| 11458 | goto out; |
| 11459 | } |
| 11460 | |
| 11461 | nla_for_each_nested(attr, mac_attr, rem) |
| 11462 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 11463 | sizeof(*func->srf_macs)); |
| 11464 | } |
| 11465 | } |
| 11466 | |
| 11467 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 11468 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 11469 | func, true); |
| 11470 | if (err) |
| 11471 | goto out; |
| 11472 | } |
| 11473 | |
| 11474 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 11475 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 11476 | func, false); |
| 11477 | if (err) |
| 11478 | goto out; |
| 11479 | } |
| 11480 | |
| 11481 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11482 | if (!msg) { |
| 11483 | err = -ENOMEM; |
| 11484 | goto out; |
| 11485 | } |
| 11486 | |
| 11487 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11488 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 11489 | /* This can't really happen - we just allocated 4KB */ |
| 11490 | if (WARN_ON(!hdr)) { |
| 11491 | err = -ENOMEM; |
| 11492 | goto out; |
| 11493 | } |
| 11494 | |
| 11495 | err = rdev_add_nan_func(rdev, wdev, func); |
| 11496 | out: |
| 11497 | if (err < 0) { |
| 11498 | cfg80211_free_nan_func(func); |
| 11499 | nlmsg_free(msg); |
| 11500 | return err; |
| 11501 | } |
| 11502 | |
| 11503 | /* propagate the instance id and cookie to userspace */ |
| 11504 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 11505 | NL80211_ATTR_PAD)) |
| 11506 | goto nla_put_failure; |
| 11507 | |
| 11508 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11509 | if (!func_attr) |
| 11510 | goto nla_put_failure; |
| 11511 | |
| 11512 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 11513 | func->instance_id)) |
| 11514 | goto nla_put_failure; |
| 11515 | |
| 11516 | nla_nest_end(msg, func_attr); |
| 11517 | |
| 11518 | genlmsg_end(msg, hdr); |
| 11519 | return genlmsg_reply(msg, info); |
| 11520 | |
| 11521 | nla_put_failure: |
| 11522 | nlmsg_free(msg); |
| 11523 | return -ENOBUFS; |
| 11524 | } |
| 11525 | |
| 11526 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 11527 | struct genl_info *info) |
| 11528 | { |
| 11529 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11530 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11531 | u64 cookie; |
| 11532 | |
| 11533 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11534 | return -EOPNOTSUPP; |
| 11535 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11536 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11537 | return -ENOTCONN; |
| 11538 | |
| 11539 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11540 | return -EINVAL; |
| 11541 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11542 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11543 | |
| 11544 | rdev_del_nan_func(rdev, wdev, cookie); |
| 11545 | |
| 11546 | return 0; |
| 11547 | } |
| 11548 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11549 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 11550 | struct genl_info *info) |
| 11551 | { |
| 11552 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11553 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11554 | struct cfg80211_nan_conf conf = {}; |
| 11555 | u32 changed = 0; |
| 11556 | |
| 11557 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11558 | return -EOPNOTSUPP; |
| 11559 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11560 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11561 | return -ENOTCONN; |
| 11562 | |
| 11563 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 11564 | conf.master_pref = |
| 11565 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11566 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 11567 | return -EINVAL; |
| 11568 | |
| 11569 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 11570 | } |
| 11571 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 11572 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 11573 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 11574 | |
| 11575 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 11576 | return -EOPNOTSUPP; |
| 11577 | |
| 11578 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 11579 | return -EINVAL; |
| 11580 | |
| 11581 | conf.bands = bands; |
| 11582 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11583 | } |
| 11584 | |
| 11585 | if (!changed) |
| 11586 | return -EINVAL; |
| 11587 | |
| 11588 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 11589 | } |
| 11590 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 11591 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 11592 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 11593 | { |
| 11594 | struct wiphy *wiphy = wdev->wiphy; |
| 11595 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11596 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 11597 | struct sk_buff *msg; |
| 11598 | void *hdr; |
| 11599 | |
| 11600 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 11601 | return; |
| 11602 | |
| 11603 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11604 | if (!msg) |
| 11605 | return; |
| 11606 | |
| 11607 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 11608 | if (!hdr) { |
| 11609 | nlmsg_free(msg); |
| 11610 | return; |
| 11611 | } |
| 11612 | |
| 11613 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11614 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11615 | wdev->netdev->ifindex)) || |
| 11616 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11617 | NL80211_ATTR_PAD)) |
| 11618 | goto nla_put_failure; |
| 11619 | |
| 11620 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 11621 | NL80211_ATTR_PAD) || |
| 11622 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 11623 | goto nla_put_failure; |
| 11624 | |
| 11625 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); |
| 11626 | if (!match_attr) |
| 11627 | goto nla_put_failure; |
| 11628 | |
| 11629 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); |
| 11630 | if (!local_func_attr) |
| 11631 | goto nla_put_failure; |
| 11632 | |
| 11633 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 11634 | goto nla_put_failure; |
| 11635 | |
| 11636 | nla_nest_end(msg, local_func_attr); |
| 11637 | |
| 11638 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); |
| 11639 | if (!peer_func_attr) |
| 11640 | goto nla_put_failure; |
| 11641 | |
| 11642 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 11643 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 11644 | goto nla_put_failure; |
| 11645 | |
| 11646 | if (match->info && match->info_len && |
| 11647 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 11648 | match->info)) |
| 11649 | goto nla_put_failure; |
| 11650 | |
| 11651 | nla_nest_end(msg, peer_func_attr); |
| 11652 | nla_nest_end(msg, match_attr); |
| 11653 | genlmsg_end(msg, hdr); |
| 11654 | |
| 11655 | if (!wdev->owner_nlportid) |
| 11656 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11657 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11658 | else |
| 11659 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11660 | wdev->owner_nlportid); |
| 11661 | |
| 11662 | return; |
| 11663 | |
| 11664 | nla_put_failure: |
| 11665 | nlmsg_free(msg); |
| 11666 | } |
| 11667 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 11668 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 11669 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 11670 | u8 inst_id, |
| 11671 | enum nl80211_nan_func_term_reason reason, |
| 11672 | u64 cookie, gfp_t gfp) |
| 11673 | { |
| 11674 | struct wiphy *wiphy = wdev->wiphy; |
| 11675 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11676 | struct sk_buff *msg; |
| 11677 | struct nlattr *func_attr; |
| 11678 | void *hdr; |
| 11679 | |
| 11680 | if (WARN_ON(!inst_id)) |
| 11681 | return; |
| 11682 | |
| 11683 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11684 | if (!msg) |
| 11685 | return; |
| 11686 | |
| 11687 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 11688 | if (!hdr) { |
| 11689 | nlmsg_free(msg); |
| 11690 | return; |
| 11691 | } |
| 11692 | |
| 11693 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11694 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11695 | wdev->netdev->ifindex)) || |
| 11696 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11697 | NL80211_ATTR_PAD)) |
| 11698 | goto nla_put_failure; |
| 11699 | |
| 11700 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11701 | NL80211_ATTR_PAD)) |
| 11702 | goto nla_put_failure; |
| 11703 | |
| 11704 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11705 | if (!func_attr) |
| 11706 | goto nla_put_failure; |
| 11707 | |
| 11708 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 11709 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 11710 | goto nla_put_failure; |
| 11711 | |
| 11712 | nla_nest_end(msg, func_attr); |
| 11713 | genlmsg_end(msg, hdr); |
| 11714 | |
| 11715 | if (!wdev->owner_nlportid) |
| 11716 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11717 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11718 | else |
| 11719 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11720 | wdev->owner_nlportid); |
| 11721 | |
| 11722 | return; |
| 11723 | |
| 11724 | nla_put_failure: |
| 11725 | nlmsg_free(msg); |
| 11726 | } |
| 11727 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 11728 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11729 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 11730 | struct genl_info *info) |
| 11731 | { |
| 11732 | void *hdr; |
| 11733 | struct sk_buff *msg; |
| 11734 | |
| 11735 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11736 | if (!msg) |
| 11737 | return -ENOMEM; |
| 11738 | |
| 11739 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11740 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 11741 | if (!hdr) |
| 11742 | goto nla_put_failure; |
| 11743 | |
| 11744 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 11745 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 11746 | goto nla_put_failure; |
| 11747 | |
| 11748 | genlmsg_end(msg, hdr); |
| 11749 | return genlmsg_reply(msg, info); |
| 11750 | |
| 11751 | nla_put_failure: |
| 11752 | kfree_skb(msg); |
| 11753 | return -ENOBUFS; |
| 11754 | } |
| 11755 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11756 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 11757 | { |
| 11758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11759 | struct cfg80211_update_ft_ies_params ft_params; |
| 11760 | struct net_device *dev = info->user_ptr[1]; |
| 11761 | |
| 11762 | if (!rdev->ops->update_ft_ies) |
| 11763 | return -EOPNOTSUPP; |
| 11764 | |
| 11765 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 11766 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 11767 | return -EINVAL; |
| 11768 | |
| 11769 | memset(&ft_params, 0, sizeof(ft_params)); |
| 11770 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 11771 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 11772 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 11773 | |
| 11774 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 11775 | } |
| 11776 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11777 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 11778 | struct genl_info *info) |
| 11779 | { |
| 11780 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11781 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11782 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 11783 | u16 duration; |
| 11784 | int ret; |
| 11785 | |
| 11786 | if (!rdev->ops->crit_proto_start) |
| 11787 | return -EOPNOTSUPP; |
| 11788 | |
| 11789 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 11790 | return -EINVAL; |
| 11791 | |
| 11792 | if (rdev->crit_proto_nlportid) |
| 11793 | return -EBUSY; |
| 11794 | |
| 11795 | /* determine protocol if provided */ |
| 11796 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 11797 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 11798 | |
| 11799 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 11800 | return -EINVAL; |
| 11801 | |
| 11802 | /* timeout must be provided */ |
| 11803 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 11804 | return -EINVAL; |
| 11805 | |
| 11806 | duration = |
| 11807 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 11808 | |
| 11809 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 11810 | return -ERANGE; |
| 11811 | |
| 11812 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 11813 | if (!ret) |
| 11814 | rdev->crit_proto_nlportid = info->snd_portid; |
| 11815 | |
| 11816 | return ret; |
| 11817 | } |
| 11818 | |
| 11819 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 11820 | struct genl_info *info) |
| 11821 | { |
| 11822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11823 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11824 | |
| 11825 | if (!rdev->ops->crit_proto_stop) |
| 11826 | return -EOPNOTSUPP; |
| 11827 | |
| 11828 | if (rdev->crit_proto_nlportid) { |
| 11829 | rdev->crit_proto_nlportid = 0; |
| 11830 | rdev_crit_proto_stop(rdev, wdev); |
| 11831 | } |
| 11832 | return 0; |
| 11833 | } |
| 11834 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11835 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 11836 | { |
| 11837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11838 | struct wireless_dev *wdev = |
| 11839 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 11840 | int i, err; |
| 11841 | u32 vid, subcmd; |
| 11842 | |
| 11843 | if (!rdev->wiphy.vendor_commands) |
| 11844 | return -EOPNOTSUPP; |
| 11845 | |
| 11846 | if (IS_ERR(wdev)) { |
| 11847 | err = PTR_ERR(wdev); |
| 11848 | if (err != -EINVAL) |
| 11849 | return err; |
| 11850 | wdev = NULL; |
| 11851 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 11852 | return -EINVAL; |
| 11853 | } |
| 11854 | |
| 11855 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 11856 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11857 | return -EINVAL; |
| 11858 | |
| 11859 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 11860 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 11861 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 11862 | const struct wiphy_vendor_command *vcmd; |
| 11863 | void *data = NULL; |
| 11864 | int len = 0; |
| 11865 | |
| 11866 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 11867 | |
| 11868 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11869 | continue; |
| 11870 | |
| 11871 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11872 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 11873 | if (!wdev) |
| 11874 | return -EINVAL; |
| 11875 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 11876 | !wdev->netdev) |
| 11877 | return -EINVAL; |
| 11878 | |
| 11879 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11880 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11881 | return -ENETDOWN; |
| 11882 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11883 | |
| 11884 | if (!vcmd->doit) |
| 11885 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11886 | } else { |
| 11887 | wdev = NULL; |
| 11888 | } |
| 11889 | |
| 11890 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 11891 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11892 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11893 | } |
| 11894 | |
| 11895 | rdev->cur_cmd_info = info; |
| 11896 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 11897 | data, len); |
| 11898 | rdev->cur_cmd_info = NULL; |
| 11899 | return err; |
| 11900 | } |
| 11901 | |
| 11902 | return -EOPNOTSUPP; |
| 11903 | } |
| 11904 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11905 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 11906 | struct netlink_callback *cb, |
| 11907 | struct cfg80211_registered_device **rdev, |
| 11908 | struct wireless_dev **wdev) |
| 11909 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11910 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11911 | u32 vid, subcmd; |
| 11912 | unsigned int i; |
| 11913 | int vcmd_idx = -1; |
| 11914 | int err; |
| 11915 | void *data = NULL; |
| 11916 | unsigned int data_len = 0; |
| 11917 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11918 | if (cb->args[0]) { |
| 11919 | /* subtract the 1 again here */ |
| 11920 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 11921 | struct wireless_dev *tmp; |
| 11922 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11923 | if (!wiphy) |
| 11924 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11925 | *rdev = wiphy_to_rdev(wiphy); |
| 11926 | *wdev = NULL; |
| 11927 | |
| 11928 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 11929 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11930 | if (tmp->identifier == cb->args[1] - 1) { |
| 11931 | *wdev = tmp; |
| 11932 | break; |
| 11933 | } |
| 11934 | } |
| 11935 | } |
| 11936 | |
| 11937 | /* keep rtnl locked in successful case */ |
| 11938 | return 0; |
| 11939 | } |
| 11940 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 11941 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf, |
| 11942 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11943 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11944 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11945 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11946 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11947 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11948 | return -EINVAL; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11949 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11950 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11951 | if (IS_ERR(*wdev)) |
| 11952 | *wdev = NULL; |
| 11953 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11954 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11955 | if (IS_ERR(*rdev)) |
| 11956 | return PTR_ERR(*rdev); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11957 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11958 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 11959 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11960 | |
| 11961 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 11962 | const struct wiphy_vendor_command *vcmd; |
| 11963 | |
| 11964 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 11965 | |
| 11966 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11967 | continue; |
| 11968 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11969 | if (!vcmd->dumpit) |
| 11970 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11971 | |
| 11972 | vcmd_idx = i; |
| 11973 | break; |
| 11974 | } |
| 11975 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11976 | if (vcmd_idx < 0) |
| 11977 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11978 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11979 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 11980 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 11981 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11982 | } |
| 11983 | |
| 11984 | /* 0 is the first index - add 1 to parse only once */ |
| 11985 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 11986 | /* add 1 to know if it was NULL */ |
| 11987 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 11988 | cb->args[2] = vcmd_idx; |
| 11989 | cb->args[3] = (unsigned long)data; |
| 11990 | cb->args[4] = data_len; |
| 11991 | |
| 11992 | /* keep rtnl locked in successful case */ |
| 11993 | return 0; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11994 | } |
| 11995 | |
| 11996 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 11997 | struct netlink_callback *cb) |
| 11998 | { |
| 11999 | struct cfg80211_registered_device *rdev; |
| 12000 | struct wireless_dev *wdev; |
| 12001 | unsigned int vcmd_idx; |
| 12002 | const struct wiphy_vendor_command *vcmd; |
| 12003 | void *data; |
| 12004 | int data_len; |
| 12005 | int err; |
| 12006 | struct nlattr *vendor_data; |
| 12007 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12008 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12009 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 12010 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12011 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12012 | |
| 12013 | vcmd_idx = cb->args[2]; |
| 12014 | data = (void *)cb->args[3]; |
| 12015 | data_len = cb->args[4]; |
| 12016 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 12017 | |
| 12018 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 12019 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12020 | if (!wdev) { |
| 12021 | err = -EINVAL; |
| 12022 | goto out; |
| 12023 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12024 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12025 | !wdev->netdev) { |
| 12026 | err = -EINVAL; |
| 12027 | goto out; |
| 12028 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12029 | |
| 12030 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 12031 | if (!wdev_running(wdev)) { |
| 12032 | err = -ENETDOWN; |
| 12033 | goto out; |
| 12034 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12035 | } |
| 12036 | } |
| 12037 | |
| 12038 | while (1) { |
| 12039 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 12040 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 12041 | NL80211_CMD_VENDOR); |
| 12042 | if (!hdr) |
| 12043 | break; |
| 12044 | |
| 12045 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12046 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 12047 | wdev_id(wdev), |
| 12048 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12049 | genlmsg_cancel(skb, hdr); |
| 12050 | break; |
| 12051 | } |
| 12052 | |
| 12053 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 12054 | if (!vendor_data) { |
| 12055 | genlmsg_cancel(skb, hdr); |
| 12056 | break; |
| 12057 | } |
| 12058 | |
| 12059 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 12060 | (unsigned long *)&cb->args[5]); |
| 12061 | nla_nest_end(skb, vendor_data); |
| 12062 | |
| 12063 | if (err == -ENOBUFS || err == -ENOENT) { |
| 12064 | genlmsg_cancel(skb, hdr); |
| 12065 | break; |
| 12066 | } else if (err) { |
| 12067 | genlmsg_cancel(skb, hdr); |
| 12068 | goto out; |
| 12069 | } |
| 12070 | |
| 12071 | genlmsg_end(skb, hdr); |
| 12072 | } |
| 12073 | |
| 12074 | err = skb->len; |
| 12075 | out: |
| 12076 | rtnl_unlock(); |
| 12077 | return err; |
| 12078 | } |
| 12079 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12080 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 12081 | enum nl80211_commands cmd, |
| 12082 | enum nl80211_attrs attr, |
| 12083 | int approxlen) |
| 12084 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12085 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12086 | |
| 12087 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 12088 | return NULL; |
| 12089 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 12090 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12091 | rdev->cur_cmd_info->snd_portid, |
| 12092 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 12093 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12094 | } |
| 12095 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 12096 | |
| 12097 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 12098 | { |
| 12099 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 12100 | void *hdr = ((void **)skb->cb)[1]; |
| 12101 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 12102 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 12103 | /* clear CB data for netlink core to own from now on */ |
| 12104 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 12105 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12106 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 12107 | kfree_skb(skb); |
| 12108 | return -EINVAL; |
| 12109 | } |
| 12110 | |
| 12111 | nla_nest_end(skb, data); |
| 12112 | genlmsg_end(skb, hdr); |
| 12113 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 12114 | } |
| 12115 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 12116 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12117 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 12118 | struct genl_info *info) |
| 12119 | { |
| 12120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12121 | struct cfg80211_qos_map *qos_map = NULL; |
| 12122 | struct net_device *dev = info->user_ptr[1]; |
| 12123 | u8 *pos, len, num_des, des_len, des; |
| 12124 | int ret; |
| 12125 | |
| 12126 | if (!rdev->ops->set_qos_map) |
| 12127 | return -EOPNOTSUPP; |
| 12128 | |
| 12129 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 12130 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 12131 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 12132 | |
| 12133 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 12134 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 12135 | return -EINVAL; |
| 12136 | |
| 12137 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 12138 | if (!qos_map) |
| 12139 | return -ENOMEM; |
| 12140 | |
| 12141 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 12142 | if (num_des) { |
| 12143 | des_len = num_des * |
| 12144 | sizeof(struct cfg80211_dscp_exception); |
| 12145 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 12146 | qos_map->num_des = num_des; |
| 12147 | for (des = 0; des < num_des; des++) { |
| 12148 | if (qos_map->dscp_exception[des].up > 7) { |
| 12149 | kfree(qos_map); |
| 12150 | return -EINVAL; |
| 12151 | } |
| 12152 | } |
| 12153 | pos += des_len; |
| 12154 | } |
| 12155 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 12156 | } |
| 12157 | |
| 12158 | wdev_lock(dev->ieee80211_ptr); |
| 12159 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 12160 | if (!ret) |
| 12161 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 12162 | wdev_unlock(dev->ieee80211_ptr); |
| 12163 | |
| 12164 | kfree(qos_map); |
| 12165 | return ret; |
| 12166 | } |
| 12167 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12168 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12169 | { |
| 12170 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12171 | struct net_device *dev = info->user_ptr[1]; |
| 12172 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12173 | const u8 *peer; |
| 12174 | u8 tsid, up; |
| 12175 | u16 admitted_time = 0; |
| 12176 | int err; |
| 12177 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12178 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12179 | return -EOPNOTSUPP; |
| 12180 | |
| 12181 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 12182 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 12183 | return -EINVAL; |
| 12184 | |
| 12185 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12186 | if (tsid >= IEEE80211_NUM_TIDS) |
| 12187 | return -EINVAL; |
| 12188 | |
| 12189 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 12190 | if (up >= IEEE80211_NUM_UPS) |
| 12191 | return -EINVAL; |
| 12192 | |
| 12193 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12194 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12195 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12196 | * need more attributes for that (e.g. BA session requirement); |
| 12197 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12198 | */ |
| 12199 | return -EINVAL; |
| 12200 | } |
| 12201 | |
| 12202 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12203 | |
| 12204 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 12205 | admitted_time = |
| 12206 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 12207 | if (!admitted_time) |
| 12208 | return -EINVAL; |
| 12209 | } |
| 12210 | |
| 12211 | wdev_lock(wdev); |
| 12212 | switch (wdev->iftype) { |
| 12213 | case NL80211_IFTYPE_STATION: |
| 12214 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12215 | if (wdev->current_bss) |
| 12216 | break; |
| 12217 | err = -ENOTCONN; |
| 12218 | goto out; |
| 12219 | default: |
| 12220 | err = -EOPNOTSUPP; |
| 12221 | goto out; |
| 12222 | } |
| 12223 | |
| 12224 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 12225 | |
| 12226 | out: |
| 12227 | wdev_unlock(wdev); |
| 12228 | return err; |
| 12229 | } |
| 12230 | |
| 12231 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12232 | { |
| 12233 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12234 | struct net_device *dev = info->user_ptr[1]; |
| 12235 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12236 | const u8 *peer; |
| 12237 | u8 tsid; |
| 12238 | int err; |
| 12239 | |
| 12240 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 12241 | return -EINVAL; |
| 12242 | |
| 12243 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12244 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12245 | |
| 12246 | wdev_lock(wdev); |
| 12247 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 12248 | wdev_unlock(wdev); |
| 12249 | |
| 12250 | return err; |
| 12251 | } |
| 12252 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12253 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 12254 | struct genl_info *info) |
| 12255 | { |
| 12256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12257 | struct net_device *dev = info->user_ptr[1]; |
| 12258 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12259 | struct cfg80211_chan_def chandef = {}; |
| 12260 | const u8 *addr; |
| 12261 | u8 oper_class; |
| 12262 | int err; |
| 12263 | |
| 12264 | if (!rdev->ops->tdls_channel_switch || |
| 12265 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12266 | return -EOPNOTSUPP; |
| 12267 | |
| 12268 | switch (dev->ieee80211_ptr->iftype) { |
| 12269 | case NL80211_IFTYPE_STATION: |
| 12270 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12271 | break; |
| 12272 | default: |
| 12273 | return -EOPNOTSUPP; |
| 12274 | } |
| 12275 | |
| 12276 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 12277 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 12278 | return -EINVAL; |
| 12279 | |
| 12280 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 12281 | if (err) |
| 12282 | return err; |
| 12283 | |
| 12284 | /* |
| 12285 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 12286 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 12287 | * specification is not defined for them. |
| 12288 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 12289 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12290 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 12291 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 12292 | return -EINVAL; |
| 12293 | |
| 12294 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 12295 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 12296 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12297 | return -EINVAL; |
| 12298 | |
| 12299 | /* don't allow switching to DFS channels */ |
| 12300 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 12301 | return -EINVAL; |
| 12302 | |
| 12303 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12304 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 12305 | |
| 12306 | wdev_lock(wdev); |
| 12307 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 12308 | wdev_unlock(wdev); |
| 12309 | |
| 12310 | return err; |
| 12311 | } |
| 12312 | |
| 12313 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 12314 | struct genl_info *info) |
| 12315 | { |
| 12316 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12317 | struct net_device *dev = info->user_ptr[1]; |
| 12318 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12319 | const u8 *addr; |
| 12320 | |
| 12321 | if (!rdev->ops->tdls_channel_switch || |
| 12322 | !rdev->ops->tdls_cancel_channel_switch || |
| 12323 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12324 | return -EOPNOTSUPP; |
| 12325 | |
| 12326 | switch (dev->ieee80211_ptr->iftype) { |
| 12327 | case NL80211_IFTYPE_STATION: |
| 12328 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12329 | break; |
| 12330 | default: |
| 12331 | return -EOPNOTSUPP; |
| 12332 | } |
| 12333 | |
| 12334 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12335 | return -EINVAL; |
| 12336 | |
| 12337 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12338 | |
| 12339 | wdev_lock(wdev); |
| 12340 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 12341 | wdev_unlock(wdev); |
| 12342 | |
| 12343 | return 0; |
| 12344 | } |
| 12345 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12346 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 12347 | struct genl_info *info) |
| 12348 | { |
| 12349 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12350 | struct net_device *dev = info->user_ptr[1]; |
| 12351 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12352 | const struct nlattr *nla; |
| 12353 | bool enabled; |
| 12354 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12355 | if (!rdev->ops->set_multicast_to_unicast) |
| 12356 | return -EOPNOTSUPP; |
| 12357 | |
| 12358 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12359 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12360 | return -EOPNOTSUPP; |
| 12361 | |
| 12362 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 12363 | enabled = nla_get_flag(nla); |
| 12364 | |
| 12365 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 12366 | } |
| 12367 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 12368 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 12369 | { |
| 12370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12371 | struct net_device *dev = info->user_ptr[1]; |
| 12372 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12373 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 12374 | int ret; |
| 12375 | |
| 12376 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 12377 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 12378 | return -EOPNOTSUPP; |
| 12379 | |
| 12380 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 12381 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 12382 | return -EOPNOTSUPP; |
| 12383 | |
| 12384 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 12385 | return -EINVAL; |
| 12386 | |
| 12387 | wdev_lock(wdev); |
| 12388 | if (!wdev->current_bss) { |
| 12389 | ret = -ENOTCONN; |
| 12390 | goto out; |
| 12391 | } |
| 12392 | |
| 12393 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12394 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 12395 | ret = -EINVAL; |
| 12396 | goto out; |
| 12397 | } |
| 12398 | |
| 12399 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 12400 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 12401 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 12402 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 12403 | ret = -EINVAL; |
| 12404 | goto out; |
| 12405 | } |
| 12406 | |
| 12407 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { |
| 12408 | int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 12409 | |
| 12410 | if (r0_name_len != WLAN_PMK_NAME_LEN) { |
| 12411 | ret = -EINVAL; |
| 12412 | goto out; |
| 12413 | } |
| 12414 | |
| 12415 | pmk_conf.pmk_r0_name = |
| 12416 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 12417 | } |
| 12418 | |
| 12419 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 12420 | out: |
| 12421 | wdev_unlock(wdev); |
| 12422 | return ret; |
| 12423 | } |
| 12424 | |
| 12425 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 12426 | { |
| 12427 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12428 | struct net_device *dev = info->user_ptr[1]; |
| 12429 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12430 | const u8 *aa; |
| 12431 | int ret; |
| 12432 | |
| 12433 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 12434 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 12435 | return -EOPNOTSUPP; |
| 12436 | |
| 12437 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 12438 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 12439 | return -EOPNOTSUPP; |
| 12440 | |
| 12441 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12442 | return -EINVAL; |
| 12443 | |
| 12444 | wdev_lock(wdev); |
| 12445 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12446 | ret = rdev_del_pmk(rdev, dev, aa); |
| 12447 | wdev_unlock(wdev); |
| 12448 | |
| 12449 | return ret; |
| 12450 | } |
| 12451 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12452 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 12453 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 12454 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12455 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 12456 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 12457 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12458 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12459 | /* 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] | 12460 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 12461 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12462 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12463 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 12464 | 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] | 12465 | struct genl_info *info) |
| 12466 | { |
| 12467 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12468 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12469 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12470 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 12471 | |
| 12472 | if (rtnl) |
| 12473 | rtnl_lock(); |
| 12474 | |
| 12475 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 12476 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12477 | if (IS_ERR(rdev)) { |
| 12478 | if (rtnl) |
| 12479 | rtnl_unlock(); |
| 12480 | return PTR_ERR(rdev); |
| 12481 | } |
| 12482 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12483 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 12484 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12485 | ASSERT_RTNL(); |
| 12486 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12487 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 12488 | info->attrs); |
| 12489 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12490 | if (rtnl) |
| 12491 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12492 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12493 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12494 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12495 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12496 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12497 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12498 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 12499 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12500 | if (rtnl) |
| 12501 | rtnl_unlock(); |
| 12502 | return -EINVAL; |
| 12503 | } |
| 12504 | |
| 12505 | info->user_ptr[1] = dev; |
| 12506 | } else { |
| 12507 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12508 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12509 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12510 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 12511 | !wdev_running(wdev)) { |
| 12512 | if (rtnl) |
| 12513 | rtnl_unlock(); |
| 12514 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12515 | } |
| 12516 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12517 | if (dev) |
| 12518 | dev_hold(dev); |
| 12519 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12520 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12521 | } |
| 12522 | |
| 12523 | return 0; |
| 12524 | } |
| 12525 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 12526 | 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] | 12527 | struct genl_info *info) |
| 12528 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12529 | if (info->user_ptr[1]) { |
| 12530 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 12531 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12532 | |
| 12533 | if (wdev->netdev) |
| 12534 | dev_put(wdev->netdev); |
| 12535 | } else { |
| 12536 | dev_put(info->user_ptr[1]); |
| 12537 | } |
| 12538 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12539 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12540 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 12541 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12542 | |
| 12543 | /* If needed, clear the netlink message payload from the SKB |
| 12544 | * as it might contain key data that shouldn't stick around on |
| 12545 | * the heap after the SKB is freed. The netlink message header |
| 12546 | * is still needed for further processing, so leave it intact. |
| 12547 | */ |
| 12548 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 12549 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 12550 | |
| 12551 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 12552 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12553 | } |
| 12554 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 12555 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12556 | { |
| 12557 | .cmd = NL80211_CMD_GET_WIPHY, |
| 12558 | .doit = nl80211_get_wiphy, |
| 12559 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 12560 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12561 | .policy = nl80211_policy, |
| 12562 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12563 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12564 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12565 | }, |
| 12566 | { |
| 12567 | .cmd = NL80211_CMD_SET_WIPHY, |
| 12568 | .doit = nl80211_set_wiphy, |
| 12569 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12570 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12571 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12572 | }, |
| 12573 | { |
| 12574 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 12575 | .doit = nl80211_get_interface, |
| 12576 | .dumpit = nl80211_dump_interface, |
| 12577 | .policy = nl80211_policy, |
| 12578 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12579 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12580 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12581 | }, |
| 12582 | { |
| 12583 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 12584 | .doit = nl80211_set_interface, |
| 12585 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12586 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12587 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12588 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12589 | }, |
| 12590 | { |
| 12591 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 12592 | .doit = nl80211_new_interface, |
| 12593 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12594 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12595 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12596 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12597 | }, |
| 12598 | { |
| 12599 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 12600 | .doit = nl80211_del_interface, |
| 12601 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12602 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 12603 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12604 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12605 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12606 | { |
| 12607 | .cmd = NL80211_CMD_GET_KEY, |
| 12608 | .doit = nl80211_get_key, |
| 12609 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12610 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12611 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12612 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12613 | }, |
| 12614 | { |
| 12615 | .cmd = NL80211_CMD_SET_KEY, |
| 12616 | .doit = nl80211_set_key, |
| 12617 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12618 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12619 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12620 | NL80211_FLAG_NEED_RTNL | |
| 12621 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12622 | }, |
| 12623 | { |
| 12624 | .cmd = NL80211_CMD_NEW_KEY, |
| 12625 | .doit = nl80211_new_key, |
| 12626 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12627 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12628 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12629 | NL80211_FLAG_NEED_RTNL | |
| 12630 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12631 | }, |
| 12632 | { |
| 12633 | .cmd = NL80211_CMD_DEL_KEY, |
| 12634 | .doit = nl80211_del_key, |
| 12635 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12636 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12637 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12638 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12639 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12640 | { |
| 12641 | .cmd = NL80211_CMD_SET_BEACON, |
| 12642 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12643 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12644 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12645 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12646 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12647 | }, |
| 12648 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12649 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12650 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12651 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12652 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12653 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12654 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12655 | }, |
| 12656 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12657 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12658 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12659 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12660 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12661 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12662 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12663 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12664 | { |
| 12665 | .cmd = NL80211_CMD_GET_STATION, |
| 12666 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12667 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12668 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12669 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12670 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12671 | }, |
| 12672 | { |
| 12673 | .cmd = NL80211_CMD_SET_STATION, |
| 12674 | .doit = nl80211_set_station, |
| 12675 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12676 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12677 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12678 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12679 | }, |
| 12680 | { |
| 12681 | .cmd = NL80211_CMD_NEW_STATION, |
| 12682 | .doit = nl80211_new_station, |
| 12683 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12684 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12685 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12686 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12687 | }, |
| 12688 | { |
| 12689 | .cmd = NL80211_CMD_DEL_STATION, |
| 12690 | .doit = nl80211_del_station, |
| 12691 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12692 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12693 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12694 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12695 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12696 | { |
| 12697 | .cmd = NL80211_CMD_GET_MPATH, |
| 12698 | .doit = nl80211_get_mpath, |
| 12699 | .dumpit = nl80211_dump_mpath, |
| 12700 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12701 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12702 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12703 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12704 | }, |
| 12705 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12706 | .cmd = NL80211_CMD_GET_MPP, |
| 12707 | .doit = nl80211_get_mpp, |
| 12708 | .dumpit = nl80211_dump_mpp, |
| 12709 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12710 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12711 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12712 | NL80211_FLAG_NEED_RTNL, |
| 12713 | }, |
| 12714 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12715 | .cmd = NL80211_CMD_SET_MPATH, |
| 12716 | .doit = nl80211_set_mpath, |
| 12717 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12718 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12719 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12720 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12721 | }, |
| 12722 | { |
| 12723 | .cmd = NL80211_CMD_NEW_MPATH, |
| 12724 | .doit = nl80211_new_mpath, |
| 12725 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12726 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12727 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12728 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12729 | }, |
| 12730 | { |
| 12731 | .cmd = NL80211_CMD_DEL_MPATH, |
| 12732 | .doit = nl80211_del_mpath, |
| 12733 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12734 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12735 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12736 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12737 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12738 | { |
| 12739 | .cmd = NL80211_CMD_SET_BSS, |
| 12740 | .doit = nl80211_set_bss, |
| 12741 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12742 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12743 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12744 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12745 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12746 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12747 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12748 | .doit = nl80211_get_reg_do, |
| 12749 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12750 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12751 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12752 | /* can be retrieved by unprivileged users */ |
| 12753 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12754 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12755 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12756 | .cmd = NL80211_CMD_SET_REG, |
| 12757 | .doit = nl80211_set_reg, |
| 12758 | .policy = nl80211_policy, |
| 12759 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12760 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12761 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12762 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12763 | { |
| 12764 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 12765 | .doit = nl80211_req_set_reg, |
| 12766 | .policy = nl80211_policy, |
| 12767 | .flags = GENL_ADMIN_PERM, |
| 12768 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12769 | { |
Johannes Berg | 1ea4ff3 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 12770 | .cmd = NL80211_CMD_RELOAD_REGDB, |
| 12771 | .doit = nl80211_reload_regdb, |
| 12772 | .policy = nl80211_policy, |
| 12773 | .flags = GENL_ADMIN_PERM, |
| 12774 | }, |
| 12775 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12776 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 12777 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12778 | .policy = nl80211_policy, |
| 12779 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12780 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12781 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12782 | }, |
| 12783 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12784 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 12785 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12786 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12787 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12788 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12789 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12790 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 12791 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12792 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 12793 | .doit = nl80211_trigger_scan, |
| 12794 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12795 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12796 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12797 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12798 | }, |
| 12799 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12800 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 12801 | .doit = nl80211_abort_scan, |
| 12802 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12803 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12804 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12805 | NL80211_FLAG_NEED_RTNL, |
| 12806 | }, |
| 12807 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12808 | .cmd = NL80211_CMD_GET_SCAN, |
| 12809 | .policy = nl80211_policy, |
| 12810 | .dumpit = nl80211_dump_scan, |
| 12811 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12812 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12813 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 12814 | .doit = nl80211_start_sched_scan, |
| 12815 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12816 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12817 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12818 | NL80211_FLAG_NEED_RTNL, |
| 12819 | }, |
| 12820 | { |
| 12821 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 12822 | .doit = nl80211_stop_sched_scan, |
| 12823 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12824 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12825 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12826 | NL80211_FLAG_NEED_RTNL, |
| 12827 | }, |
| 12828 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12829 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 12830 | .doit = nl80211_authenticate, |
| 12831 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12832 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12833 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12834 | NL80211_FLAG_NEED_RTNL | |
| 12835 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12836 | }, |
| 12837 | { |
| 12838 | .cmd = NL80211_CMD_ASSOCIATE, |
| 12839 | .doit = nl80211_associate, |
| 12840 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12841 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12842 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12843 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12844 | }, |
| 12845 | { |
| 12846 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 12847 | .doit = nl80211_deauthenticate, |
| 12848 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12849 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12850 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12851 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12852 | }, |
| 12853 | { |
| 12854 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 12855 | .doit = nl80211_disassociate, |
| 12856 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12857 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12858 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12859 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12860 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12861 | { |
| 12862 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 12863 | .doit = nl80211_join_ibss, |
| 12864 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12865 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12866 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12867 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12868 | }, |
| 12869 | { |
| 12870 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 12871 | .doit = nl80211_leave_ibss, |
| 12872 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12873 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12874 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12875 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12876 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12877 | #ifdef CONFIG_NL80211_TESTMODE |
| 12878 | { |
| 12879 | .cmd = NL80211_CMD_TESTMODE, |
| 12880 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 12881 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12882 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12883 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12884 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12885 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12886 | }, |
| 12887 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12888 | { |
| 12889 | .cmd = NL80211_CMD_CONNECT, |
| 12890 | .doit = nl80211_connect, |
| 12891 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12892 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12893 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12894 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12895 | }, |
| 12896 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 12897 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
| 12898 | .doit = nl80211_update_connect_params, |
| 12899 | .policy = nl80211_policy, |
| 12900 | .flags = GENL_ADMIN_PERM, |
| 12901 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12902 | NL80211_FLAG_NEED_RTNL, |
| 12903 | }, |
| 12904 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12905 | .cmd = NL80211_CMD_DISCONNECT, |
| 12906 | .doit = nl80211_disconnect, |
| 12907 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12908 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12909 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12910 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12911 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12912 | { |
| 12913 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 12914 | .doit = nl80211_wiphy_netns, |
| 12915 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12916 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12917 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12918 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12919 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 12920 | { |
| 12921 | .cmd = NL80211_CMD_GET_SURVEY, |
| 12922 | .policy = nl80211_policy, |
| 12923 | .dumpit = nl80211_dump_survey, |
| 12924 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12925 | { |
| 12926 | .cmd = NL80211_CMD_SET_PMKSA, |
| 12927 | .doit = nl80211_setdel_pmksa, |
| 12928 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12929 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12930 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12931 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12932 | }, |
| 12933 | { |
| 12934 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 12935 | .doit = nl80211_setdel_pmksa, |
| 12936 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12937 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12938 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12939 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12940 | }, |
| 12941 | { |
| 12942 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 12943 | .doit = nl80211_flush_pmksa, |
| 12944 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12945 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12946 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12947 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12948 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12949 | { |
| 12950 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 12951 | .doit = nl80211_remain_on_channel, |
| 12952 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12953 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12954 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12955 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12956 | }, |
| 12957 | { |
| 12958 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 12959 | .doit = nl80211_cancel_remain_on_channel, |
| 12960 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12961 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12962 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12963 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12964 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12965 | { |
| 12966 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 12967 | .doit = nl80211_set_tx_bitrate_mask, |
| 12968 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12969 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12970 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12971 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12972 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12973 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12974 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 12975 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12976 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12977 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12978 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12979 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12980 | }, |
| 12981 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12982 | .cmd = NL80211_CMD_FRAME, |
| 12983 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12984 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12985 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12986 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12987 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12988 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12989 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12990 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 12991 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 12992 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12993 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12994 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12995 | NL80211_FLAG_NEED_RTNL, |
| 12996 | }, |
| 12997 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12998 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 12999 | .doit = nl80211_set_power_save, |
| 13000 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13001 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13002 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13003 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 13004 | }, |
| 13005 | { |
| 13006 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 13007 | .doit = nl80211_get_power_save, |
| 13008 | .policy = nl80211_policy, |
| 13009 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13010 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13011 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 13012 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13013 | { |
| 13014 | .cmd = NL80211_CMD_SET_CQM, |
| 13015 | .doit = nl80211_set_cqm, |
| 13016 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13017 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13018 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13019 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13020 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 13021 | { |
| 13022 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 13023 | .doit = nl80211_set_channel, |
| 13024 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13025 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 13026 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13027 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 13028 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 13029 | { |
| 13030 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 13031 | .doit = nl80211_set_wds_peer, |
| 13032 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13033 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 13034 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13035 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 13036 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13037 | { |
| 13038 | .cmd = NL80211_CMD_JOIN_MESH, |
| 13039 | .doit = nl80211_join_mesh, |
| 13040 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13041 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13042 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13043 | NL80211_FLAG_NEED_RTNL, |
| 13044 | }, |
| 13045 | { |
| 13046 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 13047 | .doit = nl80211_leave_mesh, |
| 13048 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13049 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 13050 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13051 | NL80211_FLAG_NEED_RTNL, |
| 13052 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 13053 | { |
| 13054 | .cmd = NL80211_CMD_JOIN_OCB, |
| 13055 | .doit = nl80211_join_ocb, |
| 13056 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13057 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 13058 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13059 | NL80211_FLAG_NEED_RTNL, |
| 13060 | }, |
| 13061 | { |
| 13062 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 13063 | .doit = nl80211_leave_ocb, |
| 13064 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13065 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 13066 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13067 | NL80211_FLAG_NEED_RTNL, |
| 13068 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 13069 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 13070 | { |
| 13071 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 13072 | .doit = nl80211_get_wowlan, |
| 13073 | .policy = nl80211_policy, |
| 13074 | /* can be retrieved by unprivileged users */ |
| 13075 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13076 | NL80211_FLAG_NEED_RTNL, |
| 13077 | }, |
| 13078 | { |
| 13079 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 13080 | .doit = nl80211_set_wowlan, |
| 13081 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13082 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 13083 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13084 | NL80211_FLAG_NEED_RTNL, |
| 13085 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 13086 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13087 | { |
| 13088 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 13089 | .doit = nl80211_set_rekey_data, |
| 13090 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13091 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13092 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13093 | NL80211_FLAG_NEED_RTNL | |
| 13094 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13095 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13096 | { |
| 13097 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 13098 | .doit = nl80211_tdls_mgmt, |
| 13099 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13100 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13101 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13102 | NL80211_FLAG_NEED_RTNL, |
| 13103 | }, |
| 13104 | { |
| 13105 | .cmd = NL80211_CMD_TDLS_OPER, |
| 13106 | .doit = nl80211_tdls_oper, |
| 13107 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13108 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13109 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13110 | NL80211_FLAG_NEED_RTNL, |
| 13111 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13112 | { |
| 13113 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 13114 | .doit = nl80211_register_unexpected_frame, |
| 13115 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13116 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13117 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13118 | NL80211_FLAG_NEED_RTNL, |
| 13119 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13120 | { |
| 13121 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 13122 | .doit = nl80211_probe_client, |
| 13123 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13124 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13125 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13126 | NL80211_FLAG_NEED_RTNL, |
| 13127 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13128 | { |
| 13129 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 13130 | .doit = nl80211_register_beacons, |
| 13131 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13132 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13133 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13134 | NL80211_FLAG_NEED_RTNL, |
| 13135 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 13136 | { |
| 13137 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 13138 | .doit = nl80211_set_noack_map, |
| 13139 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13140 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 13141 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13142 | NL80211_FLAG_NEED_RTNL, |
| 13143 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13144 | { |
| 13145 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 13146 | .doit = nl80211_start_p2p_device, |
| 13147 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13148 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13149 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13150 | NL80211_FLAG_NEED_RTNL, |
| 13151 | }, |
| 13152 | { |
| 13153 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 13154 | .doit = nl80211_stop_p2p_device, |
| 13155 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13156 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13157 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13158 | NL80211_FLAG_NEED_RTNL, |
| 13159 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13160 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13161 | .cmd = NL80211_CMD_START_NAN, |
| 13162 | .doit = nl80211_start_nan, |
| 13163 | .policy = nl80211_policy, |
| 13164 | .flags = GENL_ADMIN_PERM, |
| 13165 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13166 | NL80211_FLAG_NEED_RTNL, |
| 13167 | }, |
| 13168 | { |
| 13169 | .cmd = NL80211_CMD_STOP_NAN, |
| 13170 | .doit = nl80211_stop_nan, |
| 13171 | .policy = nl80211_policy, |
| 13172 | .flags = GENL_ADMIN_PERM, |
| 13173 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13174 | NL80211_FLAG_NEED_RTNL, |
| 13175 | }, |
| 13176 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13177 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
| 13178 | .doit = nl80211_nan_add_func, |
| 13179 | .policy = nl80211_policy, |
| 13180 | .flags = GENL_ADMIN_PERM, |
| 13181 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13182 | NL80211_FLAG_NEED_RTNL, |
| 13183 | }, |
| 13184 | { |
| 13185 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
| 13186 | .doit = nl80211_nan_del_func, |
| 13187 | .policy = nl80211_policy, |
| 13188 | .flags = GENL_ADMIN_PERM, |
| 13189 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13190 | NL80211_FLAG_NEED_RTNL, |
| 13191 | }, |
| 13192 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13193 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
| 13194 | .doit = nl80211_nan_change_config, |
| 13195 | .policy = nl80211_policy, |
| 13196 | .flags = GENL_ADMIN_PERM, |
| 13197 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13198 | NL80211_FLAG_NEED_RTNL, |
| 13199 | }, |
| 13200 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13201 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 13202 | .doit = nl80211_set_mcast_rate, |
| 13203 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13204 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13205 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13206 | NL80211_FLAG_NEED_RTNL, |
| 13207 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 13208 | { |
| 13209 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 13210 | .doit = nl80211_set_mac_acl, |
| 13211 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13212 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 13213 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13214 | NL80211_FLAG_NEED_RTNL, |
| 13215 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13216 | { |
| 13217 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 13218 | .doit = nl80211_start_radar_detection, |
| 13219 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13220 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13221 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13222 | NL80211_FLAG_NEED_RTNL, |
| 13223 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 13224 | { |
| 13225 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 13226 | .doit = nl80211_get_protocol_features, |
| 13227 | .policy = nl80211_policy, |
| 13228 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13229 | { |
| 13230 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 13231 | .doit = nl80211_update_ft_ies, |
| 13232 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13233 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13234 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13235 | NL80211_FLAG_NEED_RTNL, |
| 13236 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13237 | { |
| 13238 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 13239 | .doit = nl80211_crit_protocol_start, |
| 13240 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13241 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13242 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13243 | NL80211_FLAG_NEED_RTNL, |
| 13244 | }, |
| 13245 | { |
| 13246 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 13247 | .doit = nl80211_crit_protocol_stop, |
| 13248 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13249 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13250 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13251 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13252 | }, |
| 13253 | { |
| 13254 | .cmd = NL80211_CMD_GET_COALESCE, |
| 13255 | .doit = nl80211_get_coalesce, |
| 13256 | .policy = nl80211_policy, |
| 13257 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13258 | NL80211_FLAG_NEED_RTNL, |
| 13259 | }, |
| 13260 | { |
| 13261 | .cmd = NL80211_CMD_SET_COALESCE, |
| 13262 | .doit = nl80211_set_coalesce, |
| 13263 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13264 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13265 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13266 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 13267 | }, |
| 13268 | { |
| 13269 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 13270 | .doit = nl80211_channel_switch, |
| 13271 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13272 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 13273 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13274 | NL80211_FLAG_NEED_RTNL, |
| 13275 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13276 | { |
| 13277 | .cmd = NL80211_CMD_VENDOR, |
| 13278 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13279 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13280 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13281 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13282 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13283 | NL80211_FLAG_NEED_RTNL, |
| 13284 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13285 | { |
| 13286 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 13287 | .doit = nl80211_set_qos_map, |
| 13288 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13289 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13290 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13291 | NL80211_FLAG_NEED_RTNL, |
| 13292 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13293 | { |
| 13294 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 13295 | .doit = nl80211_add_tx_ts, |
| 13296 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13297 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13298 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13299 | NL80211_FLAG_NEED_RTNL, |
| 13300 | }, |
| 13301 | { |
| 13302 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 13303 | .doit = nl80211_del_tx_ts, |
| 13304 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13305 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13306 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13307 | NL80211_FLAG_NEED_RTNL, |
| 13308 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13309 | { |
| 13310 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 13311 | .doit = nl80211_tdls_channel_switch, |
| 13312 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13313 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13314 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13315 | NL80211_FLAG_NEED_RTNL, |
| 13316 | }, |
| 13317 | { |
| 13318 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 13319 | .doit = nl80211_tdls_cancel_channel_switch, |
| 13320 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13321 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13322 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13323 | NL80211_FLAG_NEED_RTNL, |
| 13324 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13325 | { |
| 13326 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
| 13327 | .doit = nl80211_set_multicast_to_unicast, |
| 13328 | .policy = nl80211_policy, |
| 13329 | .flags = GENL_UNS_ADMIN_PERM, |
| 13330 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13331 | NL80211_FLAG_NEED_RTNL, |
| 13332 | }, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 13333 | { |
| 13334 | .cmd = NL80211_CMD_SET_PMK, |
| 13335 | .doit = nl80211_set_pmk, |
| 13336 | .policy = nl80211_policy, |
| 13337 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13338 | NL80211_FLAG_NEED_RTNL, |
| 13339 | }, |
| 13340 | { |
| 13341 | .cmd = NL80211_CMD_DEL_PMK, |
| 13342 | .doit = nl80211_del_pmk, |
| 13343 | .policy = nl80211_policy, |
| 13344 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13345 | NL80211_FLAG_NEED_RTNL, |
| 13346 | }, |
| 13347 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13348 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13349 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 13350 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 13351 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 13352 | .hdrsize = 0, /* no private header */ |
| 13353 | .version = 1, /* no particular meaning now */ |
| 13354 | .maxattr = NL80211_ATTR_MAX, |
| 13355 | .netnsok = true, |
| 13356 | .pre_doit = nl80211_pre_doit, |
| 13357 | .post_doit = nl80211_post_doit, |
| 13358 | .module = THIS_MODULE, |
| 13359 | .ops = nl80211_ops, |
| 13360 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| 13361 | .mcgrps = nl80211_mcgrps, |
| 13362 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
| 13363 | }; |
| 13364 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13365 | /* notification functions */ |
| 13366 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13367 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 13368 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13369 | { |
| 13370 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 13371 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13372 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13373 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 13374 | cmd != NL80211_CMD_DEL_WIPHY); |
| 13375 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13376 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13377 | if (!msg) |
| 13378 | return; |
| 13379 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13380 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13381 | nlmsg_free(msg); |
| 13382 | return; |
| 13383 | } |
| 13384 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13385 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13386 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13387 | } |
| 13388 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 13389 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 13390 | struct wireless_dev *wdev, |
| 13391 | enum nl80211_commands cmd) |
| 13392 | { |
| 13393 | struct sk_buff *msg; |
| 13394 | |
| 13395 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 13396 | cmd != NL80211_CMD_DEL_INTERFACE); |
| 13397 | |
| 13398 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13399 | if (!msg) |
| 13400 | return; |
| 13401 | |
| 13402 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, |
| 13403 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { |
| 13404 | nlmsg_free(msg); |
| 13405 | return; |
| 13406 | } |
| 13407 | |
| 13408 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 13409 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 13410 | } |
| 13411 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13412 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 13413 | struct cfg80211_registered_device *rdev) |
| 13414 | { |
| 13415 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 13416 | struct nlattr *nest; |
| 13417 | int i; |
| 13418 | |
| 13419 | if (WARN_ON(!req)) |
| 13420 | return 0; |
| 13421 | |
| 13422 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 13423 | if (!nest) |
| 13424 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13425 | for (i = 0; i < req->n_ssids; i++) { |
| 13426 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 13427 | goto nla_put_failure; |
| 13428 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13429 | nla_nest_end(msg, nest); |
| 13430 | |
| 13431 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 13432 | if (!nest) |
| 13433 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13434 | for (i = 0; i < req->n_channels; i++) { |
| 13435 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 13436 | goto nla_put_failure; |
| 13437 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13438 | nla_nest_end(msg, nest); |
| 13439 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13440 | if (req->ie && |
| 13441 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 13442 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13443 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13444 | if (req->flags && |
| 13445 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 13446 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 13447 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 13448 | if (req->info.scan_start_tsf && |
| 13449 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 13450 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 13451 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 13452 | req->info.tsf_bssid))) |
| 13453 | goto nla_put_failure; |
| 13454 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13455 | return 0; |
| 13456 | nla_put_failure: |
| 13457 | return -ENOBUFS; |
| 13458 | } |
| 13459 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13460 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13461 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13462 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13463 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13464 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13465 | { |
| 13466 | void *hdr; |
| 13467 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13468 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13469 | if (!hdr) |
| 13470 | return -1; |
| 13471 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13472 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13473 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13474 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13475 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13476 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13477 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13478 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13479 | /* ignore errors and send incomplete event anyway */ |
| 13480 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13481 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 13482 | genlmsg_end(msg, hdr); |
| 13483 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13484 | |
| 13485 | nla_put_failure: |
| 13486 | genlmsg_cancel(msg, hdr); |
| 13487 | return -EMSGSIZE; |
| 13488 | } |
| 13489 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13490 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13491 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13492 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13493 | { |
| 13494 | void *hdr; |
| 13495 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13496 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13497 | if (!hdr) |
| 13498 | return -1; |
| 13499 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13500 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 13501 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 13502 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 13503 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 13504 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13505 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13506 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 13507 | genlmsg_end(msg, hdr); |
| 13508 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13509 | |
| 13510 | nla_put_failure: |
| 13511 | genlmsg_cancel(msg, hdr); |
| 13512 | return -EMSGSIZE; |
| 13513 | } |
| 13514 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13515 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13516 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13517 | { |
| 13518 | struct sk_buff *msg; |
| 13519 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13520 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13521 | if (!msg) |
| 13522 | return; |
| 13523 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13524 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13525 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 13526 | nlmsg_free(msg); |
| 13527 | return; |
| 13528 | } |
| 13529 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13530 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13531 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13532 | } |
| 13533 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13534 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 13535 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13536 | { |
| 13537 | struct sk_buff *msg; |
| 13538 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13539 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13540 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13541 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13542 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13543 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13544 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 13545 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13546 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13547 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13548 | } |
| 13549 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13550 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13551 | } |
| 13552 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13553 | /* send message created by nl80211_build_scan_msg() */ |
| 13554 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 13555 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13556 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13557 | if (!msg) |
| 13558 | return; |
| 13559 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13560 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13561 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13562 | } |
| 13563 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13564 | 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] | 13565 | { |
| 13566 | struct sk_buff *msg; |
| 13567 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13568 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13569 | if (!msg) |
| 13570 | return; |
| 13571 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13572 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13573 | nlmsg_free(msg); |
| 13574 | return; |
| 13575 | } |
| 13576 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13577 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13578 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13579 | } |
| 13580 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 13581 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 13582 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13583 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13584 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13585 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 13586 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13587 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13588 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 13589 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13590 | NL80211_REGDOM_TYPE_WORLD)) |
| 13591 | goto nla_put_failure; |
| 13592 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 13593 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13594 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 13595 | goto nla_put_failure; |
| 13596 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 13597 | request->intersect) { |
| 13598 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13599 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 13600 | goto nla_put_failure; |
| 13601 | } else { |
| 13602 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13603 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 13604 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 13605 | request->alpha2)) |
| 13606 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13607 | } |
| 13608 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13609 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 13610 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 13611 | |
| 13612 | if (wiphy && |
| 13613 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 13614 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 13615 | |
| 13616 | if (wiphy && |
| 13617 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 13618 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 13619 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13620 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13621 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 13622 | return true; |
| 13623 | |
| 13624 | nla_put_failure: |
| 13625 | return false; |
| 13626 | } |
| 13627 | |
| 13628 | /* |
| 13629 | * This can happen on global regulatory changes or device specific settings |
| 13630 | * based on custom regulatory domains. |
| 13631 | */ |
| 13632 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 13633 | struct regulatory_request *request) |
| 13634 | { |
| 13635 | struct sk_buff *msg; |
| 13636 | void *hdr; |
| 13637 | |
| 13638 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13639 | if (!msg) |
| 13640 | return; |
| 13641 | |
| 13642 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 13643 | if (!hdr) { |
| 13644 | nlmsg_free(msg); |
| 13645 | return; |
| 13646 | } |
| 13647 | |
| 13648 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 13649 | goto nla_put_failure; |
| 13650 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13651 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13652 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13653 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13654 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13655 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13656 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13657 | |
| 13658 | return; |
| 13659 | |
| 13660 | nla_put_failure: |
| 13661 | genlmsg_cancel(msg, hdr); |
| 13662 | nlmsg_free(msg); |
| 13663 | } |
| 13664 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13665 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 13666 | struct net_device *netdev, |
| 13667 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13668 | enum nl80211_commands cmd, gfp_t gfp, |
| 13669 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13670 | { |
| 13671 | struct sk_buff *msg; |
| 13672 | void *hdr; |
| 13673 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13674 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13675 | if (!msg) |
| 13676 | return; |
| 13677 | |
| 13678 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13679 | if (!hdr) { |
| 13680 | nlmsg_free(msg); |
| 13681 | return; |
| 13682 | } |
| 13683 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13684 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13685 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13686 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 13687 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13688 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13689 | if (uapsd_queues >= 0) { |
| 13690 | struct nlattr *nla_wmm = |
| 13691 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 13692 | if (!nla_wmm) |
| 13693 | goto nla_put_failure; |
| 13694 | |
| 13695 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 13696 | uapsd_queues)) |
| 13697 | goto nla_put_failure; |
| 13698 | |
| 13699 | nla_nest_end(msg, nla_wmm); |
| 13700 | } |
| 13701 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13702 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13703 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13704 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13705 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13706 | return; |
| 13707 | |
| 13708 | nla_put_failure: |
| 13709 | genlmsg_cancel(msg, hdr); |
| 13710 | nlmsg_free(msg); |
| 13711 | } |
| 13712 | |
| 13713 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13714 | struct net_device *netdev, const u8 *buf, |
| 13715 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13716 | { |
| 13717 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13718 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13719 | } |
| 13720 | |
| 13721 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 13722 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13723 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13724 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13725 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13726 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13727 | } |
| 13728 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13729 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13730 | struct net_device *netdev, const u8 *buf, |
| 13731 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13732 | { |
| 13733 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13734 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13735 | } |
| 13736 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13737 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 13738 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13739 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13740 | { |
| 13741 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13742 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13743 | } |
| 13744 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13745 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 13746 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13747 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13748 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13749 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13750 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13751 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 13752 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13753 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13754 | if (WARN_ON(len < 2)) |
| 13755 | return; |
| 13756 | |
| 13757 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 13758 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 13759 | else |
| 13760 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 13761 | |
| 13762 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13763 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13764 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13765 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13766 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 13767 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 13768 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13769 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13770 | { |
| 13771 | struct sk_buff *msg; |
| 13772 | void *hdr; |
| 13773 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13775 | if (!msg) |
| 13776 | return; |
| 13777 | |
| 13778 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13779 | if (!hdr) { |
| 13780 | nlmsg_free(msg); |
| 13781 | return; |
| 13782 | } |
| 13783 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13784 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13785 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13786 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 13787 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 13788 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13789 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13790 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13791 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13792 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13793 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13794 | return; |
| 13795 | |
| 13796 | nla_put_failure: |
| 13797 | genlmsg_cancel(msg, hdr); |
| 13798 | nlmsg_free(msg); |
| 13799 | } |
| 13800 | |
| 13801 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13802 | struct net_device *netdev, const u8 *addr, |
| 13803 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13804 | { |
| 13805 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13806 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13807 | } |
| 13808 | |
| 13809 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13810 | struct net_device *netdev, const u8 *addr, |
| 13811 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13812 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13813 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 13814 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13815 | } |
| 13816 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13817 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13818 | struct net_device *netdev, |
| 13819 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 13820 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13821 | { |
| 13822 | struct sk_buff *msg; |
| 13823 | void *hdr; |
| 13824 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 13825 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
| 13826 | cr->fils_kek_len + cr->pmk_len + |
| 13827 | (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13828 | if (!msg) |
| 13829 | return; |
| 13830 | |
| 13831 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 13832 | if (!hdr) { |
| 13833 | nlmsg_free(msg); |
| 13834 | return; |
| 13835 | } |
| 13836 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13837 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13838 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13839 | (cr->bssid && |
| 13840 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 13841 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13842 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 13843 | cr->status) || |
| 13844 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 13845 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13846 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 13847 | cr->timeout_reason))) || |
| 13848 | (cr->req_ie && |
| 13849 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 13850 | (cr->resp_ie && |
| 13851 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 13852 | cr->resp_ie)) || |
| 13853 | (cr->update_erp_next_seq_num && |
| 13854 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 13855 | cr->fils_erp_next_seq_num)) || |
| 13856 | (cr->status == WLAN_STATUS_SUCCESS && |
| 13857 | ((cr->fils_kek && |
| 13858 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len, |
| 13859 | cr->fils_kek)) || |
| 13860 | (cr->pmk && |
| 13861 | nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) || |
| 13862 | (cr->pmkid && |
| 13863 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid))))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13864 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13865 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13866 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13867 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13868 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13869 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13870 | return; |
| 13871 | |
| 13872 | nla_put_failure: |
| 13873 | genlmsg_cancel(msg, hdr); |
| 13874 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13875 | } |
| 13876 | |
| 13877 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13878 | struct net_device *netdev, |
| 13879 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13880 | { |
| 13881 | struct sk_buff *msg; |
| 13882 | void *hdr; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13883 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13884 | |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13885 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13886 | if (!msg) |
| 13887 | return; |
| 13888 | |
| 13889 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 13890 | if (!hdr) { |
| 13891 | nlmsg_free(msg); |
| 13892 | return; |
| 13893 | } |
| 13894 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13895 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13896 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13897 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13898 | (info->req_ie && |
| 13899 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 13900 | info->req_ie)) || |
| 13901 | (info->resp_ie && |
| 13902 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 13903 | info->resp_ie))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13904 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13905 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13906 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13907 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13908 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13909 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13910 | return; |
| 13911 | |
| 13912 | nla_put_failure: |
| 13913 | genlmsg_cancel(msg, hdr); |
| 13914 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13915 | } |
| 13916 | |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 13917 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, |
| 13918 | struct net_device *netdev, const u8 *bssid) |
| 13919 | { |
| 13920 | struct sk_buff *msg; |
| 13921 | void *hdr; |
| 13922 | |
| 13923 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13924 | if (!msg) |
| 13925 | return; |
| 13926 | |
| 13927 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); |
| 13928 | if (!hdr) { |
| 13929 | nlmsg_free(msg); |
| 13930 | return; |
| 13931 | } |
| 13932 | |
| 13933 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13934 | goto nla_put_failure; |
| 13935 | |
| 13936 | genlmsg_end(msg, hdr); |
| 13937 | |
| 13938 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 13939 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 13940 | return; |
| 13941 | |
| 13942 | nla_put_failure: |
| 13943 | genlmsg_cancel(msg, hdr); |
| 13944 | nlmsg_free(msg); |
| 13945 | } |
| 13946 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13947 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 13948 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 13949 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13950 | { |
| 13951 | struct sk_buff *msg; |
| 13952 | void *hdr; |
| 13953 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13954 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13955 | if (!msg) |
| 13956 | return; |
| 13957 | |
| 13958 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 13959 | if (!hdr) { |
| 13960 | nlmsg_free(msg); |
| 13961 | return; |
| 13962 | } |
| 13963 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13964 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13965 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
David Spinadel | 86b6c46 | 2017-12-18 12:14:05 +0200 | [diff] [blame^] | 13966 | (reason && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13967 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 13968 | (from_ap && |
| 13969 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 13970 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 13971 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13972 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13973 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13974 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13975 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13976 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13977 | return; |
| 13978 | |
| 13979 | nla_put_failure: |
| 13980 | genlmsg_cancel(msg, hdr); |
| 13981 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13982 | } |
| 13983 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13984 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 13985 | struct net_device *netdev, const u8 *bssid, |
| 13986 | gfp_t gfp) |
| 13987 | { |
| 13988 | struct sk_buff *msg; |
| 13989 | void *hdr; |
| 13990 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13991 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13992 | if (!msg) |
| 13993 | return; |
| 13994 | |
| 13995 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 13996 | if (!hdr) { |
| 13997 | nlmsg_free(msg); |
| 13998 | return; |
| 13999 | } |
| 14000 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14001 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14002 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14003 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 14004 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14005 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14006 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14007 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14008 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14009 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14010 | return; |
| 14011 | |
| 14012 | nla_put_failure: |
| 14013 | genlmsg_cancel(msg, hdr); |
| 14014 | nlmsg_free(msg); |
| 14015 | } |
| 14016 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14017 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 14018 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14019 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14020 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14021 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14022 | struct sk_buff *msg; |
| 14023 | void *hdr; |
| 14024 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14025 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 14026 | return; |
| 14027 | |
| 14028 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 14029 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14030 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14031 | if (!msg) |
| 14032 | return; |
| 14033 | |
| 14034 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 14035 | if (!hdr) { |
| 14036 | nlmsg_free(msg); |
| 14037 | return; |
| 14038 | } |
| 14039 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14040 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14041 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14042 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14043 | (ie_len && ie && |
| 14044 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 14045 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14046 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14047 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14048 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14049 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14050 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14051 | return; |
| 14052 | |
| 14053 | nla_put_failure: |
| 14054 | genlmsg_cancel(msg, hdr); |
| 14055 | nlmsg_free(msg); |
| 14056 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14057 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 14058 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14059 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 14060 | struct net_device *netdev, const u8 *addr, |
| 14061 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14062 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14063 | { |
| 14064 | struct sk_buff *msg; |
| 14065 | void *hdr; |
| 14066 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 14067 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14068 | if (!msg) |
| 14069 | return; |
| 14070 | |
| 14071 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 14072 | if (!hdr) { |
| 14073 | nlmsg_free(msg); |
| 14074 | return; |
| 14075 | } |
| 14076 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14077 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14078 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14079 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 14080 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 14081 | (key_id != -1 && |
| 14082 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 14083 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 14084 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14085 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14086 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14087 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14088 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14089 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14090 | return; |
| 14091 | |
| 14092 | nla_put_failure: |
| 14093 | genlmsg_cancel(msg, hdr); |
| 14094 | nlmsg_free(msg); |
| 14095 | } |
| 14096 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14097 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 14098 | struct ieee80211_channel *channel_before, |
| 14099 | struct ieee80211_channel *channel_after) |
| 14100 | { |
| 14101 | struct sk_buff *msg; |
| 14102 | void *hdr; |
| 14103 | struct nlattr *nl_freq; |
| 14104 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 14105 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14106 | if (!msg) |
| 14107 | return; |
| 14108 | |
| 14109 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 14110 | if (!hdr) { |
| 14111 | nlmsg_free(msg); |
| 14112 | return; |
| 14113 | } |
| 14114 | |
| 14115 | /* |
| 14116 | * Since we are applying the beacon hint to a wiphy we know its |
| 14117 | * wiphy_idx is valid |
| 14118 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14119 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 14120 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14121 | |
| 14122 | /* Before */ |
| 14123 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 14124 | if (!nl_freq) |
| 14125 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 14126 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14127 | goto nla_put_failure; |
| 14128 | nla_nest_end(msg, nl_freq); |
| 14129 | |
| 14130 | /* After */ |
| 14131 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 14132 | if (!nl_freq) |
| 14133 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 14134 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14135 | goto nla_put_failure; |
| 14136 | nla_nest_end(msg, nl_freq); |
| 14137 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14138 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14139 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14140 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14141 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14142 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14143 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14144 | |
| 14145 | return; |
| 14146 | |
| 14147 | nla_put_failure: |
| 14148 | genlmsg_cancel(msg, hdr); |
| 14149 | nlmsg_free(msg); |
| 14150 | } |
| 14151 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14152 | static void nl80211_send_remain_on_chan_event( |
| 14153 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14154 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14155 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14156 | unsigned int duration, gfp_t gfp) |
| 14157 | { |
| 14158 | struct sk_buff *msg; |
| 14159 | void *hdr; |
| 14160 | |
| 14161 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14162 | if (!msg) |
| 14163 | return; |
| 14164 | |
| 14165 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 14166 | if (!hdr) { |
| 14167 | nlmsg_free(msg); |
| 14168 | return; |
| 14169 | } |
| 14170 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14171 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14172 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14173 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14174 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14175 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14176 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14177 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 14178 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14179 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14180 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14181 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14182 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14183 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 14184 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 14185 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14186 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14187 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14188 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14189 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14190 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14191 | return; |
| 14192 | |
| 14193 | nla_put_failure: |
| 14194 | genlmsg_cancel(msg, hdr); |
| 14195 | nlmsg_free(msg); |
| 14196 | } |
| 14197 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14198 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 14199 | struct ieee80211_channel *chan, |
| 14200 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14201 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14202 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14203 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14204 | |
| 14205 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14206 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14207 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14208 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14209 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14210 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14211 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14212 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 14213 | struct ieee80211_channel *chan, |
| 14214 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14215 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14216 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14217 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14218 | |
| 14219 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14220 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14221 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14222 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14223 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14224 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14225 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 14226 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14227 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14228 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14229 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14230 | struct sk_buff *msg; |
| 14231 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14232 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 14233 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14234 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14235 | if (!msg) |
| 14236 | return; |
| 14237 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14238 | 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] | 14239 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14240 | nlmsg_free(msg); |
| 14241 | return; |
| 14242 | } |
| 14243 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14244 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14245 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14246 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14247 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14248 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14249 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 14250 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14251 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14252 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14253 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14254 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14255 | struct station_info empty_sinfo = {}; |
| 14256 | |
| 14257 | if (!sinfo) |
| 14258 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14259 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14260 | trace_cfg80211_del_sta(dev, mac_addr); |
| 14261 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14262 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14263 | if (!msg) |
| 14264 | return; |
| 14265 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14266 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 14267 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14268 | nlmsg_free(msg); |
| 14269 | return; |
| 14270 | } |
| 14271 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14272 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14273 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14274 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14275 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14276 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14277 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 14278 | enum nl80211_connect_failed_reason reason, |
| 14279 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14280 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14281 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14282 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14283 | struct sk_buff *msg; |
| 14284 | void *hdr; |
| 14285 | |
| 14286 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 14287 | if (!msg) |
| 14288 | return; |
| 14289 | |
| 14290 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 14291 | if (!hdr) { |
| 14292 | nlmsg_free(msg); |
| 14293 | return; |
| 14294 | } |
| 14295 | |
| 14296 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14297 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 14298 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 14299 | goto nla_put_failure; |
| 14300 | |
| 14301 | genlmsg_end(msg, hdr); |
| 14302 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14303 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14304 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14305 | return; |
| 14306 | |
| 14307 | nla_put_failure: |
| 14308 | genlmsg_cancel(msg, hdr); |
| 14309 | nlmsg_free(msg); |
| 14310 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14311 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14312 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14313 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 14314 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14315 | { |
| 14316 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14317 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14318 | struct sk_buff *msg; |
| 14319 | void *hdr; |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 14320 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14321 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14322 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14323 | return false; |
| 14324 | |
| 14325 | msg = nlmsg_new(100, gfp); |
| 14326 | if (!msg) |
| 14327 | return true; |
| 14328 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14329 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14330 | if (!hdr) { |
| 14331 | nlmsg_free(msg); |
| 14332 | return true; |
| 14333 | } |
| 14334 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14335 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14336 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14337 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 14338 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14339 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14340 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14341 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14342 | return true; |
| 14343 | |
| 14344 | nla_put_failure: |
| 14345 | genlmsg_cancel(msg, hdr); |
| 14346 | nlmsg_free(msg); |
| 14347 | return true; |
| 14348 | } |
| 14349 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14350 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 14351 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14352 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14353 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14354 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14355 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14356 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 14357 | |
| 14358 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 14359 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 14360 | trace_cfg80211_return_bool(false); |
| 14361 | return false; |
| 14362 | } |
| 14363 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 14364 | addr, gfp); |
| 14365 | trace_cfg80211_return_bool(ret); |
| 14366 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14367 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14368 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 14369 | |
| 14370 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 14371 | const u8 *addr, gfp_t gfp) |
| 14372 | { |
| 14373 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14374 | bool ret; |
| 14375 | |
| 14376 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 14377 | |
| 14378 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 14379 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 14380 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 14381 | trace_cfg80211_return_bool(false); |
| 14382 | return false; |
| 14383 | } |
| 14384 | ret = __nl80211_unexpected_frame(dev, |
| 14385 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 14386 | addr, gfp); |
| 14387 | trace_cfg80211_return_bool(ret); |
| 14388 | return ret; |
| 14389 | } |
| 14390 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14391 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14392 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14393 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 14394 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14395 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14396 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14397 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14398 | struct sk_buff *msg; |
| 14399 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14400 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14401 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14402 | if (!msg) |
| 14403 | return -ENOMEM; |
| 14404 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14405 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14406 | if (!hdr) { |
| 14407 | nlmsg_free(msg); |
| 14408 | return -ENOMEM; |
| 14409 | } |
| 14410 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14411 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14412 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14413 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14414 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14415 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14416 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 14417 | (sig_dbm && |
| 14418 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14419 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 14420 | (flags && |
| 14421 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14422 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14423 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14424 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14425 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14426 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14427 | |
| 14428 | nla_put_failure: |
| 14429 | genlmsg_cancel(msg, hdr); |
| 14430 | nlmsg_free(msg); |
| 14431 | return -ENOBUFS; |
| 14432 | } |
| 14433 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14434 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 14435 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14436 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14437 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14438 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14439 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14440 | struct sk_buff *msg; |
| 14441 | void *hdr; |
| 14442 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14443 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 14444 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14445 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14446 | if (!msg) |
| 14447 | return; |
| 14448 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14449 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14450 | if (!hdr) { |
| 14451 | nlmsg_free(msg); |
| 14452 | return; |
| 14453 | } |
| 14454 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14455 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14456 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14457 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14458 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14459 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14460 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14461 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14462 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14463 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14464 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14465 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14466 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14467 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14468 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14469 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14470 | return; |
| 14471 | |
| 14472 | nla_put_failure: |
| 14473 | genlmsg_cancel(msg, hdr); |
| 14474 | nlmsg_free(msg); |
| 14475 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14476 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14477 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14478 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 14479 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14480 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14481 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14482 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 14483 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14484 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14485 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14486 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14487 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14488 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14489 | cb = (void **)msg->cb; |
| 14490 | |
| 14491 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 14492 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14493 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14494 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14495 | } |
| 14496 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14497 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14498 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14499 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14500 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14501 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14502 | goto nla_put_failure; |
| 14503 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14504 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 14505 | if (!cb[1]) |
| 14506 | goto nla_put_failure; |
| 14507 | |
| 14508 | cb[2] = rdev; |
| 14509 | |
| 14510 | return msg; |
| 14511 | nla_put_failure: |
| 14512 | nlmsg_free(msg); |
| 14513 | return NULL; |
| 14514 | } |
| 14515 | |
| 14516 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 14517 | { |
| 14518 | void **cb = (void **)msg->cb; |
| 14519 | struct cfg80211_registered_device *rdev = cb[2]; |
| 14520 | |
| 14521 | nla_nest_end(msg, cb[1]); |
| 14522 | genlmsg_end(msg, cb[0]); |
| 14523 | |
| 14524 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 14525 | |
| 14526 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 14527 | NL80211_MCGRP_MLME, gfp); |
| 14528 | } |
| 14529 | |
| 14530 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 14531 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14532 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14533 | { |
| 14534 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 14535 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14536 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14537 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14538 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14539 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 14540 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 14541 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 14542 | return; |
| 14543 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 14544 | if (wdev->cqm_config) { |
| 14545 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 14546 | |
| 14547 | cfg80211_cqm_rssi_update(rdev, dev); |
| 14548 | |
| 14549 | if (rssi_level == 0) |
| 14550 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 14551 | } |
| 14552 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14553 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 14554 | if (!msg) |
| 14555 | return; |
| 14556 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14557 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 14558 | rssi_event)) |
| 14559 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14560 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14561 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 14562 | rssi_level)) |
| 14563 | goto nla_put_failure; |
| 14564 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14565 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14566 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14567 | return; |
| 14568 | |
| 14569 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14570 | nlmsg_free(msg); |
| 14571 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14572 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14573 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14574 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 14575 | const u8 *peer, u32 num_packets, |
| 14576 | u32 rate, u32 intvl, gfp_t gfp) |
| 14577 | { |
| 14578 | struct sk_buff *msg; |
| 14579 | |
| 14580 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 14581 | if (!msg) |
| 14582 | return; |
| 14583 | |
| 14584 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 14585 | goto nla_put_failure; |
| 14586 | |
| 14587 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 14588 | goto nla_put_failure; |
| 14589 | |
| 14590 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 14591 | goto nla_put_failure; |
| 14592 | |
| 14593 | cfg80211_send_cqm(msg, gfp); |
| 14594 | return; |
| 14595 | |
| 14596 | nla_put_failure: |
| 14597 | nlmsg_free(msg); |
| 14598 | } |
| 14599 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 14600 | |
| 14601 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 14602 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 14603 | { |
| 14604 | struct sk_buff *msg; |
| 14605 | |
| 14606 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 14607 | |
| 14608 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 14609 | if (!msg) |
| 14610 | return; |
| 14611 | |
| 14612 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 14613 | goto nla_put_failure; |
| 14614 | |
| 14615 | cfg80211_send_cqm(msg, gfp); |
| 14616 | return; |
| 14617 | |
| 14618 | nla_put_failure: |
| 14619 | nlmsg_free(msg); |
| 14620 | } |
| 14621 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 14622 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 14623 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 14624 | { |
| 14625 | struct sk_buff *msg; |
| 14626 | |
| 14627 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 14628 | if (!msg) |
| 14629 | return; |
| 14630 | |
| 14631 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 14632 | goto nla_put_failure; |
| 14633 | |
| 14634 | cfg80211_send_cqm(msg, gfp); |
| 14635 | return; |
| 14636 | |
| 14637 | nla_put_failure: |
| 14638 | nlmsg_free(msg); |
| 14639 | } |
| 14640 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 14641 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14642 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 14643 | struct net_device *netdev, const u8 *bssid, |
| 14644 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14645 | { |
| 14646 | struct sk_buff *msg; |
| 14647 | struct nlattr *rekey_attr; |
| 14648 | void *hdr; |
| 14649 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14650 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14651 | if (!msg) |
| 14652 | return; |
| 14653 | |
| 14654 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 14655 | if (!hdr) { |
| 14656 | nlmsg_free(msg); |
| 14657 | return; |
| 14658 | } |
| 14659 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14660 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14661 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14662 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 14663 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14664 | |
| 14665 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 14666 | if (!rekey_attr) |
| 14667 | goto nla_put_failure; |
| 14668 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14669 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 14670 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 14671 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14672 | |
| 14673 | nla_nest_end(msg, rekey_attr); |
| 14674 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14675 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14676 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14677 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14678 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14679 | return; |
| 14680 | |
| 14681 | nla_put_failure: |
| 14682 | genlmsg_cancel(msg, hdr); |
| 14683 | nlmsg_free(msg); |
| 14684 | } |
| 14685 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14686 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 14687 | const u8 *replay_ctr, gfp_t gfp) |
| 14688 | { |
| 14689 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14690 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14691 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14692 | |
| 14693 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 14694 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 14695 | } |
| 14696 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 14697 | |
| 14698 | static void |
| 14699 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 14700 | struct net_device *netdev, int index, |
| 14701 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14702 | { |
| 14703 | struct sk_buff *msg; |
| 14704 | struct nlattr *attr; |
| 14705 | void *hdr; |
| 14706 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14707 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14708 | if (!msg) |
| 14709 | return; |
| 14710 | |
| 14711 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 14712 | if (!hdr) { |
| 14713 | nlmsg_free(msg); |
| 14714 | return; |
| 14715 | } |
| 14716 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14717 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14718 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14719 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14720 | |
| 14721 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 14722 | if (!attr) |
| 14723 | goto nla_put_failure; |
| 14724 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14725 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 14726 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 14727 | (preauth && |
| 14728 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 14729 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14730 | |
| 14731 | nla_nest_end(msg, attr); |
| 14732 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14733 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14734 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14735 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14736 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14737 | return; |
| 14738 | |
| 14739 | nla_put_failure: |
| 14740 | genlmsg_cancel(msg, hdr); |
| 14741 | nlmsg_free(msg); |
| 14742 | } |
| 14743 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14744 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 14745 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 14746 | { |
| 14747 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14748 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14749 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14750 | |
| 14751 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 14752 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 14753 | } |
| 14754 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 14755 | |
| 14756 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 14757 | struct net_device *netdev, |
| 14758 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14759 | gfp_t gfp, |
| 14760 | enum nl80211_commands notif, |
| 14761 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14762 | { |
| 14763 | struct sk_buff *msg; |
| 14764 | void *hdr; |
| 14765 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14766 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14767 | if (!msg) |
| 14768 | return; |
| 14769 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14770 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14771 | if (!hdr) { |
| 14772 | nlmsg_free(msg); |
| 14773 | return; |
| 14774 | } |
| 14775 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 14776 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14777 | goto nla_put_failure; |
| 14778 | |
| 14779 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 14780 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14781 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14782 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 14783 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 14784 | goto nla_put_failure; |
| 14785 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14786 | genlmsg_end(msg, hdr); |
| 14787 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14788 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14789 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14790 | return; |
| 14791 | |
| 14792 | nla_put_failure: |
| 14793 | genlmsg_cancel(msg, hdr); |
| 14794 | nlmsg_free(msg); |
| 14795 | } |
| 14796 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14797 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 14798 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14799 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14800 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14801 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14802 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14803 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14804 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14805 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14806 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14807 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 14808 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 14809 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14810 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14811 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14812 | } |
| 14813 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 14814 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14815 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 14816 | struct cfg80211_chan_def *chandef, |
| 14817 | u8 count) |
| 14818 | { |
| 14819 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14820 | struct wiphy *wiphy = wdev->wiphy; |
| 14821 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 14822 | |
| 14823 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 14824 | |
| 14825 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14826 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 14827 | } |
| 14828 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 14829 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14830 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14831 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 14832 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14833 | enum nl80211_radar_event event, |
| 14834 | struct net_device *netdev, gfp_t gfp) |
| 14835 | { |
| 14836 | struct sk_buff *msg; |
| 14837 | void *hdr; |
| 14838 | |
| 14839 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14840 | if (!msg) |
| 14841 | return; |
| 14842 | |
| 14843 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 14844 | if (!hdr) { |
| 14845 | nlmsg_free(msg); |
| 14846 | return; |
| 14847 | } |
| 14848 | |
| 14849 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 14850 | goto nla_put_failure; |
| 14851 | |
| 14852 | /* NOP and radar events don't need a netdev parameter */ |
| 14853 | if (netdev) { |
| 14854 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 14855 | |
| 14856 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14857 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14858 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14859 | goto nla_put_failure; |
| 14860 | } |
| 14861 | |
| 14862 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 14863 | goto nla_put_failure; |
| 14864 | |
| 14865 | if (nl80211_send_chandef(msg, chandef)) |
| 14866 | goto nla_put_failure; |
| 14867 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14868 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14869 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14870 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14871 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14872 | return; |
| 14873 | |
| 14874 | nla_put_failure: |
| 14875 | genlmsg_cancel(msg, hdr); |
| 14876 | nlmsg_free(msg); |
| 14877 | } |
| 14878 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14879 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 14880 | u64 cookie, bool acked, gfp_t gfp) |
| 14881 | { |
| 14882 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14883 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14884 | struct sk_buff *msg; |
| 14885 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14886 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14887 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 14888 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14890 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14891 | if (!msg) |
| 14892 | return; |
| 14893 | |
| 14894 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 14895 | if (!hdr) { |
| 14896 | nlmsg_free(msg); |
| 14897 | return; |
| 14898 | } |
| 14899 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14900 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14901 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14902 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14903 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14904 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14905 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14906 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14907 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14908 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14909 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14910 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14911 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14912 | return; |
| 14913 | |
| 14914 | nla_put_failure: |
| 14915 | genlmsg_cancel(msg, hdr); |
| 14916 | nlmsg_free(msg); |
| 14917 | } |
| 14918 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 14919 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14920 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 14921 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14922 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14923 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14924 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14925 | struct sk_buff *msg; |
| 14926 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14927 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14928 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14929 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 14930 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14931 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14932 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 14933 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 14934 | if (!msg) { |
| 14935 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14936 | return; |
| 14937 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14938 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14939 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 14940 | if (!hdr) |
| 14941 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14942 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14943 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14944 | (freq && |
| 14945 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 14946 | (sig_dbm && |
| 14947 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 14948 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 14949 | goto nla_put_failure; |
| 14950 | |
| 14951 | genlmsg_end(msg, hdr); |
| 14952 | |
| 14953 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14954 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14955 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14956 | return; |
| 14957 | |
| 14958 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14959 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14960 | if (hdr) |
| 14961 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14962 | nlmsg_free(msg); |
| 14963 | } |
| 14964 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 14965 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14966 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14967 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 14968 | struct cfg80211_wowlan_wakeup *wakeup) |
| 14969 | { |
| 14970 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 14971 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 14972 | int i, j; |
| 14973 | |
| 14974 | nl_results = nla_nest_start( |
| 14975 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 14976 | if (!nl_results) |
| 14977 | return -EMSGSIZE; |
| 14978 | |
| 14979 | for (i = 0; i < nd->n_matches; i++) { |
| 14980 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 14981 | |
| 14982 | nl_match = nla_nest_start(msg, i); |
| 14983 | if (!nl_match) |
| 14984 | break; |
| 14985 | |
| 14986 | /* The SSID attribute is optional in nl80211, but for |
| 14987 | * simplicity reasons it's always present in the |
| 14988 | * cfg80211 structure. If a driver can't pass the |
| 14989 | * SSID, that needs to be changed. A zero length SSID |
| 14990 | * is still a valid SSID (wildcard), so it cannot be |
| 14991 | * used for this purpose. |
| 14992 | */ |
| 14993 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 14994 | match->ssid.ssid)) { |
| 14995 | nla_nest_cancel(msg, nl_match); |
| 14996 | goto out; |
| 14997 | } |
| 14998 | |
| 14999 | if (match->n_channels) { |
| 15000 | nl_freqs = nla_nest_start( |
| 15001 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 15002 | if (!nl_freqs) { |
| 15003 | nla_nest_cancel(msg, nl_match); |
| 15004 | goto out; |
| 15005 | } |
| 15006 | |
| 15007 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 15008 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 15009 | nla_nest_cancel(msg, nl_freqs); |
| 15010 | nla_nest_cancel(msg, nl_match); |
| 15011 | goto out; |
| 15012 | } |
| 15013 | } |
| 15014 | |
| 15015 | nla_nest_end(msg, nl_freqs); |
| 15016 | } |
| 15017 | |
| 15018 | nla_nest_end(msg, nl_match); |
| 15019 | } |
| 15020 | |
| 15021 | out: |
| 15022 | nla_nest_end(msg, nl_results); |
| 15023 | return 0; |
| 15024 | } |
| 15025 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15026 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 15027 | struct cfg80211_wowlan_wakeup *wakeup, |
| 15028 | gfp_t gfp) |
| 15029 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15030 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15031 | struct sk_buff *msg; |
| 15032 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15033 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15034 | |
| 15035 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 15036 | |
| 15037 | if (wakeup) |
| 15038 | size += wakeup->packet_present_len; |
| 15039 | |
| 15040 | msg = nlmsg_new(size, gfp); |
| 15041 | if (!msg) |
| 15042 | return; |
| 15043 | |
| 15044 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 15045 | if (!hdr) |
| 15046 | goto free_msg; |
| 15047 | |
| 15048 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15049 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15050 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15051 | goto free_msg; |
| 15052 | |
| 15053 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15054 | wdev->netdev->ifindex)) |
| 15055 | goto free_msg; |
| 15056 | |
| 15057 | if (wakeup) { |
| 15058 | struct nlattr *reasons; |
| 15059 | |
| 15060 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 15061 | if (!reasons) |
| 15062 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15063 | |
| 15064 | if (wakeup->disconnect && |
| 15065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 15066 | goto free_msg; |
| 15067 | if (wakeup->magic_pkt && |
| 15068 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 15069 | goto free_msg; |
| 15070 | if (wakeup->gtk_rekey_failure && |
| 15071 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 15072 | goto free_msg; |
| 15073 | if (wakeup->eap_identity_req && |
| 15074 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 15075 | goto free_msg; |
| 15076 | if (wakeup->four_way_handshake && |
| 15077 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 15078 | goto free_msg; |
| 15079 | if (wakeup->rfkill_release && |
| 15080 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 15081 | goto free_msg; |
| 15082 | |
| 15083 | if (wakeup->pattern_idx >= 0 && |
| 15084 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 15085 | wakeup->pattern_idx)) |
| 15086 | goto free_msg; |
| 15087 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15088 | if (wakeup->tcp_match && |
| 15089 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 15090 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 15091 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15092 | if (wakeup->tcp_connlost && |
| 15093 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 15094 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 15095 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15096 | if (wakeup->tcp_nomoretokens && |
| 15097 | nla_put_flag(msg, |
| 15098 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 15099 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 15100 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15101 | if (wakeup->packet) { |
| 15102 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 15103 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 15104 | |
| 15105 | if (!wakeup->packet_80211) { |
| 15106 | pkt_attr = |
| 15107 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 15108 | len_attr = |
| 15109 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 15110 | } |
| 15111 | |
| 15112 | if (wakeup->packet_len && |
| 15113 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 15114 | goto free_msg; |
| 15115 | |
| 15116 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 15117 | wakeup->packet)) |
| 15118 | goto free_msg; |
| 15119 | } |
| 15120 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 15121 | if (wakeup->net_detect && |
| 15122 | cfg80211_net_detect_results(msg, wakeup)) |
| 15123 | goto free_msg; |
| 15124 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15125 | nla_nest_end(msg, reasons); |
| 15126 | } |
| 15127 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15128 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15129 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15130 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15131 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15132 | return; |
| 15133 | |
| 15134 | free_msg: |
| 15135 | nlmsg_free(msg); |
| 15136 | } |
| 15137 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 15138 | #endif |
| 15139 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15140 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 15141 | enum nl80211_tdls_operation oper, |
| 15142 | u16 reason_code, gfp_t gfp) |
| 15143 | { |
| 15144 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15145 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15146 | struct sk_buff *msg; |
| 15147 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15148 | |
| 15149 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 15150 | reason_code); |
| 15151 | |
| 15152 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15153 | if (!msg) |
| 15154 | return; |
| 15155 | |
| 15156 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 15157 | if (!hdr) { |
| 15158 | nlmsg_free(msg); |
| 15159 | return; |
| 15160 | } |
| 15161 | |
| 15162 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15163 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15164 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 15165 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 15166 | (reason_code > 0 && |
| 15167 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 15168 | goto nla_put_failure; |
| 15169 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15170 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15171 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15172 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15173 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15174 | return; |
| 15175 | |
| 15176 | nla_put_failure: |
| 15177 | genlmsg_cancel(msg, hdr); |
| 15178 | nlmsg_free(msg); |
| 15179 | } |
| 15180 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 15181 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15182 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 15183 | unsigned long state, |
| 15184 | void *_notify) |
| 15185 | { |
| 15186 | struct netlink_notify *notify = _notify; |
| 15187 | struct cfg80211_registered_device *rdev; |
| 15188 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15189 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15190 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 15191 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15192 | return NOTIFY_DONE; |
| 15193 | |
| 15194 | rcu_read_lock(); |
| 15195 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15196 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15197 | struct cfg80211_sched_scan_request *sched_scan_req; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 15198 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15199 | list_for_each_entry_rcu(sched_scan_req, |
| 15200 | &rdev->sched_scan_req_list, |
| 15201 | list) { |
| 15202 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 15203 | sched_scan_req->nl_owner_dead = true; |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 15204 | schedule_work(&rdev->sched_scan_stop_wk); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15205 | } |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 15206 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 15207 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 15208 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15209 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15210 | |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 15211 | if (wdev->owner_nlportid == notify->portid) { |
| 15212 | wdev->nl_owner_dead = true; |
| 15213 | schedule_work(&rdev->destroy_work); |
| 15214 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 15215 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 15216 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 15217 | } |
| 15218 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15219 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 15220 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 15221 | list) { |
| 15222 | if (reg->nlportid == notify->portid) { |
| 15223 | list_del(®->list); |
| 15224 | kfree(reg); |
| 15225 | break; |
| 15226 | } |
| 15227 | } |
| 15228 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15229 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15230 | |
| 15231 | rcu_read_unlock(); |
| 15232 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 15233 | /* |
| 15234 | * It is possible that the user space process that is controlling the |
| 15235 | * indoor setting disappeared, so notify the regulatory core. |
| 15236 | */ |
| 15237 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 15238 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15239 | } |
| 15240 | |
| 15241 | static struct notifier_block nl80211_netlink_notifier = { |
| 15242 | .notifier_call = nl80211_netlink_notify, |
| 15243 | }; |
| 15244 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15245 | void cfg80211_ft_event(struct net_device *netdev, |
| 15246 | struct cfg80211_ft_event_params *ft_event) |
| 15247 | { |
| 15248 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15249 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15250 | struct sk_buff *msg; |
| 15251 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15252 | |
| 15253 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 15254 | |
| 15255 | if (!ft_event->target_ap) |
| 15256 | return; |
| 15257 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 15258 | msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15259 | if (!msg) |
| 15260 | return; |
| 15261 | |
| 15262 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15263 | if (!hdr) |
| 15264 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15265 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15266 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15267 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15268 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 15269 | goto out; |
| 15270 | |
| 15271 | if (ft_event->ies && |
| 15272 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 15273 | goto out; |
| 15274 | if (ft_event->ric_ies && |
| 15275 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 15276 | ft_event->ric_ies)) |
| 15277 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15278 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15279 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15280 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15281 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15282 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15283 | return; |
| 15284 | out: |
| 15285 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15286 | } |
| 15287 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 15288 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15289 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 15290 | { |
| 15291 | struct cfg80211_registered_device *rdev; |
| 15292 | struct sk_buff *msg; |
| 15293 | void *hdr; |
| 15294 | u32 nlportid; |
| 15295 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15296 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15297 | if (!rdev->crit_proto_nlportid) |
| 15298 | return; |
| 15299 | |
| 15300 | nlportid = rdev->crit_proto_nlportid; |
| 15301 | rdev->crit_proto_nlportid = 0; |
| 15302 | |
| 15303 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15304 | if (!msg) |
| 15305 | return; |
| 15306 | |
| 15307 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 15308 | if (!hdr) |
| 15309 | goto nla_put_failure; |
| 15310 | |
| 15311 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15312 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15313 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15314 | goto nla_put_failure; |
| 15315 | |
| 15316 | genlmsg_end(msg, hdr); |
| 15317 | |
| 15318 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 15319 | return; |
| 15320 | |
| 15321 | nla_put_failure: |
| 15322 | if (hdr) |
| 15323 | genlmsg_cancel(msg, hdr); |
| 15324 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15325 | } |
| 15326 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 15327 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15328 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 15329 | { |
| 15330 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15331 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15332 | struct sk_buff *msg; |
| 15333 | void *hdr; |
| 15334 | |
| 15335 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15336 | if (!msg) |
| 15337 | return; |
| 15338 | |
| 15339 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 15340 | if (!hdr) |
| 15341 | goto out; |
| 15342 | |
| 15343 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15344 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15345 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15346 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15347 | goto out; |
| 15348 | |
| 15349 | genlmsg_end(msg, hdr); |
| 15350 | |
| 15351 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 15352 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 15353 | return; |
| 15354 | out: |
| 15355 | nlmsg_free(msg); |
| 15356 | } |
| 15357 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15358 | /* initialisation/exit functions */ |
| 15359 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 15360 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15361 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 15362 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15363 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15364 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15365 | if (err) |
| 15366 | return err; |
| 15367 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15368 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 15369 | if (err) |
| 15370 | goto err_out; |
| 15371 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15372 | return 0; |
| 15373 | err_out: |
| 15374 | genl_unregister_family(&nl80211_fam); |
| 15375 | return err; |
| 15376 | } |
| 15377 | |
| 15378 | void nl80211_exit(void) |
| 15379 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15380 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15381 | genl_unregister_family(&nl80211_fam); |
| 15382 | } |